Microsoft founder Bill Gates Yana Paskova/Getty Images

Microsoft had shifted at least $39 billion in US profits to Puerto Rico back in 2005, where its tax consultants at KPMG had persuaded the territory's government to give Microsoft a negligible tax rate.

The IRS decided to take a stand against the company, and embarked on an investigation that it believed would show Microsoft's scheme to avoid taxes.

Microsoft fought back by rallying business and trade groups like the US Chamber of Commerce, hiring aggressive attorneys, lobbying Congress and eventually persuading Congress members to propose laws would remove or limit the tools that the IRS could use.

This month, a judge ruled that all Microsoft's KPMG documents needed to be turned over because the firm had promoted a tax shelter: "a significant purpose, if not the sole purpose, of Microsoft's transactions was to avoid or evade federal income tax."

Meanwhile, the 12-year audit drags on under an agency that has suffered budget cuts and has been drained of resources.

Visit Business Insider's homepage for more stories.

ProPublica is a Pulitzer Prize-winning investigative newsroom. Sign up for The Big Story newsletter to receive stories like this one in your inbox.

Eight years ago, the IRS, tired of seeing the country's largest corporations fearlessly stash billions in tax havens, decided to take a stand. The agency challenged what it saw as an epic case of tax dodging by one of the largest companies in the world, Microsoft. It was the biggest audit by dollar amount in the history of the agency.

Microsoft had shifted at least $39 billion in U.S. profits to Puerto Rico, where the company's tax consultants, KPMG, had persuaded the territory's government to give Microsoft a tax rate of nearly 0%. Microsoft had justified this transfer with a ludicrous-sounding deal: It had sold its most valuable possession — its intellectual property — to an 85-person factory it owned in a small Puerto Rican city.

Over years of work, the IRS uncovered evidence that it believed laid the scheme bare. In one document, a Microsoft senior executive celebrated the company's "pure tax play." In another, KPMG plotted how to make the company Microsoft created to own the Puerto Rico factory — and a portion of Microsoft's profits — seem "real."

Meanwhile, the numbers Microsoft had used to craft its deal were laughable, the agency concluded. In one instance, Microsoft had told investors its revenues would grow 10% to 12% but told the IRS the figure was 4%. In another, the IRS found Microsoft had understated revenues by $15 billion.

Determined to seize every advantage against a giant foe, the small team at the helm of the audit decided to be aggressive. It used special powers that the agency had shied away from using in the past. It took unprecedented steps like hiring an elite law firm to join the government's side.

To Microsoft and its corporate allies, the nature of the audit posed a dire threat. This was not the IRS they knew. This was an agency suddenly committed to fighting and winning. If the aggression went unchecked, it would only encourage the IRS to try these tactics on other corporations.

"Most people, the 99%, they're afraid of the IRS," said an attorney who works on large corporate audits. "The other 1%, they're not afraid. They make the IRS afraid of them."

Microsoft fought back with every tool it could muster. Business organizations, ranging from the U.S. Chamber of Commerce to tech trade groups, rallied, hiring attorneys to jump into the fray on Microsoft's side in court and making their case to IRS leadership and lawmakers on Capitol Hill. Soon, members of Congress, both Republicans and Democrats, were decrying the IRS' tactics and introducing legislation to stop the IRS from ever taking similar steps again.

The outcome of the audit remains to be seen — the Microsoft case grinds on — but the blowback was effective. Last year, the company's allies succeeded in changing the law, removing or limiting tools the IRS team had used against the company. The IRS, meanwhile, has become notably less bold. Drained of resources by years of punishing budget cuts, the agency has largely retreated from challenging the largest corporations. The IRS declined to comment for this article.

Recent years have been a golden age for corporate tax avoidance, with massive companies awash in profits routinely paying tax rates in the single digits, or even nothing at all. But how corporations manage to do this and keep the IRS at bay is mostly shrouded in secrecy. The audit process is confidential, and the IRS, for all its flaws, simply doesn't leak. Microsoft's war with the IRS offers a rare view into how a giant company maneuvers to avoid taxes — and how it responds when the government tries to crack down. ProPublica has reconstructed the fight from thousands of pages of court documents, information obtained through public records requests and accounts from current and former IRS employees.

Microsoft declined to discuss its taxes in any detail. In response to extensive questions provided in writing, the company said it "follows the law and has always fully paid the taxes it owes."

"We would all benefit from a resurgence of moderation and heightened regard for principle."

In 2010, the IRS announced that it was creating a new unit to audit international, intra-company deals. Tech, pharmaceutical and other giants had figured out how to use these dubious deals to avoid taxes on a colossal scale. It was hardly a secret: News articles had detailed how Google, Pfizer and others saved billions. Senate hearings ensued.

Despite the publicity, nothing changed. The trend, which had taken off in the 2000s, intensified. The losses to the U.S. Treasury in uncollected taxes ran well into the hundreds of billions of dollars. In 2016 alone, according to an estimate by economists including Gabriel Zucman of the University of California, Berkeley, U.S. corporations avoided $61 billion in taxes by sending profits to tax havens.

The concept was simple. A U.S. company sold its most valuable asset — for a tech company, its intellectual property — to a subsidiary in a place (Ireland, Singapore, Puerto Rico, etc.) where the tax rate was extremely low.

The details of these deals were monstrously complex, making it difficult for the IRS to prove they were done solely to dodge taxes. Essentially, the IRS had to argue that the company had set the wrong price for its intellectual property. And to do that, the agency had to understand the company, its markets and its prospects top to bottom. It was a near-impossible task, and the IRS suffered some key losses in court, which only emboldened companies to stake out even more aggressive positions.

In 2011, the IRS picked Samuel Maruca to lead the new unit. A partner at the prominent law firm Covington & Burling, Maruca had spent decades advising corporations on "transfer pricing," as this area of tax is called, and facing off against the agency on audits. He came to the job, he said, to help fix a broken system.

Maruca is the picture of a tax lawyer (thinning hair, glasses). But unlike many of his colleagues, he expresses himself clearly, sometimes in moral terms. He told peers at industry conferences that the nation's corporations had grown excessively bold. "We would all benefit," he said, "from a resurgence of moderation and heightened regard for principle."

To restore balance, the IRS "must produce some winners," he said. "I really want to make a difference."

Maruca built a team of about 60 — agents, attorneys and economists — with half recruited from outside the agency. For the IRS, this was a notable influx of talent. But it was still modest when compared with the scale of the challenge.

Among the key advisers on the new team was Eli Hoory, an attorney who had worked under Maruca at Covington and followed him over to the IRS a few months later. Hoory, then in his mid-30s, had a shaved head and prominent nose that gave him an angular appearance. Known for being extremely bright, he was also frank and outspoken, sometimes to a fault. A graduate of the U.S. Coast Guard Academy, he'd served as a reservist during law school and studied at the London School of Economics before landing at Covington.

Maruca and his team set about canvassing the IRS' inventory to find good targets for producing "some winners," as he'd put it.

Microsoft's Puerto Rico deal almost slipped by. The week before Maruca started at the IRS in May 2011, the agency, which had already been auditing the transaction for four years, completed its work and sent Microsoft its findings.

That 2011 assessment by the IRS isn't public, but it's clear Maruca and Hoory were unimpressed. The IRS, they thought, had been credulous, accepting too many of Microsoft's numbers. They also thought the IRS was set up for failure. The agency had been able to retain only one outside expert, an economist. If the case went to court, Microsoft would surely summon a cast of varied experts to undermine the IRS' position.

It seems likely, given the size of Microsoft's Puerto Rico transaction, that the IRS in May 2011 had hit the company with a tax bill in the billions. But Maruca and Hoory thought the agency was thinking small.

Maruca told Microsoft the IRS needed more time, and in early 2012, the IRS withdrew its findings. By then, Hoory had taken leadership of the audit. He began sending new document requests to Microsoft, asking for more interviews and considering what other experts the IRS needed to round out its case. Over the next three years, he and his team amassed tens of thousands of pages and conducted dozens of interviews with Microsoft personnel. (Hoory, who still works at the IRS, declined to comment.)

The evidence they assembled told a story. It revealed how Microsoft had built a massive Rube Goldberg machine that channeled at least $39 billion in profits to Puerto Rico. It revealed a workshop of outside consultants, economists and attorneys who, as they had with other corporate clients, meticulously planned a structure that seemed to have a basis in the law, even if it violated common sense.

The documents showed that Microsoft had been caught red-handed, Hoory believed. Despite all their care in preparing for an eventual audit, the deal's architects had left damning evidence that, he thought, made it possible for the IRS to expose the sham.

In 2003, Microsoft had a decision to make. Since 1989, it had operated a manufacturing facility in the small city of Humacao at the eastern end of Puerto Rico. The factory existed because of a tax break, and that break was due to expire after 2005.

A 2003 company memo laid out the quandary. Microsoft had about 85 employees in Humacao burning Windows and Office software onto CDs. Doing that in Puerto Rico had saved the company almost $200 million in taxes over the years. Closing the plant and outsourcing Microsoft's CD production when the tax break expired was the obvious choice. "The cost to manufacture one CD [in Puerto Rico] is from 1.4 to almost three times the cost of outsourcing," the memo said.

There was one alternative to closing the plant, but it would "require very aggressive tax structuring and work," according to Microsoft's head of international tax, Glenn Cogswell, as cited in the 2003 memo. Microsoft could create a new tax advantage by using the factory as a means to stash U.S. profits. The memo dismissed that option as impractical.

But the next year, Microsoft changed its mind. KPMG, one of the "Big Four" accounting firms, made a persuasive pitch. Microsoft should engage in that very aggressive tax structuring, after all.

KPMG had "significant experience assisting Fortune 50 companies" faced with the same problem, according to a July 2004 PowerPoint presentation to Microsoft executives. KPMG could do for Microsoft what it had done for those other giant American corporations: send U.S. profits to the island.

Puerto Rico — which has an autonomous tax system even though it's a U.S. territory — didn't have a particularly low tax rate, but KPMG could fix that. Its partner in the San Juan office, the PowerPoint said, had "previously advised several U.S. clients on migrations of this type and successfully negotiated significant tax holidays for U.S. companies with the Puerto Rican government."

The next month, a team of Microsoft executives met with KPMG to hash out the details. They made sure not to leave a paper trail. "This needs to be a verbal briefing with no handouts and no e-mail," wrote Bill Sample, a senior Microsoft tax executive, in an email scheduling the meeting. "We will do this on the white board."

Shuttling company profits from country to country was not a new idea for Microsoft. Not long before, it had conjured deals to send its profits in Asia to Singapore and its profits in Europe and Africa to Ireland. The Puerto Rico transaction, which would cover North and South America, would be the biggest and boldest yet.

Here's how it would work. Microsoft's Puerto Rican subsidiary would produce all the CDs for the American market. Because it was the sole producer, it would buy the exclusive rights to Microsoft's technology. Those licenses would entitle the Puerto Rican company to a share of Microsoft's American profits.

According to Hoory's calculations, the factory subsidiary would send the parent company about $31 billion over 10 years — and receive almost $70 billion in profits in return over the same period. Instead of being taxed in the U.S., where the rate was 35%, the $39 billion difference between those figures would be taxed in Puerto Rico at a rate near 0%. It was a long-term plan that could continue indefinitely.

It didn't matter that the transaction was fundamentally absurd. Microsoft would never actually sell its most valuable asset to another company, let alone to a little tropical factory. Still, there were rules for constructing and valuing deals like this, and Microsoft and KPMG set out to prove they were following them.

Minutes from meetings involving KPMG's experts show them straining to fit the details together. "This work needs to be very detailed and [have] incredibly great documentation to refute any IRS issues," read the notes for one meeting in March 2005.

One problem was that there was a rush to get the deal done that summer, but Microsoft's factory wouldn't be ready to produce 100% of the CDs that soon. As a result, the new Puerto Rican subsidiary would only be a company on paper, while the old Puerto Rican company was still pumping out CDs. In order for the transaction to seem genuine, the new Puerto Rican subsidiary needed to appear to be bona fide.

"What can we do to make this thing real?" was the question, according to the notes for another KPMG meeting. They had an answer: "Go out and do something substantial, so go out and use insurance. Point to a contract with a third party … [that] shows that something real is being done."

The spitballing continued when KPMG's team met with a group of Microsoft employees a few days later. "What happens when all info sent online?" was another conundrum, according to meeting notes. If customers downloaded the software instead of getting it on a CD that was produced in Puerto Rico, would the premise of the deal — that it was based on CD manufacturing — be undermined? They ultimately decided that wasn't a problem, "because customers seem to want CDs, and we'll put the servers down in PR and send them CDs too."

KPMG kept its promise to land a rock-bottom rate from the Puerto Rican government. In exchange for Microsoft's promise to hire an additional 46 full-time employees, Puerto Rico's secretary of state agreed to grant the company a tax rate that ranged from 0% to 2% for a period of 15 years. A spokesman for KPMG declined to comment.

"Deal of the Century Return on Investment"

By the next year, Microsoft had shifted all CD production for the Americas to Puerto Rico. In a written self-evaluation, a Microsoft executive celebrated: "This was a pure tax play and because we took the factory live by July 1 we were able to start claiming the tax benefit as planned."

But Microsoft wouldn't be telling the IRS the transaction was a pure tax play. The two sides of the transaction were supposed to arrive at a fair, "arm's length" price, one that an unrelated company might pay to another. Of course, Microsoft was dealing with itself, and no company of its size had ever sold anything like what it was selling. So, to arrive at a price, KPMG's economists generated complicated models. These would provide protection if the IRS questioned Microsoft's numbers. The price was supposedly impartial, based on a thorough analysis of all the relevant variables.

One document in particular exploded this fallacy, Hoory believed. Shortly after the deal went live, a consulting firm delivered a report to Microsoft about the Puerto Rican subsidiary. It valued the company at $30.4 billion. As Hoory later testified, the document was "effectively saying a company that was worth nothing or a nominal amount on June 30th, 2005, was worth $30 billion one day later."

On Jan. 14, 2014, Hoory stepped in front of a room of Microsoft executives and attorneys from Baker McKenzie, Microsoft's law firm for the audit. It was his first presentation of his team's findings. He did not hold back, showing slide after slide that detailed the distortions and errors of the Puerto Rico deal.

"Deal of the Century Return on Investment" said one slide. According to the IRS' analysis, the Puerto Rican subsidiary had been set up to reap a 200% annual return. It meant that Microsoft's price for the transaction was not remotely plausible.

Hoory argued that just about every aspect of the deal should be valued differently. Just what those numbers were is not public, but it's clear he thought Microsoft had caused the Puerto Rican subsidiary to substantially underpay for the software rights while overestimating how much profit the U.S. operation could legitimately send to Puerto Rico.

The presentation put Microsoft on notice. Their big, bold Puerto Rican deal was the target of a big, bold audit. After Hoory finished his presentation, Microsoft's tax team "said they had to think a little," Hoory later testified.

Hammer the little guys and let the big guys go

It's routine for IRS agents to share initial findings with corporations under audit. The point is to see whether the two sides might come to an agreement or at least agree on certain aspects and narrow the number of issues under dispute. That was part of Hoory's mission that day.

But a month later, Microsoft told Hoory and Maruca that it did not want to discuss resolution. Instead, the company wanted the IRS to finalize its findings. With that in hand, Microsoft could then move the fight to another part of the IRS: the Office of Appeals. There, Microsoft had good reason to think it would fare much better.

The Office of Appeals provides taxpayers big and small with an independent review. If an agent has gotten it wrong, appeals can fix it. The office also aims to stem the flood of tax disputes into the courts. It's where taxpayers go looking to cut a deal.

IRS agents often grouse about working hard on an exam only to see an appeals officer slash the amount of tax owed. To some veterans, the Office of Appeals is known as "the gift shop."

"No question, Exam hates Appeals," said Gerry Ouellette, who served as an appeals officer on large corporate cases until 2012 and now works with a Boston firm that advises taxpayers facing audits.

But there's a logic to the slashing, he said. One reason that tax bills are cut is because the IRS fears it may lose in court. Appeals officers are supposed to judge the "litigation hazard" of a case and put a number on it. For instance, an appeals officer who thinks the IRS is only 30% likely to prevail in court might settle for 30 cents on the dollar.

That's particularly likely to happen on large, complex audits. According to a 2016 report by the IRS' inspector general, appeals of transfer pricing audits reduced the amount of tax owed by an average of 81%.

Appeals officers often feel pressure to be lenient, said Willie Chin, a recently retired Appeals officer who handled corporate cases. "If I have to give up the penalty to resolve the case, to move the case along, that's the idea: to move the case along," he said. Large corporations rarely face penalties at all, a 2019 report by the IRS' inspector general found, and when they do, they can count on an appeal to reduce or eliminate the penalties 94% of the time.

The story is different for taxpayers who aren't represented by a battalion of attorneys and CPAs, Chin said: "In my opinion, we hammer the little guys and we let the big guys go."

Maruca and Hoory knew all this. It was no mystery why Microsoft was so eager to appeal. But they also knew they could prevent it.

The IRS has the power to "designate a case for litigation" — in other words, force a taxpayer to skip Appeals and go straight to court. It is a move sure to anger a powerful adversary. Not only does an appeal offer the corporation a good opportunity to see the audit overturned, but it does so with the promise that it will keep the details quiet. The U.S. Tax Court, by contrast, is a public forum.

In March 2014, Hoory told Microsoft that the IRS was considering designating the case for litigation. The case was just too big and unique to send to Appeals. "It is such a huge divergence in numbers," he later testified, "and we have put a lot of energy into it."

Hoory's move was aggressive, but not unprecedented. From 2010 through April 2019, the IRS designated 13 cases for litigation, according to agency documents ProPublica obtained through a public records request. The IRS refused to divulge a list of those cases, but the known instances include other large corporations facing transfer-pricing audits: Amazon, Coca-Cola and Facebook.

Maruca and Hoory had other, more radical ideas on how to tackle such a massive case.They wanted to hire a high-powered outside attorney to help the IRS. In the past, they believed, the IRS had failed in court on big, complex cases for two main reasons. The first was that the agency hadn't done enough work uncovering evidence. It was an error they were well on their way to fixing, they thought. The other stumbling block was the agency's inability to make a persuasive argument and tell a compelling story to a judge.

Maruca and Hoory wanted a legal star, someone with the experience of winning an enormously complex case against a gigantic foe. But such attorneys are typically found in elite law firms, where large corporate clients might balk at the firm representing the IRS.

Maruca and Hoory concentrated on finding top attorneys who didn't usually handle tax matters. Their first choice was David Boies. He had beaten Microsoft before, when he represented the Justice Department in its landmark 1998 antitrust lawsuit against the company. But Boies had another case that created a conflict of interest and couldn't take the assignment.

The IRS' next choice was Quinn Emanuel, which describes itself as a "global litigation colossus without equal." That fit the bill. In May 2014, the two sides signed a $2.2 million contract. It provided for two of the firm's top partners, John Quinn and John Gordon, each of whom bill more than $1,000 an hour, to spend hundreds of hours on the case along with a small team of other Quinn Emanuel lawyers.

The IRS did this quietly. It wasn't until late August 2014, on the third page of a letter to Microsoft about scheduling further employee interviews, that Hoory let word slip. The IRS "will have one or more contractors attend," he wrote. This "may include outside counsel from Quinn Emanuel."

It didn't go unnoticed. For the next week, Hoory and Mike Bernard, then Microsoft's U.S. tax counsel, fired letters back and forth. Microsoft requested a copy of the IRS "engagement letter" with Quinn Emanuel. Hoory, apparently determined not to be too helpful, responded that there was none. When Bernard expressed disbelief and asked more generally for any contract, Hoory sent over a copy of the main section of the contract.

Microsoft was "deeply concerned" about the role of Quinn Emanuel, Bernard wrote, because the firm represented Microsoft competitors like Google and Motorola. He asked Hoory for more details. "We have conflict, confidentiality and ethical concerns," he wrote.

Hoory responded but also urged Microsoft to make it clear whether it would allow the Quinn Emanuel attorneys to participate in the interviews. When Bernard again asked for more detail, Hoory wrote that he'd been accommodating, but "we are at a decision point now." Would Microsoft prevent the Quinn Emanuel attorneys from questioning witnesses? "If you do not agree or do not respond, the Service will consider alternatives," Hoory wrote.

A few weeks later, Hoory arrived at Microsoft's Redmond, Washington, headquarters with a team of a few other IRS employees, a couple hired experts and Gordon of Quinn Emanuel. On Microsoft's side, two senior tax executives and a group of Baker McKenzie attorneys attended the interviews.

Microsoft's outside attorneys kept a close watch on Gordon, the IRS' outside attorney. Whenever Gordon repeatedly pressed a Microsoft employee for an answer, Daniel Rosen of Baker McKenzie jumped in. "This is being done under the proviso that you guys control this," Rosen told Hoory, according to a transcript of one interview. "If you don't control Mr. Gordon, then this is over." A few days later, when Gordon pushed another Microsoft employee to clarify an answer, the scene repeated. "We're done with this line of questioning," Rosen said. "And Mr. Gordon's not directing this witness to answer any questions," he said, "Mr. Hoory can, but this gentleman cannot."

By this time, the investigation had grown intense. Hoory and his team were racing to put their case together while pushing Microsoft to provide more documents. They were up against an approaching deadline. At the end of the year, the statute of limitations would expire. The law gives the IRS three years to complete an audit, and Microsoft had agreed several times to give the IRS more time, as large corporations often do. Microsoft had done this because it was hoping to resolve the audit without a messy court battle. Now that hope was gone, and there would be no more extensions.

As the clock ticked down, Hoory considered his options. Microsoft had both buried the IRS in paper — sending over 1 million pages, much of which Hoory later said wasn't relevant — and, in his view, failed to send everything the IRS had asked for. If he hurriedly wrapped up the case, he ran the risk of missing crucial pieces of evidence. The stakes, he decided, were too high. So, yet again, he decided to take a remarkable step.

In audits of large corporations, the law grants the IRS a special power. It can issue a "designated summons" for documents and interviews that, with the approval of a federal judge, temporarily stops the clock. After the summons is resolved, the clock starts again. It's a muscle move that wrenches away any control the corporation has over the audit.

Before Maruca and Hoory arrived in 2011, the IRS had not used this tool since 1996. Partly, that was because it clashed with an IRS culture that valued amicable relations with the country's largest taxpayers. There was also the potential cost to antagonizing powerful opponents. But for Hoory, these were secondary concerns. In October 2014, the IRS issued a designated summons to Microsoft, demanding 48 categories of documents.

The IRS also summoned for interviews a roster of Microsoft employees, including Steve Ballmer, who'd recently left as CEO. KPMG, too, got a summons. The IRS then filed suit in a federal court in Seattle to enforce its demands.

Microsoft set out to quash the summonses. Its attorneys argued that federal rules exclusively permit IRS employees to question witnesses. The IRS had broken the law by allowing the Quinn Emanuel attorneys to question witnesses, according to Microsoft, and by essentially putting them in charge of the audit.

It was fundamentally wrong for the IRS to use high-powered litigators, one Microsoft attorney argued in a hearing, because "they know how to win, and that's very different" than the IRS' mission. The IRS was supposed to work with taxpayers to "find the right number," she said, not focus on winning.

The marks of Quinn Emanuel's obsession with winning were all over the IRS' actions, Microsoft's attorneys contended. It was the hired sharks who'd prompted the agency to deluge Microsoft with more document and interview requests. It was their idea to force those interviews to be under oath, as opposed to the more common IRS practice of conducting "informal" interviews. And it was their idea to knock on Ballmer's door with a summons. "It's not unusual, in high-stakes litigation," said one of Microsoft's attorneys, for law firms "to try to put pressure on their opponent by doing things like asking to depose the CEO."

The dispute over the summons became an opportunity for Microsoft to put Hoory — and the sort of IRS that he represented — on trial. Hoory took the stand to defend the IRS' actions.

At the hearing in August 2015, Philip Beck handled the questioning for Microsoft. A top litigator, he'd once been a hired gun for the government himself, having replaced Boies as counsel in the antitrust case against Microsoft. Now he was on Microsoft's side, arguing against the government's use of outside counsel.

Beck found Hoory to be a frustrating quarry. He would not be pinned down and had a detailed explanation for everything. After an hour of this, Beck complained, "Your Honor, we are never going to get done today if I get 10-minute answers for yes or no questions." The judge urged Hoory to be briefer. "I will do my best, Your Honor," Hoory replied.

Beck's frustrations continued as Hoory clouded the simplicity of Microsoft's case. But in one area, Hoory allowed a simple answer. Beck asked: Wasn't this "the first time in the history of the universe" that the IRS had hired an outside law firm to help conduct an audit?

Hoory said that was correct, adding, "I guess I am a trailblazer."

Microsoft's complaints grew louder when Hoory and a Justice Department attorney presented the IRS' side. In addition to laying out the Puerto Rico transaction, Hoory divulged details that made an obvious tax dodge look even worse. Microsoft's lawyers called that "mudslinging" meant to "punish" the company "for daring to oppose the IRS."

Hoory testified that Microsoft had used a growth rate of 4% for tax purposes while publicly reporting to investors expected growth of 10% to 12%. One error in their calculations, he said, had "understated revenues by approximately $15 billion."

After almost four hours of testimony, Hoory stepped down. "It has been a long day," U.S. District Court Judge Ricardo Martinez said. "Mr. Hoory talks a mile a minute, and it was hard to follow up on all of that." He added, turning to Hoory, "Working for the IRS is a good job for you."

Microsoft, meanwhile, was fighting on other fronts, too. Its attorneys pursued Freedom of Information Act requests to dig up as much as they could about the Quinn Emanuel hiring, eventually filing several lawsuits to force the IRS to turn over documents.

The company also turned to its friends in Congress for help. In May 2015, Sen. Orrin Hatch, R-Utah, then the chair of the committee that oversees the IRS, and who counted Microsoft as one of his top campaign contributors, fired off a letter to the IRS commissioner about "outsourcing" the agency's audit of "a corporate taxpayer." That "appears to violate federal law and the express will of the Congress," he wrote, and the $2.2 million contract "calls into question the IRS' use of its limited resources." By that time, Republicans in Congress had cut the IRS' budget by $1.5 billion from its 2010 peak. (A spokesperson for Hatch declined to comment.)

Hatch asked the IRS "to immediately halt" Quinn Emanuel's work on the case. Microsoft filed a copy of the letter in court a few days later.

But Martinez ruled in favor of the IRS and its use of the special summons to suspend the statute of limitations and demand additional documents. He wrote that he was "troubled" by the IRS' use of outside counsel since it was unprecedented and that the hiring might "lead to further scrutiny by Congress." But, he wrote, "Microsoft has no factual basis for the grand assertion that Quinn Emanuel was or will be engaging in taxation or conducting the audit." Rather, the firm's role was "limited" and "under the direct supervision of the IRS."

The IRS had clear legal authority to hire Quinn Emanuel and for its attorneys to question witnesses, the judge ruled. Microsoft would have to comply with the summons.

It was a setback for Microsoft. But as the court case ground on, the company and its allies went to work on Capitol Hill to make sure something like this never happened again.

In the autumn of 2015, a new trade group emerged. It was called the Coalition for Effective and Efficient Tax Administration, or CEETA. Among the members were Microsoft, the U.S. Chamber of Commerce and a host of other business and tech groups. The new coalition hired lobbyists at PwC, another Big Four firm and one with a stable of well-connected former government officials and congressional staff.

The new group's clout soon became clear. In October 2015, just a few days after CEETA members fired off a letter to the IRS decrying the use of outside counsel on audits, Pam Olson, one of CEETA's PwC lobbyists, sat down for a two-hour meeting with Doug O'Donnell, the head of the IRS division that audits large corporations.

"When it comes to the tax law, I don't like the word 'enforcement,'" Olson, who oversaw tax policy as a Treasury Department official in the early 2000s, said in a speech to corporate tax executives that December. "Let's remember that the agency is the Internal Revenue Service," she said. Olson forwarded a copy of her speech to O'Donnell, who responded, according to emails obtained by ProPublica, "Thanks for sharing — I appreciate your perspective." He said he would pass it on to other senior IRS officials.

CEETA's lobbyists stalked the halls of Congress, urging reforms in response to the IRS' newfound aggression. They found a ready audience. In late 2015, a senior aide to Hatch participated in an online seminar for tax professionals along with a senior Microsoft executive. According to a description, participants discussed "the actions of an increasingly aggressive IRS" and the need for reform. (The aide, Christopher Armstrong, has since left Congress and now works as a lobbyist. He did not respond to requests for comment.)

"Focusing on litigation destroys cooperative relationships between taxpayers and the IRS," read a document distributed by CEETA's lobbyists to lawmakers around that time and obtained by ProPublica. The proposals targeted the three bold steps Hoory had taken in the Microsoft audit: CEETA wanted lawmakers to curtail the IRS' ability to block taxpayers' access to the Office of Appeals, rein in the use of designated summons and prohibit outside lawyers from questioning witnesses.

The IRS had used these tools to audit one of the world's largest companies and in few other cases. From 2010 through 2019, it blocked appeals in 13 cases (not counting Microsoft's), used a designated summons in one case other than Microsoft's and hired an outside attorney on an audit once. By comparison, from 2010 through 2018, the IRS completed about 18,000 audits of corporations with assets above $1 billion.

But CEETA members warned that the tactics posed a threat to small businesses. The leader of one tech group testified before the House Committee on Small Business about the IRS' use of "intimidation tactics." And the Small Business and Entrepreneurship Council sent a letter to Sen. Rob Portman, R-Ohio, warning that small business owners "certainly do not have the resources to go up against a powerful $1,000-an-hour legal team in a tax dispute."

A spokesman for CEETA, Brian Cove of Financial Executives International, said in a statement, "CEETA believed that IRS audit process changes often spread from one part of the IRS to another and could have an impact on small businesses."

Portman introduced a bill that followed all three of CEETA's recommendations. The next year, a bipartisan group of House lawmakers introduced a bill that largely mirrored Portman's. CEETA cheered both times. (The lawmakers declined to comment.) Microsoft, Coca-Cola and Facebook, all companies that had had their path to appeals blocked, lobbied to support one or both bills, along with a collection of tech and business groups.

The ideas were ultimately included in a large, bipartisan bill called the "Taxpayer First Act" with a wide range of IRS reforms. The bill contained provisions similar to what CEETA had sought, though milder. The IRS would have a new process to follow in order to block appeals or designate summonses and would have to report to Congress when it did so. And the agency would now be barred from using an outside attorney to question a witness under oath. The bill passed overwhelmingly and was signed into law in July.

CEETA's success sent a clear message to the IRS, one the agency appears to have heeded. In 2016, for example, when the IRS was locked in a battle with Facebook, the agency considered using a designated summons since the statute expiration was approaching. But the IRS did not use it, even though, according to an agency court filing, "the examination team had not completed its fact gathering efforts when the clock ran out."

The era of daring, new initiatives has passed at the IRS. Instead, the agency appears to have largely avoided picking fights with large corporations and embraced the sort of cooperation urged by Microsoft and CEETA. In part, this is because the IRS is simply too weak. The agency has lost more than a third of its enforcement staff since 2010, and the result has been fewer audits. For corporations with assets over $20 billion, the audit rate has declined from about 100% in 2010 to under 50% in 2018.

The makeup of those remaining audits tells a story, too. The number of contentious audits, where corporations disagreed with the agency's findings, have plummeted from 185 to 25, a drop of 86%. But audits that ended in agreement have stayed relatively steady over the years. Not surprisingly, audits ending in agreement tend to result in relatively small adjustments.

Microsoft, meanwhile, has continued to reap the benefits of its offshore deals. In 2017, the last year before the new tax law cut the corporate rate from 35% to 21%, Microsoft paid $2.4 billion in taxes on $29.9 billion in income, a rate of 8%. By that point, Microsoft had stored $142 billion in profits offshore, according to its public filings. Only two other U.S. companies had accrued more, according to the Institute on Taxation and Economic Policy: Apple, with $246 billion, and Pfizer, with $199 billion.

Bringing those foreign profits into the U.S., Microsoft disclosed in 2017, would have resulted in a $45 billion tax bill. Of course, the company didn't do that. Instead, like other companies that stashed profits offshore, it waited for a better deal. There was good reason to wait: Back in 2004, for example, Congress had passed a tax holiday that allowed multinationals to bring home foreign profits at a tax rate of 5.25%.

At the end of 2017, the Trump administration and Republican Congress came through. The Tax Cuts and Jobs Act required U.S. companies to bring home those foreign profits, but at a one-time rate ranging from 8% to 15.5%. So, instead of a $45 billion tax bill, Microsoft says it will pay $18 billion under this provision, a savings of $27 billion.

Time marches on. But the IRS and Microsoft are still in court, the clock still stopped.

The two sides most recently brawled in 2016. As before, the fight involved Hoory and the IRS taking a relatively aggressive position, and Microsoft and its allies reacting with dismay.

The dispute began when Microsoft refused to turn over some documents, most of them involving KPMG, in response to the summons. Microsoft argued the documents were protected by a privilege for tax advice. The government countered with an inflammatory claim: The Puerto Rico deal was, as Hoory put it in a filing, "illusory in nature, serving no material economic purpose except to shift income to Puerto Rico" and was thus a tax shelter.

A tax shelter is something done mainly to avoid taxes, whether legally or illegally, and the law provides far less protection for advice on such a scheme. In response, Microsoft argued that its Puerto Rican company "was a real business with real risks and was not a tax shelter."

Its allies jumped in to help, too. The Chamber of Commerce filed an amicus brief, arguing that "the extreme positions articulated by the government … would chill businesses from obtaining and relying on the uninhibited advice of their tax advisors." Other business groups made similar arguments.

In May 2017, Martinez ruled that he would view the disputed documents privately and then decide whether they ought to be turned over. Nearly three years later, he has yet to issue a ruling. (The judge was still reviewing the question as of early January, according to a person in his chambers.)

And so, 12 years after the IRS began its audit of the Puerto Rico deal, eight years after Hoory began his work on it, and five years after the IRS sued to enforce its summons, the audit continues.

One day, the judge will issue his ruling. Soon after, perhaps, the summons will be fully resolved, and the clock will start again. A few months later, the IRS will, at long last, officially tell Microsoft what it owes. In all likelihood, Microsoft will then file a petition in U.S. Tax Court, thus beginning a new court battle. From there, the fight could shift to a U.S. appeals court. A further appeal to the U.S. Supreme Court is certainly possible.

And then, eventually, perhaps someday in the mid-2020s, the audit of Microsoft's 2005 Puerto Rico deal will be done.

Update, Jan. 22, 2020: On Jan. 17, 2020, after this story was finalized for publication, but before it published, U.S. District Court Judge Ricardo Martinez issued his ruling on the remaining, disputed documents. It was another big win for the IRS in the case. (Martinez, who had taken the better part of three years to consider the ruling, issued it 10 days after ProPublica inquired about the delay.) Almost none of the documents were protected by various privileges, he ruled. Most crucially, he decided that all KPMG documents must be turned over, because the firm had been promoting a tax shelter. He wrote, "the Court finds itself unable to escape the conclusion that a significant purpose, if not the sole purpose, of Microsoft's transactions was to avoid or evade federal income tax." It's an outcome that "serves the public interest," he wrote, given the difficulty of the IRS' task of discovering underreporting of corporate taxes.

Barring an appeal, the ruling resolves the summons enforcement case and means the audit can now be completed by the IRS in the coming months.