Just a short observation: People don't usually use guns with a primary instrumental goal of killing people permanently.
I'm not talking about firing squads, suicides, or hunting, where killing someone or something is indeed the purpose, or accidental discharges of firearms.
I'm talking about intentional uses of firearms justified or criminal, against people other than the person using the gun, both in civilian settings and in war. And, I'm not talking about menacing, threats, or deterrence. I'm talking about actually and intentionally shooting other people with firearms, i.e. gun homicide, whether or not it is legally justified.
Of course, firing squads are hardly the only practical means of executing people sentenced to death. Firearm suicides would ideally be prevented in every case because, even if there are circumstances where suicide should be legally allowed, firearms are not a desirable tool to achieve that end. And, by definition, no one wants people to be kill with an accidental discharge of a firearm.
The vast majority of the time, shooting someone with a firearm is a permanent solution to a temporary problem.
Sure, there are times when someone uses a gun to kill someone because they want that person to be dead permanently, in essentially a non-judicial version of a firing squad execution. And, almost always, extra-legal execution that is not simply for the purpose of incapacitating someone to achieve some other end is a crime, even when this is done by members of the military. If it is equally possible and reliable to incapacitate someone rather than to kill them, such as when enemy soldiers surrender in war, it is criminal or a war crime, to kill them instead.
Far more often than having a goal of extra-judicial execution, someone uses a gun to incapacitate someone. The fire a gun at someone to prevent them from harming them or someone else, to prevent them from interrupting the commission of a crime, to prevent someone from arresting you, to prevent a kidnapping you or some other serious crime, to prevent them from getting in the way of their advance, to protect a boundary or location, to prevent someone from escaping from prison, or to prevent someone from escaping being arrested or stopped.
When law enforcement and the military use firearms to kill people, arresting or taking prisoner the person who they shot while disrupting their actions in progress, would almost always be preferable. The same is true of civilians using firearms in self-defense. This is also true of a large share of criminals who shoot someone in furtherance of a crime like robbery, burglary, kidnapping, or rape, or criminals who shoot members of law enforcement or civilians using firearms in defense of themselves or others or property.
People mostly shoot other people with firearms because firearms make it possible to incapacitate someone immediately when it is not practicable to incapacitate them in any other way.
If we had Star Trek-style ray guns that could be set to "stun" rather than "kill" and were just as effective at incapacitating someone immediately as a firearm was, that would satisfy the goals of firearm users who actually shoot other people with firearms the vast majority of the time.
Non-lethal weapons aren't there yet. There are many situations where the imperative of incapacitating someone outweighs the value of their own life, and non-lethal weapons aren't an adequate substitute to achieving that end. But ultimately, this is a technology problem. If we could develop that kind of technology, it would be vastly more desirable than our existing firearms in the vast majority of circumstances where they are used for their intended purpose.
One can also imagine AI and technologies like "smart bullets" improving the accuracy of firearms in a manner that makes shooting a person in a way that incapacitates them without killing them just as easy as shooting to kill.
Indeed, even against animals, the only accepted use of large caliber ammunition against an animal is to incapacitate a large bear or a large herbivore that presents an immediate threat, and not to kill it for food. Bear and larger than moose herbivore killing for food is almost completely banned, outside some rare, regulated Safari hunting, mostly in rural Africa.
Really, the only time that firearms are legitimately used for the express and intended purposes of killing what is being shot permanently, for which there aren't already superior alternatives, is hunting game. And, that rarely calls for ammunition in excess of 22 to 30 caliber bullets or shotgun pellets (which are not armor piercing or hollow point bullets), which are not automatic weapons that fire multiple shots per pull of the trigger, and do not require large magazines of ammunition. And, in these applications, long guns (i.e. rifles or shotguns) rather than handguns, are almost always preferable, because they are much more accurate at longer ranges.
In essentially every circumstance other than conventional hunting rifles and shotguns to hunt animals for food or trophies, a Star Trek-style stun gun would better meet the legitimate legal objectives of the user than a firearm. Indeed, if a Star Trek-style stun gun could incapacitate animals that are being hunted as effectively as hunting rifles and shotguns do, and the hunter then killed the animal only after it was incapacitated, that would be no worse for legitimate hunters than the status quo. If a Star Trek-style stun gun that was this effective did exist for humans, this is plausible because in most cases, because deer are about the same weight as an average human or smaller, and other animals are the same or smaller in weight, leaving only adult male grizzly bears, elk, and moose as typical animals that are larger than humans. A moose is only five or six times the weight of a heavier human man, an elk is smaller than a moose, and a grizzly bear is only three to four times the weight of a heavier human man, so the Star Trek-style stun gun wouldn't have to be that much more powerful to handle every animal in the wild in the Americas short of a bison, and pretty much everything except elephants, rhinos, hippos, and the very largest wildcats (almost all of which are endangered species) outside of the Americas.
Legally, the case for allowing private ownership of firearms, according to the U.S. Supreme Court in Heller v. District of Columbia, which is the governing theory of the Second Amendment to the U.S. Constitution, is that an individual right to bear arms exists to permit people to use them in furtherance of a "natural right" to self-defense of their persons, of others, and of their homes (not the political insurgency theory that the language of the Second Amendment hints at), and the existence of equally effective non-firearm technology that could achieve that end would undermine this justification.
Again, we don't have that technology yet. But this suggests that we invest far, far too little resources into developing non-lethal weapons (really less lethal weapons, since no weapon is non-lethal in all circumstances, even if designed to be), since actually killing someone is so rarely the actual primary goal for which a firearm is used. Replacing firearms (as would be possible in almost every legitimate case) with non-lethal/less lethal weapons that are equally effective at incapacitating someone, would save tens of thousands of lives each year in the United States alone, and would save hundreds of thousands or millions of lives each year in warfare.