You probably knew someone like Mavis Gary in high school. If you didn’t date her, then you most likely hated her. Beautiful, statuesque, popular, occasionally cruel and not unintelligent, girls like Mavis ruled the school — and seemed poised to rule the world.

But Mavis’ life didn’t turn out that way. At the start of “Young Adult,” she is 37, living in Minneapolis, divorced and edging into full-blown alcoholism. Mavis (played by Charlize Theron) ghost-writes young adult novels (think “Sweet Valley High”) and spends her free time gorging on reality TV shows. Her life is as sparse and empty as her apartment, with the exception of the little pet dog she neglects. When she learns her ex-boyfriend (Patrick Wilson) is about to become a father, Mavis returns to her hometown to attempt to liberate him from the shackles of domesticity. To her, marriage and parenthood are death sentences. “Babies are boring,” Mavis observes. This is not the sort of declaration rom-com heroines usually make.

“If a guy said ‘Babies are boring’ in a movie, that might get a chuckle, but it wouldn’t be anything new,” says Diablo Cody, who wrote “Young Adult.” “But a woman of childbearing age saying it is actually pretty radical. I’m a parent now, and I’ve noticed other parents always say ‘There’s never a dull moment with kids!’ But that’s not actually true. Babies can be very boring. Mavis is actually right. And I’m saying that as someone who loves being a mother!”

“Young Adult” is a departure of sorts for Cody, who won a Best Original Screenplay Oscar for the teenage-pregnancy comedy “Juno” and used the demonically possessed cheerleader of “Jennifer’s Body” as an allegory for female empowerment. This is the third film Cody has written, and the first that focuses exclusively on grown-ups. Mavis just happens to be an adult who behaves like an adolescent mean girl.

“I had two goals in mind when I wrote ‘Young Adult’: To create a really unsympathetic curmudgeon and to write a female character who was struggling with arrested development, because we haven’t seen a lot of women playing this kind of role,” Cody says. “But the story became very personal in a way, because I started thinking ‘Why am I writing about teenagers all the time? What is wrong with me? Am I having trouble facing adulthood?’ I projected a lot of that into the script as well. It became something I had to write.”

Cody was working on a film adaptation of “Sweet Valley High” (she promises the movie will be rated a “hard R”) when she got the idea for “Young Adult.” She wrote the script as a personal project and solicited feedback from her friend Jason Reitman, who directed “Juno” and produced “Jennifer’s Body.”

Reitman (“Thank You for Smoking,” “Up in the Air”) loved the “Young Adult” script, but he was already committed to an adaptation of Joyce Maynard’s novel “Labor Day.” When the start of that production got pushed to June 2012, Reitman told Cody he wanted to direct “Young Adult” himself — immediately.

“Six weeks after he called me, he was in Long Island shooting this movie with Charlize,” Cody says. “Writers always dream of things happening that fast. To get a call when you find out that something that was in limbo is suddenly happening, with this amazing Oscar-winning leading lady. … I’m still walking on air.”

Although Cody has proven to be a diverse talent — she also created the Showtime series “The United States of Tara,” is writing the upcoming remake of “The Evil Dead” and will make her directorial debut in the spring with a still-untitled drama about a woman whose life is changed by a plane crash — she is still usually associated with the self-consciously arch dialogue and hipster humor of “Juno.”

“People base that connection on one movie where she used a specific form of writing,” Reitman says. “But I’ve read a lot of Diablo’s stuff, and she writes incredibly nuanced things. What is really special about Diablo’s writing has nothing to do with her word choices, even though they can be very clever. If there’s a connection among all her scripts, it is that she always makes unexpected choices. The second and third acts of her films go to places you wouldn’t expect. That was certainly the case in ‘Juno,’ where every character was a surprise. The entire third act of ‘Young Adult’ is a surprise as well, because none of the things you expect will happen actually happen. I want to direct everything she ever writes.”

“Young Adult” was also a perfect fit for Reitman in another way: Like the tobacco industry lobbyist of “Thank You for Smoking” or the corporate downsizing hatchet man of “Up in the Air,” the prickly Mavis isn’t easy to cozy up to.

“All my main characters have been unlikable or subversive people who I like to make as successful as possible,” Reitman says. “I’m interested in finding the humanity in these characters — something that is usually not seen on screen. And Charlize understood that. She is sneaky in her brilliance. She often makes really hard things seem effortless. This is one of those scripts where you can see how articulated and complete the character is, and you understand why she behaves the way she does. But all that could have been simplified and reduced to a caricature by another actor. The way Charlize plays Mavis, she’s able to create vulnerability and brokenness, without physicality and without dialogue. She’s able to change her nature. She dims the light bulb from within, and in doing so, she makes you feel things for Mavis, even though everything she’s saying is atrocious.”

Theron’s tricky, subtle performance is the secret to the film’s success: You can’t help but feel for Mavis, despite her horrendous behavior. Without that sympathetic connection, “Young Adult” might have been too acerbic to even qualify as a comedy.

“I actually root for her at times too, even though I know it’s wrong,” Cody says. “Charlize loves the character, too. Some people feel affection for her. And other people are just horrified. But Charlize’s performance is so brave. She’s just not afraid of being a bitch, and she never, ever veers away from the black humor of the script. She’s so funny and fantastic that you do cheer her on. It’s fun to watch Mavis wreak havoc on people’s lives.”