Washington (CNN)How could a young man whose lawyers say he has been "experiencing and enduring mental illness his entire life" purchase a semiautomatic rifle?
How do laws prevent mentally ill people from buying guns?
Perhaps, perfectly legally.
While people who knew Nikolas Cruz describe a complicated picture of the 19-year-old behind Wednesday's school shooting, questions of mental health and gun laws are beginning to occupy the top tiers of American government.
According to a US official briefed on the investigation, Cruz used an AR-15 style weapon that he had bought legally after passing a background check to kill 17 students and adults at Marjory Stoneman Douglas High School.
"As you know, mental health is often a big problem underlying these tragedies," House Speaker Paul Ryan said at a news conference Thursday reacting to the shooting. "We have a system to prevent people who aren't supposed to get guns from getting guns, and if there are gaps there then we need to look at those gaps."
Here's how that system works, and how it could apply to the Parkland, Florida, shooter.
Under federal law, a person can be tallied in a database and barred from purchasing or possessing a firearm due to a mental illness under two conditions: if he is involuntarily committed to a mental hospital, or if a court or government body declares him mentally incompetent.
In many states, including Florida, law enforcement can take an individual to a mental hospital against his or her will for an initial evaluation. If after 72 hours the doctors observing the individual want to continue that treatment, then they can petition a court for permission, even against the patient's wishes.
That -- a court order allowing a person's continued involuntary institutionalization -- is one thing that should stop an individual from purchasing a firearm.
If the person was taken in for mental treatment involuntarily but was not requested to be held past 72 hours, he is not blocked from buying a gun.
In Florida, if the court chose to commit even an underage individual, he would fail a background check on that basis.
The other way to wind up in the database that could cause an individual to fail a background check for mental illness is if a court or government body were to rule that due to his mental health, a person is a danger to himself or others or is unable to manage his own affairs.
The issue commonly arises when a court or government agency is appointing a conservator or a guardian for an adult because of mental impairment.
When either of those two things happens in Florida, the court or government body that made the decision on the individual's mental health is required to report that record to a state law enforcement agency or the FBI.
The records would be in the National Instant Criminal Background Check System, a confidential database that houses the names and birth years of individuals ineligible to buy firearms.
A licensed gun dealer is required under federal law to run potential buyers through the criminal background check system. The process usually takes around 90 seconds, and, if all the records are in the right place, would prevent a purchaser who was previously involuntarily committed or adjudicated as mentally incompetent from getting the gun.
But federal law doesn't require states to make these mental health records part of background check system, and many fail to voluntarily report the records.
And licensed gun shops aren't the only places to buy a firearm.
"You could buy guns from someone from an online classified ad, people at a yard sale or on the street corner selling guns, or people who are at a gun show but not a retail dealer," all without having to pass a background check, according to Ari Freilich, a legal expert with the Giffords Law Center to Prevent Gun Violence, a group that promotes gun control.
In a speech to the nation Thursday morning, President Donald Trump promised to "tackle the difficult issue of mental health." But so far, his administration has only loosened federal gun laws related to the issue.
Early into his first year in the White House, Trump signed a measure that got rid of a regulation aimed at keeping guns out of the hands of people who were either receiving full disability benefits because of mental illness and couldn't work or people who were unable to manage their own Social Security benefits and needed the help of third parties.
Using the Congressional Review Act, Republican majorities in the House and Senate voted to revoke the rule that former President Barack Obama issued as part of a series of efforts to curb gun violence after similar measures failed to pass through Congress.
Trump signed the bill in private, without his typical public signing ceremony meant to draw attention and fanfare.
He also rolled back an attempt by the Obama administration to clarify and broaden the statutory definitions of the terms that disable individuals who had been committed to mental institutions or adjudicated as mentally incompetent from buying guns.
The measure, proposed by Obama in 2014, had been making its way through the rule-making process but was stymied after the election by the new Trump administration, according to federal documents shared with CNN by the advocacy group Democracy Forward.
CORRECTION: This story has been updated to correct the type of weapon purchased by Nikolas Cruz. It was a semiautomatic rifle.