It is a fact undeniable that raunchy comedy works, as humiliating as it can be to admit this sometimes. Chaucer knew this; Shakespeare knew this. A great many contemporary filmmakers also know this, though it hardly needs to be mentioned that very few of them are working at a level comparable to Chaucer or Shakespeare. Most of them, you might even say, are not working at a level comparable to Chaucer or Shakespeare's dirty socks. But every now and then something manages to rise above the fray and prove that yes! dick jokes and sex jokes and crude slapstick and cursing can be amusing - can be gut-bustingly funny - the stuff of right proper great comedy.

You've no doubt guessed by now that I hold >The Hangover to be exactly such a film. It's filthy and then some (there is one shot, in fact, which makes me genuinely question how it managed to avoid the infamous NC-17 rating), and it is colossally stupid in nearly every way, and it is hilarious. It is said that there's no arguing with comedy: if it makes you laugh, it works. This is really the only thing that it takes for a comic movie to be considered a great movie, (take, for instance, nearly all of the Marx brothers' films: frequently indifferent cinema, but they're almost all rightfully considered classics). Of course, by the same token, comedy is subjective; and it's certain that a healthy subset of the world would find The Hangover perfectly awful, crude and mean-spirited and gross, misogynistic and racist.

The big "however", is that no matter how much one doesn't find The Hangover funny, it cannot be said that it is a failed film - and how often does one get to say nowadays that a funny movie is made conspicuously well? Then let us all be doubly thankful for this, the funniest live-action movie released so far in 2009 and the first film comedy in what feels like years and years but is really only since last autumn that stands up as a motion picture in addition to working as a delivery system for gags. This is a minor surprise: the director, Todd Phillips, was behind Will Ferrell's best vehicle to date, Old School, but that film was hardly great in the ways that would make you think to yourself, "This Phillips kid, he's one to keep an eye on", while the writing team of Jon Lucas & Scott Moore have previously given the world deathless works like Four Christmases and this summer's Ghosts of Girlfriends Past. But everybody has that one great script in them, theoretically, and The Hangover is just a terrifically solid piece of work, as fine a mystery and character study as it is a comedy.

Opening at the end, the film shows us three men somewhere in the desert, looking much worse for the wear: Phil (Bradley Cooper), Stu (Ed Helms), and Alan (Zach Galifianakis). Phil, with great reluctance, has just placed a call to Tracy (Sasha Barrese), a nervous bride on the morning of her wedding, waiting for the groom and groomsmen to show up. Ah, well, Phil, Stu, and Alan are those groomsmen, and the groom is, unfortunately, missing. And thereon hangs a tale.

Two days earlier, the groom Doug (Justin Bartha) heads out to Las Vegas with his two best friends, and Alan, the off-putting manchild who's about to become his brother-in-law. In typically broad comedy strokes, we learn that Phil is married, somewhat happily, but he views the whole institution as a straitjacket; Stu is in year three of a relationship with a tyrannic woman that he loves despite her infidelity and abuse, both emotional and physical. Alan is just fucked-up and weird. Anyway the four men arrive in Vegas, check in, celebrate Doug's impending nuptials with shots of Jägermeister, and then a shockingly elegant time-lapse shot, impeccably choreographed to the song underneath, shows us the passage from night into day, and the groomsmen find themselves in the hellish shambles of a $4200-per-night hotel suite where there was one hell of a party the night before, clearly. A party that the men cannot remember in even the slightest detail, although the slightest detail might help them figure out what happened to Doug.

The first moments of their post-bacchanal arising set up with admirable directness and simplicity all of the unanswered questions that will take up the rest of the movie: why is Stu missing a tooth, whose baby is in the closet, where did the tiger come from, what sent Phil to the hospital, where did they get the cop car, and who are the terrifying men threatening them with guns? And that's all the rest of the movie consists of: answering those questions one by one along the way to solving the biggest mystery of all, the Case of the Disappearing Groom.

I have the highest respect for the care with which the scenario is set up, one pin at a time; and the same respect for the unforced way that each and every single question is resolved, sometimes after a good stretch when both the audience and the characters had forgotten about them. Chekhov would have been proud: not one element (except, maybe, the chicken) is introduced just for the sake of a gag, but each and every point raised in the first part of the movie is answered before the end of the closing credits. To a certain degree, this gives the film an episodic feel, but it is a Quest; a particularly special case of the Quest archetype, structured loosely as a Long Night of the Soul type of story, except that the Long Night happens off-screen during an elegant time-lapse, and what we're watching is the aftermath.

Phillips has a fantastic gift for moving through the episodes will all appropriate speed; in nearly every single case, it's just at the exact second that the gag of the moment starts to get tiresome that the film whisks away to another place. And that's not even touching on the director's visual style, which plays as a subtle (and occasionally not subtle at all) parody of all the many films set in a glamorous storybook Las Vegas: he's not going to win anybody's Director of the Year prize, but the look of the film is far more than merely functional, and that, in particular, is an attribute that's rare on the ground indeed in modern comedy.

And of course, the jokes: which, to judge from what I've written so far, are an afterthought, but that's obviously not the case. As whole-heartedly fratty as the humor can be in The Hangover, it's tremendously smart for a stupid comedy. Laden with callbacks, perfectly timed idiot tricks, boisterously smutty dialogue, and every now and then a sneaky, clever line that proves that the filmmakers had more up their sleeves than just showing men pissing and bleeding ("It's funny because he is fat!" laughs a character at one point, in a marvelously post-modern touch), this is one of the least-guilty pleasures of all the many bawdy films to crop up in the wake of the Farelly brothers.

The cast is, every one of them, in top condition: Galifianakis runs away with the film, getting to play the most complex character (and yet that complexity is entirely a result of his absolute lack of inner life), but nobody is overshadowed, not even the reliably bland Bradley Cooper, who here gets to actually demonstrate any kind of sceen presence at all, and proving wrong those of us who'd written him off as like Ryan Reynolds, but somehow even less so.

I think it's fair to say that I loved this movie: it made me laugh in an easy, juvenile way, and yet it's an assured, taut work of the finest craftsmanship. At the end of the day it's not witty or intellectual, and lord knows it doesn't come within swiping distance of "meaningful", but there is a certain satisfaction in watching the lowest humor carried off with the utmost skill, whether it's in poring over Middle English blank verse, or sitting behind a bucket of popcorn.