Why did Ian David Long open fire inside a crowded California bar on Wednesday night?

That's the question investigators are working to answer, even as burials commence and the mourning continues for the 12 victims Long gunned down at the Borderline Bar & Grill. The rampage ended only after Long killed himself.

Officials have suggested post-traumatic stress disorder may have been a factor for the former Marine, who had served in a hellish area of Afghanistan at a particularly brutal time in the war. But authorities also said the 28-year-old had been "cleared" by a mental health professional just months earlier after a disturbance incident.

"He was somewhat irate. Acting a little irrationally," Ventura County Sheriff Geoff Dean said Thursday, talking about officers' earlier interaction with Long. "They felt he might be suffering from PTSD, the fact he was a veteran."

This 2017 photo from the California Department of Motor Vehicles shows Ian David Long. Authorities said the Marine combat veteran opened fire Wednesday evening, Nov. 7, 2018, at a country music bar in Southern California, killing multiple people before apparently taking his own life. (California Department of Motor Vehicles via AP)

But investigators are unlikely to quickly reveal a definitive motive for the massacre, and authorities are still unraveling Long’s background – including his nearly five-year stint with the Marines.

Long joined the military in August 2008 at the age of 18. Less than a year later, he married in Honolulu, according to military and court records.

Part of the infantry, Long was responsible for hauling and shooting machine guns until he was honorably discharged with the rank of corporal in 2013, the Pentagon said.

CALIFORNIA BAR GUNMAN ID'D AS IAN DAVID LONG, 28: EVERYTHING WE KNOW SO FAR

While in the Marines, Long was deployed once – to the Afghan province of Helmand – with Golf Company, 2nd Battalion, 3rd Marine Regiment from November 2010 to June 2011.

The Marine Corps told The New York Times the 1,000-person battalion saw little action compared with others in the province, which saw much of the deadliest fighting in the region from 2010 to 2012. The only casualty that occurred in Long's battalion died in a suicide, allegedly after being hazed by other Marines, the newspaper reported.

“It was fairly quiet,” Jeremy Soliz, who was part of the deployment, told the newspaper. “We were warriors, but we acted more like policemen. We built roads, built canals, tried to help people.”

Despite the relative peace, there was a constant threat of improvised explosive devices, snipers or hidden bombs.

“Every time you walked outside the wire, you wondered if you were going to get your legs blown off,” Dwayne Pettiford, who was Long’s roommate in the military, told the Times.

At the time of Long’s deployment to Helmand Province, the U.S. Marines had just launched a major offensive in the southern part of the country in response to a growing Taliban insurgency. Between 90,000 and 100,000 U.S. troops were on the ground at the time.

A month before his arrival to Helmand, Marines on the ground faced daily attacks – especially in Sangin, which is considered the bloodiest battleground in Afghanistan. Camp Pendleton’s 3rd Battalion, 5th Marine Regiment had 25 killed and about 200 wounded during seven months in Sangin – the heaviest casualties of any unit in the war, The San Diego Tribune reported in 2014.

Long’s regiment returned stateside in June 2011. He was awarded a Marine Corps Good Conduct Medal and a Combat Action Ribbon, which means he saw combat while deployed.

“The Marine Corps extends its deepest condolences to the families of the victims in this senseless tragedy,” the Marines said Thursday of the shooting in California.

CALIFORNIA BAR SHOOTING LEAVES 12 DEAD, INCLUDING SHERIFF'S SERGEANT, POLICE SAY

During his service, Long's marriage fell apart. He and his wife separated in June 2011, while he was deployed in Afghanistan. The couple cited irreconcilable differences in divorce papers filed in May 2013, two months after Long left the Marines.

Later, he enrolled at nearby California State University, Northridge, last attending in 2016, the school said in a statement.

More recently he was living in a home where neighbors said they could hear frequent, aggressive shouting between Long and his mother -- especially during the last year.

One especially bad ruckus in April had law enforcement officials knocking on Long's door.

At the time, authorities brought in a mental health specialist who concluded that Long could not be involuntarily committed for psychiatric observation. The specialist worried the veteran might have post-traumatic stress disorder.

It's unclear if Long was ever officially diagnosed.

"I think we try to look at the core and try to understand what happened and see if there's a way that we can stop it. We all try to make sense of the senseless,” Dean said, according to ABC 7.

PTSD: WHAT IT IS AND HOW TO SPOT IT

Post-traumatic stress disorder, or PTSD, affects a significant number of soldiers returning from war. According to one estimate, around 2.5 million veterans from the wars in Iraq and Afghanistan returned home with the disorder or subsequently developed it.

The Associated Press contributed to this report.