Among the review quotes on the Amazon page for Guy Lawson’s book Arms and the Dudes is one from the magazine Mother Jones, which reads “it sounds like a comedy flick.” It does, and now it is; War Dogs from director Todd Phillips.

Lawson’s reporting, first published as a feature in Rolling Stone, followed two ambitious Miami bros named Efraim Diveroli and David Packouz as they smooth-talked their way into a massive deal with the Pentagon. The film version, which hews fairly closely to the facts, opens with David (Miles Teller) working as a massage therapist. At a funeral, he reconnects with Efraim (Jonah Hill), a childhood friend who’d moved away from Florida during high school. Efraim returns to South Beach dressed like a gangster out of Scarface, a movie they’d cherished as kids and a character they continue to idolize as adults. (They don’t seem fazed by the fact that Scarface dies in a hail of gunfire.)

Barely into his 20s and working alone out of a tiny office, Efraim has nonetheless discovered a way to make millions selling weapons to the U.S. government. The short version of the scheme: Every Pentagon contract must, by law, be posted on a website known as FedBizOpps. While massive conglomerates gobble up the big contracts, small business owners like Efraim can earn a handsome living filling orders for odds and ends like helmets and Humvees. “Everyone’s fighting over the same pie while ignoring the crumbs,” Efraim explains at one point. “I live on crumbs. Like a rat.” Or as they’re unaffectionately known in the defense industry, like a “war dog.”

With conflicts raging in Iraq and Afghanistan in the mid-2000s, there were plenty of crumbs for David and Efraim. Through a combination of luck, deceit, and wildly underbidding their competition, they eventually won a big slice of the pie; a contract to deliver a massive stockpile of weapons and ammo to Afghanistan’s flagging military. But the multimillion-dollar deal hit one snag after another; most crucially, a shady arms dealer named Henry Girard (Bradley Cooper) who sold them Chinese AK-47 bullets they couldn’t use because of a trade embargo, necessitating an elaborate scheme to disguise the illegal munitions by changing their packaging.

There’s a similar kind of disguised smuggling operation going on in War Dogs. Superficially, the movie looks a lot like past Phillips comedies about men behaving badly, with dirty jokes and wacky hijinks galore. But War Dogs is more critical of its protagonists’ behavior, and there’s plenty of sad commentary about the state of modern America. What David and Efraim did was wrong, but most of it wasn’t even illegal, and all of it was possible only because of a system that needed shady characters like them to funnel illegal guns to governments (including our own) who didn’t want to know where those weapons were coming from.

Phillips make smart use of visual juxtapositions, showing Efraim and David’s glamorous dreams and contrasting them with their often pitiful realities. He cuts from a swanky Miami dance club, where the buddies get beaten up after hitting on a guy’s girlfriend, to a greasy spoon where the pair can’t even get a waitress to take their order. Later, he jumps from the glittering neon of Las Vegas to the gray, crumbling warehouses of Albania, where the AK-47 ammo they need is hidden. Phillips also concludes his story on a fascinatingly ambiguous note; War Dogs draws favorable comparisons to The Big Short, another darkly (and depressingly) funny historical dramedy from a guy (Adam McKay) who turned his eye for macho doofuses into social commentary about the terrifying consequences those macho doofuses’ actions have for the rest of us.

As noted by that Mother Jones critic, all of this stuff sounds like something out of a movie. But Phillips can’t help embellishing the story in ways that sometimes pushes War Dogs past the point of believability. An occasionally funny sequence finds David and Efraim personally driving thousands of Beretta pistols through Iraq’s “Triangle of Death” after the guns get confiscated in Jordan. (According to Lawson’s article, the partners failed to deliver the guns and defaulted on the contract.) To ramp up the stakes, he also gives the movie an ominous framing sequence right out of Martin Scorsese’s Casino, with Teller’s David held up at gunpoint by angry Albanians.

At 32, Hill is way too old for his part, but he makes a compulsively watchable criminal. In contrast to the bad guys in something like Suicide Squad, whose villainy was largely justified with tragic or sympathetic backstories, Hill’s Efraim is a complete and unapologetic scoundrel. Vulgar, amoral, and totally remorseless, his Efraim is loyal to no one and nothing except his own bank account. But in the tradition of compelling cinema villains like Gordon Gekko and Hannibal Lecter, there’s something alluring about him too. He knows what he is and he makes no excuses for himself. Efraim has an unforgettable, infectious laugh; high and soft, like air leaking slowly from a balloon. It’s very easy to see why the real David followed this guy into some very poor decisions.

It’s easy to see why Phillips was drawn to him as well. As the man who made Old School and The Hangover series, Phillips is the king of movies about men of limited intelligence and limitless ability to get into trouble. For a guy like that, finding this story must have felt like a gift from God. If Phillips and his screenwriters had simply invented these guys and their improbable rise to the top of the American military supply chain, no one would have believed it. In this case, reality did the heavy lifting.