On the surface, yes. That’s exactly why it’s legal. However, from another perspective it’s the same company.
Let’s take the Apple example:
Apple created Apple Sales International and Apple Operations Europe as companies that own the intellectual property that Apple uses to create it’s products.
They did this because when they make 1B profit on 10B sales (let’s pretend for the sake of easy math), they would normally have to pay tax on that 1B but instead they can say “Our agreement with Apple Sales International and Apple Operations Europe state that we must pay “them” 1B in licensing fees for these sales. As you can see, we have no more money left to tax.”. Since Apple Sales International and Apple Operations Europe are subject to different tax laws they can pay little to no tax at all.
Now: Are those separate legal companies? Yes. But when it comes down to it, are they all the company we think of when we say Apple? I would say yes.