There a periodic “count-down clock” in this Will Ferrell-Kevin Hart comedy, clicking down the thirty days of freedom Farrell’s character, James King, has before reporting to prison for a ten-year stretch for securities fraud. A viewer can use the device, too, but in reverse: he begins serving his sentence the moment “Get Hard” starts, and can hope for release only when the awful thing ends.

It’s the arrest of King during a big engagement party his father-in-law-to-be (and boss) Martin Barrow (Craig T. Nelson) is throwing for him and his daughter Alissa (Alison Brie) that starts the plot rolling. Convinced that time in the slammer will destroy him, the doofus approaches the only black guy he knows, Darnell Lewis (Hart), to school him in how to survive behind bars. Lewis, who runs the car-wash service King uses and needs $30,000 to expand his business, is a family man who’s never been in trouble with the law, but he falls in with King’s assumption that, being black, he’s statistically likely to have been in prison, to take the job, eventually co-opting the plot of “Boyz ‘n the Hood” to explain his own supposed arrest.

In the opening scenes we’ve already been treated to lots of nudity on Ferrell’s part—he’d given up disrobing for the camera (a motif in his early movies) for awhile, but now the tick I apparently back—but while that’s hardly a pleasant sight, its grossness pales compared to what follows. The relationship between King and Lewis is meant to blossom into a kind of lovable bromance, but the script descends so far into racial stereotyping, offhanded homophobia, class division, sexual coarseness and scatological gags that whatever chemistry the stars might have brought to the table is pretty much dissipated. Generally speaking, one can take it as a rule of thumb that the number of times a movie employs the words “dick” and “f**k” is inversely proportional to its comedic quality; both occur in profusion here.

It’s difficult, in fact, to determine which of the set-pieces concocted by director Etan Cohen and his co-writers Jay Martel and Ian Roberts sinks lowest, but the episode in which Darnell takes James to a café popular with gays where Lewis orders King to give a blow-job to a customer—an attempt portrayed in pretty explicit detail, all for squeamish laughs—is certainly in the running. But then so is the vaudeville bit in which Darnell supposedly instructs King in prison-yard etiquette by quickly switching gears to portray a black gangsta, a Hispanic thug, and a gay queen. The sequence in which King dresses up as Lil Wayne to meet Darnell’s bad-boy cousin Russell (Top “T.I.” Harris) is as much of a groaner as Jamie Kennedy’s “Malibu’s Most Wanted” was, and a visit by the two guys to a White Power bike gang’s headquarters is equally bad.

Under the circumstances all the leads can do is to fall back on their familiar shtick—so we get Ferrell’s dumbness as well as his propensity to go about undressed and Hart’s proclivity for motor-mouthed delivery as the movie’s supposed saving graces. Both are funny guys, and with the right material they could work well together; but they need something, however feeble, to apply their talent to. Here the idiot plot, which requires James to be an utter dolt (except when it needs him to be suddenly smart) and Darnell a nice guy so desperate to get his daughter (Ariana Neal) into a better school district that he’s willing to demean himself for dough, is more an anchor than a life preserver; they sink under its weight. Nobody in the supporting cast earns high marks, though Edwina Findley and Neal are pleasant enough as Darnell’s wife and daughter. By contrast Nelson is dull as can be, and Brie annoying as King’s selfish fiancée. Nor can much positive be reported about Cohen’s direction, which simply allows the stars space to do their thing, and Mike Sale’s editing, which allows them far too much leeway to do it at inordinate length; or the rest of the technical side of the picture, which is mediocre at best.

The ultimate horror of “Get Hard” is the idea that perhaps the filmmakers thought they were making a comedy that actually said something worthwhile about racial and class distinctions in American society. If so, they bungled the job badly. And if not, they bungled the job badly too.