The 2nd Amendment specifies that a well regulated militia is necessary for a free state, and that the right to keep and bear arms cannot be abridged by the Federal government.
Nothing in that amendment specifically mentions the purpose of preventing totalitarian government. That's a modern interpretation, albeit one currently upheld by the Supreme Court.