Some countries including France and Germany have the concept of "Abuse of Rights" [0]. I don't know if it would apply in a case similar to Apple, but it can definitely apply when you're trying to find loopholes to not pay taxes.
[0]: https://en.wikipedia.org/wiki/Abuse_of_rights