The lights had just come up and the credits were still rolling on “War Machine,” a new movie that pillories the U.S. military for its performance in Afghanistan, when I turned with some hesitation to my friend who had spent more than two years of his life fighting that war.

“Wow, that was the most anti-military movie I can remember seeing,” I said.

“Yeah,” he replied without pause. “That’s why I liked it.”

The movie, which debuts Friday on Netflix and I saw at a screening last week, is a fictionalized account of the events that led to the ouster of Gen. Stanley McChrystal from Afghanistan in 2010. (It is based on “The Operators,” a book by the late Michael Hastings, whose legendary and infamous profile of the war commander for Rolling Stone magazine led President Barack Obama to summon the general back to Washington and fire him.) The movie seeks to explain why a war that began with promise in the first months after the Sept. 11, 2001, attacks has devolved into a bloody and expensive quagmire. “War Machine” lays the blame unflinchingly on the U.S. military.

As a journalist, I was fixated on the many things the movie gets wrong. The generals, especially the lightly camouflaged McChrystal character played by Brad Pitt, are cartoonish buffoons obsessed with their legacies and contemptuous of the U.S. civilians they serve. The enlisted troops are mostly angry and alone. The Afghans are largely drug addicts.

The real McChrystal was a smart, compassionate and politically tone-deaf officer who urged his troops to take on more risk to protect civilians from harm. He empathized with Iraqis and Afghans and understood that they felt humiliated by the American occupations. Here’s McChrystal in his autobiography, describing a U.S. raid in which an Iraqi man is demeaned in front of his terrified 4-year-old son: “As I watched, I felt sick. I could feel in my own limbs and chest the shame and fury that must have been coursing through the father. . . . I thought, not for the first time: It would be easy for us to lose.”

Here’s the McChrystal character in “War Machine”: “We’re here to build, to protect, to support the civilian population. To that end, we must avoid killing it at all costs. We can’t help them and kill them at the same time. It just ain’t humanly possible.”

The first quote sounds like the general I met in Afghanistan. The second guy is a moron.

But my friend, retired Army Lt. Col. Jason Dempsey, told me he was most grateful for the big things that “War Machine” got right. The movie captures the strange, intoxicating and often lonely bubble that most of America’s four-star war commanders inhabit. The McChrystal character is surrounded by aides who share his all-consuming belief in the mission, and who are determined to shield him from bad news and burnish his legacy. He’s cut off from his political leadership in Washington and the depressing reality that no one back home, including the president, sees his troops’ life-and-death struggle as a top priority.

“I thought 40,000 sounded like a reasonable number,” he mutters when the White House flips out over his request for more soldiers. The movie McChrystal is forever angling for a face-to-face meeting with Obama that comes only when the commander in chief fires him.

“War Machine” also nails the way Iraq and Afghanistan can seem like abstractions to those toiling away inside the U.S. military’s sprawling, air-conditioned command posts. Early in the movie, the general invites Afghan President Hamid Karzai, his feckless partner, to accompany him on a helicopter tour of the country. The Afghan leader immediately recognizes the folly of the general’s listening tour. “Thank you for the invitation,” he says. “It’s very generous, but I’ve seen the country.”

I asked Dempsey what he would have thought of the movie in 2009, when he and I first met in Konar province — one of those middle-of-nowhere places on the Afghanistan-Pakistan border that was home to some of the fiercest fighting of the war. Back then, Dempsey was only a few months into his first combat deployment, the Obama White House was in the middle of a major strategy review, and McChrystal was being hailed in the media as a tireless, creative commander who slept just four hours each night and ran seven miles each morning. He was the guy was who going to win the war.

“I think I would have hated it,” Dempsey told me. “This was our chance to take a crack at the war and do it right.” Even as he left Afghanistan in 2010, there was cause for optimism. U.S. troops were pouring into the country and seemed to be taking back territory from the Taliban.

Dempsey spent his second tour as an adviser to the Afghan army and said he started to have his doubts about the war. U.S. troops were training Afghans in basic tasks, such as marksmanship and battlefield first aid, but they were making little progress in the long, hard work of building a functioning army. The Afghan air force consisted of a handful of helicopters that could not be kept in the air because of a lack of training and spare parts. Corruption, theft and bribery were overwhelming the contracting and logistics systems that ferried food, equipment and ammunition to the front lines.

Dempsey tried for months to get a corrupt and incompetent Afghan battalion commander fired in 2012, only to learn two years later that the Afghan had returned to the job. By that point, Dempsey was long gone, his relief had cycled home, and the new American combat adviser had no clue that the Afghan officer had been fired two years earlier. “I realized everyone was getting on the same treadmill year after year after year,” Dempsey said.

Top military commanders have been too quick to hang all the blame for their recent battlefield failures on civilians — and, as a country, we’ve been too quick to accept their account: The State Department didn’t send enough aid and development experts to secure hard-fought gains. The president lacked the will to stick it out and win in a place like Afghanistan. A distracted and fickle American public never truly understood the stakes.

“War Machine” offers a different verdict: America lost in Afghanistan because its generals were overtaken by hubris, vanity and the delusion that victory was even possible. Like all of the other explanations, it captures only a tiny fraction of the truth. But for Dempsey, it’s a welcome critique.

Like a lot of smart Army officers, he worries that the military has become largely off limits to criticism from a civilian population that is largely ignorant of military operations and too eager to genuflect to the generals. To question their intelligence, integrity or commitment is somehow to impugn the sacrifice of the men and women who fought and died on their orders. The net result of this compact between soldier and civilian is a “respectful indifference,” Dempsey said, that has made praise for the military feel a bit like a Little League participation award. They are heroes just for showing up.

The lesson hasn’t been lost on President Trump, who has stocked the upper ranks of his administration with active-duty and retired brass.

But, of course, not all soldiers are heroes. Before the movie started, Dempsey and I were gossiping about the three colonels he served under in Afghanistan. All three were bounced from the service and stripped of rank for spectacular sex scandals. Two of them were promoted to general before their misconduct and poor judgment were exposed in the media. These figures aren’t necessarily representative, but their stories certainly suggest some rot in the upper ranks of the world’s most powerful fighting force. It’s not an organization that warrants our unquestioning trust.

The next day, Dempsey sent me an email that summed up his feelings about the film and quite possibly the war. “It’s an absurd movie about an absurd war,” he wrote. The real problem with “War Machine,” he added, is that it “might not be absurd enough.”