A New York federal judge may rule imminently on a case that could reverse the General Motors (GM) bailout and send the company back into bankruptcy, according to sources close to the case.

At issue is a backroom deal hatched by GM to fulfill the Obama administration’s demand for a quick bankruptcy, draining the automaker of nearly all of its cash on hand and leaving it in worse shape than it was when it collapsed in 2009.

One condition of GM's bailout was to shore up its overseas subsidiaries. On the eve of entering bankruptcy, the company cut a $367 million "lock-up agreement" with several major hedge funds to prevent GM Canada from failing. The agreement ensured that GM could spin-off its liabilities to "old GM," while using a multi-billion dollar bailout to create a new company.

All of that could be reversed if bankruptcy Judge Robert Gerber reopens the process and rules in favor of old GM trustees, who are suing the hedge funds at the center of the lockout agreement.

"In this particular situation, there’s $1.3 billion in liabilities, but that’s just what’s officially back on the table if the court rules for old GM," said a bankruptcy expert close to the negotiations. "If those go back on the table then everything could be back on the table and [new GM] would have to address them."

Those liabilities, which include old GM’s debt and product liabilities that pre-date bankruptcy, are valued at $30 billion, a sum that would wipe out the company’s $34.6 billion cash reserves.

Negotiators representing both sides of the case met in New York on Thursday to try to settle the suit through mediation rather than a court order.

"They’re feeling pretty good about it," said an industry insider who spoke to one of the hedge fund negotiators on Thursday.

Gerber, the federal judge who initially approved the sale with little hesitation, now has the power to reverse the entire auto bailout. He has expressed deep frustration with the company for failing to disclose the deal, leading some to speculate that he may overturn one of President Barack Obama’s signature achievements.

"When I approved the sale agreement and entered the sale approval order I mistakenly thought that I was merely saving GM, the supply chain, and about a million jobs. It never once occurred to me, and nobody bothered to disclose, that amongst all of the assigned contracts was this lock-up agreement, if indeed it was assigned at all," Gerber said in July.

"The judge has made it very clear that he is greatly dissatisfied with the process," one analyst told the Washington Free Beacon in October. "He’s basically implying that GM hid it from him and that reopening the sale is a possibility."

If Gerber takes that course the company could be forced to return the $30 billion taxpayer bailout that it received through the course of bankruptcy, on top of the new liabilities.

"It’s nice to see that GM is profitable again, but if all the liabilities come back to roost, short that stock," the bankruptcy expert said.

A GM spokesman declined comment since the litigation is pending.

The Canadian and American governments played vital roles in the deal and pushed GM to negotiate as quickly as possible.

"Officials from the U.S. and Canada were very much involved—they were in the building when the deal was being negotiated," an insider familiar with the deal said in October.

The Treasury Department, which oversaw the auto bailout, did not return emails for comment.

The company is taking the possibility of a negative ruling from Gerber very seriously. GM attorneys filed court documents saying that the lawsuit "could create a chaotic situation for GM Canada, spawn new litigation in other forums, and potentially provide a windfall to the noteholders."

The bankruptcy expert said if the two sides cannot come to an agreement on Thursday, Gerber could preside over one of the most historic rulings in bankruptcy court history.

"This has tremendous implications for future of American business and bankruptcy precedent," he said. "It means more than just GM—this is the rule of law and how creditors are treated in the United States legal system."