Filtered Content: This photo may not be appropriate for work.

General Motors Co posted its biggest quarterly profit in six years on Thursday, a day ahead of an expected IPO filing that would open the gates for the U.S. government to slash its stake in the automaker.

The top U.S. automaker reported second-quarter net earnings of $1.3 billion, compared with $865 million in the first quarter. The second-quarter profit was the largest since 2004.

Sources told Reuters on Wednesday that the largest U.S. automaker had secured a $5 billion credit facility, marking its return to the capital markets a year after it emerged from a government-funded landmark bankruptcy.

The credit facility was a last hurdle toward filing for an initial public offering of stock that allows the U.S. Treasury to reduce its nearly 61 per cent stake in GM — and the automaker to begin to shed its "Government Motors" label.