When President Trump signed the massive, last minute tax overhaul last year (literally on the Friday before the Christmas weekend), it changed the U.S. Tax Code, big time.

Now, it turns out that it also prompted Apple to make a move that ultimately cost it $9 billion.

Whoops. Here's the law, the completely logical thing it prompted Apple to do (and that backfired), and what it all tells us about how last-minute laws can lead to unintended consequences.

Big-time unintended consequences

For most people and companies, the new tax law should ultimately lead to more money. But it's complicated, and we'll know more for sure next month, after people start filing their 2018 tax returns.

Still, we've already seen that this law, which was negotiated in secret last year and then passed on party lines in the last few days of the Congressional session, brought with it some real quirks and missteps.

For example, ultra-wealthy families almost didn't qualify for massive tax breaks they expected, due to what seems like an unnoticed drafting error. (The IRS came to their rescue last month.)

And some married couples in troubled relationships were racing to get divorced by Dec. 31, because the new tax law completely reverses the way alimony was treated for tax purposes. 

The one group that should have been relentlessly cheering this tax law however was big corporations, since they got a massive tax break.

And they are getting it--but it seems that the tax savings led some companies to do a completely logical thing that ultimately didn't work -- and wound up losing a ton of money in the process. (The biggest name among them: Apple.) 

How stock buy backs work (or don't)

The populist argument in favor of big corporate tax breaks is that the money will ultimately find its way to workers and investors, in the form of higher salaries and dividends.

You'll be shocked (shocked!) to learn that's not always what happens.

In fact, as many clear-eyed observers predicted, big public companies are answerable to their shareholders, so they have a duty to do things that are reasonably calculated to increase the value of their stock. One classic way to do that: buy back your own stock.

It's an especially attractive option when companies are nervous about what the economy will look like down the road. So, instead of higher wages or investments, that's exactly what a lot of companies did in 2018.

Facebook announced a plan this month to increase its buybacks, The Wall Street Journal reported, as have Lowe's, United Rentals, Mastercard, and many others -- including Apple.

But of course, this strategy only works if your stock continues to increase in value as you buy more of it. And in the case of Apple and some other companies that bet big on this strategy, it's been a bit of a disaster. As the Journal reports:

Apple Inc. has lost more than $9 billion this year on an underperforming investment--its own stock.

Like many large companies, Apple has used much of its windfall from the 2017 tax overhaul to buy back shares. But the recent plunge in stock prices has made that look like a bad idea. Apple and companies including Wells Fargo & Co., Citigroup Inc. and Applied Materials Inc. repurchased their own shares at rich prices, only to see their value decline sharply.

In effect, the market has told them they overpaid by billions of dollars. 

It's okay to laugh

Granted, Apple's stock could theoretically rebound and recover all of the losses next year. 

And even if it doesn't rebound, it still was arguably a good move from a shareholder's perspective, if you believe that Apple's stock value would have lost even more than $9 billion without the buyback. 

Although, could Apple have done something better with that $9 billion? Maybe, design the next wave of products that might usher in yet another generation of dominance? We're deep into the realm of the theoretical now.

But at least one group should be cheering--anyone who sold Apple's stock at the same time as the buyback strategy. Because if you think about it, it's quite funny how this worked out.

President Trump and Congress rushed last year to Apple and other companies a massive tax break. And by pursuing this strategy, they ultimately wound up passing a big chunk of it along to people who bet against Apple and the other companies they were trying to help.