The solution would be to have absolute minimalist tax rules which are so simple that there wont be loopholes. Then also make judges apply common sense and smash every attempted loophole until everyone stops wasting money to find one.
Never going to happen obviously but we can dream.
I think we'd be better off fixing the deduction of such problems, but just pointing out that part of the reason taxes are so complicated are to enable this. Another reason is to create corporate tax loopholes...
Yes the loopholes are intentional but it only helps very few individuals and a whole industry of layer, while corporations aren't actually in the business of finding tax loopholes they are indirectly forced to participate anyway because their competitor does. People blame the companies for evading taxes but they are not the problem they have to play along because everything else would be hard to explain to the shareholders.
Imagine if you are a business owner and your company slowly grows to amazon size. At what point would a sane person like to pay people to evade taxes? You would never want to do that instead of building a team of tax specialist or outsource that you could expand in real business. Your local small business owner and Jeff Bezos both have no interest in that.
Some big companies retain multiple law firms and ask the same advice a couple of times. If an overworked attorney who barely gets any sleep ever misses a point or drafts his/her advice vaguely in a way that would enable their evil plans, they rely on that single opinion. If there are any problems they don't assume any liability, because hey they got a legal opinion from a respectable law firm. Nobody needs to know/can prove they obtained multiple opinions on the same matter because of legal privilege.
In return, big law gets paid a lot of $$$, because of the risk of providing such opinions under considerable pressure and trickstery.
In a big corp, I think most employees are concerned with saving the day. If the management pressures them to cut corners most will. What better way is there to pass the blame?