After filing for bankruptcy five years ago, General Motors is now one of the most profitable companies in the world.

GM has earned a stunning $22.6 billion since the dark days of the financial crisis, when the automaker was bailed out by the U.S. government. Taxpayers didn't fare nearly as well. They'd lost $10.6 billion by the time the U.S. Treasury department closed the books on the $49.5 billion bailout in December.

GM (GM), which filed for bankruptcy five years ago this Sunday, has repaid everything it was obligated to pay Treasury. Taxpayers came up short because the U.S. decided to buy GM stock to keep the automaker alive instead of giving it a loan and saddling it with more debt.

Although GM has been very profitable since 2009, its stock price never rose to a level that let Treasury to recoup that investment.

"Our goal was never to make a profit but to stabilize the auto industry," said one Treasury official on background the day it sold its final GM shares. "By any measure, we succeeded."

Related: GM cars sold: 12.1 million. Recalled: 13.8 million

GM is now one of the 40 most profitable companies in the nation. It's more profitable than a third of the companies in the Dow, including Verizon (VZ), American Express (AXP), Boeing (BA) and 3M (MMM).

But the costs related to its controversial ignition switch recall essentially wiped out its profit in the first quarter of this year. GM estimates that repairs to the 15.8 million vehicles it's recalled this year will cost at least $1.7 billion. And that doesn't include any legal costs, fines or victim payouts that it will face.

GM has admitted that its employees knew of an ignition switch problem in millions of its cars about a decade before it ordered a recall in February of this year. The flaw has been tied to at least 13 deaths, though government safety regulators expect that death toll will rise once the investigation is complete.

Critics of the GM bailout say the deal should have been structured so that a portion of future profits would go to repay taxpayers.

"We're certainly glad they're making a profit now, but it would have been nice if there had been clawback provisions to make taxpayers whole," said Scott Hagerstrom, Michigan state director of the Americans for Prosperity, a public interest group opposed to government spending.

Related: Taxpayers made $52 billion on Geithner's bailouts

GM said that if it paid the Treasury more than it owed under terms of the rescue plan, the automakers' shareholders could sue.

Taxpayers also lost $1.3 billion on the bailout of Chrysler Group, but made money overall on the $700 billion in federal bailouts issued during the financial crisis.

GM's post-bankruptcy profitability is in stark contrast to the $100 billion it lost in the 4-1/2 years leading up to its filing. The bankruptcy helped it reach new labor agreements, and shed debt, non-productive factories and weak brands and dealerships.

"We will always be grateful for the second chance extended to us and we are doing our best to make the most of it," said then GM CEO Dan Akerson on the day the U.S. sold its remaining GM stake.