In “Dragon Tattoo,” Daniel Craig plays a journalist who teams with Rooney Mara’s Lisbeth Salander. The inspiration for her character came from a horrific assault that author Stieg Larsson witnessed at age 15. Photo: AP

‘The Girl With the Dragon Tattoo” is one of the edgiest and most stylish films of the year, primarily because of its title character, the enigmatic hacker Lisbeth Salander. But where did the iconic rebel come from?

The origins of this dark antihero are twofold and wildly divergent: one a true story of horrific violence, regret and the desire for vengeance, the other a nod to a classic children’s story.

Swedish novelist Stieg Larsson originally called the first book in his Millennium trilogy “Men Who Hate Women.” It was changed internationally to “The Girl With the Dragon Tattoo,” no doubt due to its unpalatable marketing potential, but the first title reflected Larsson’s real views on the grim underbelly of Swedish society, which had affected him very personally.

When Larsson was 15, he went camping with friends in Umea, a town in northern Sweden. Kurdo Baksi, a close friend of Larsson’s, described what happened in the Daily Mail and in his memoir, “Stieg Larsson, My Friend.”

That night, “15-year-old Stieg watched three friends rape a girl, also called Lisbeth, who was the same age as him and someone he knew. Her screams were heartrending, but he didn’t intervene. His loyalty to his friends was too strong. He was too young, too insecure.”

Larsson tried to apologize to the victim later, says Baksi, but she didn’t accept his apology. “It was obvious, looking at him, that the girl’s voice still echoed in his ears, even after he had written three novels about vulnerable, violated and raped women.”

In addition, Larsson was influenced by two murders that took place in 2001 and 2002: first, a Swedish model killed by her boyfriend; second, a Swedish-Kurdish woman who was killed by her father.

For all of these reasons, Baksi concludes, Larsson created the fictional Lisbeth to be a woman who fights back against her attackers and gets revenge, “just as he wished all women would do in the real world.”

But there is also a lighter side to Lisbeth, a nod to one of the best-known children’s series in Sweden: Astrid Lindgren’s Pippi Longstocking, the fiercely independent 9-year-old with bright red hair in ponytails, superhuman strength and intolerance for obtuse adults.

Eva Gedin, Larsson’s Swedish editor, told NPR that the author said point-blank he’d created Lisbeth Salander partly as a vision of Pippi as a grown-up: “She sort of makes up her own rules and is quite a

loner,” Gedin said.

According to the author’s official Web site, he had discussed his thoughts with a co-worker during a break from work one day: They came up with the idea of “Pippi Longstocking, a dysfunctional girl, probably with attention deficit disorder, who would have had a hard time finding a regular place in ‘normal society,’ ” which he then drew on when writing Lisbeth.

Larsson, who died in 2004 of a heart attack shortly before his books became bestsellers, reportedly wrote an e-mail to his publisher in which he specified this idea. “I have tried to swim against the tide compared to ordinary crime novels. My point of departure was what Pippi Longstocking would be like as an adult. Would she be called a sociopath because she looked upon society in a different way and did not have any social competences? She turned into Lisbeth Salander, who has many masculine features.”

There are multiple references to Pippi in “Dragon Tattoo.” Most notable is the nickname for Mikael Blomqvist, the journalist who becomes Salander’s friend and lover: People constantly call him “Kalle” as a nod to Kalle Blomquist, another Lindgren creation.

And then there’s Salander’s typically contrarian reaction to the mention of the pint-size, rebellious redhead (which Salander is in the book, though she dyes her hair black): “Somebody’d get a fat lip,” she says, “if they ever called me Pippi Longstocking.”