why wouldn't any international business do whatever it could legally do to minimize its taxes?The argument for not doing so (or at least, not going to such lengths to minimize the tax burden) is political rather than legal. I don't think it's 'evil,' incidentally, so please take the following as descriptive rather than proscriptive!
What happens when a company expands overseas? Well, it's a coup for the receiving country. There's a ribbon-cutting ceremony, speeches are made about the number of jobs it will create, people feel good about the past taxes they paid that went towards educating the workforce, and and there's a general expectation that the country will pick up 'a bit of the action' in three ways: by collecting some taxes from a successful business (pure rent-seeking, but after all that's part of why investing in education and infrastructure seemed like a good idea to begin with); by attracting other businesses in the same sector and getting a 'hub effect,' which will build up a secondary market serving these firms' ancillary needs (eg payroll, new real estate etc.); and a long-term benefit as employees of the Big Foreign Corporation develop world-class skills and later some of them start companies of their own or guide university researchers etc., making the country's economy more competitive and modern.
What happens is a little different. Usually the incoming firm has negotiated a favorable tax regime with the local government, and the long-term benefits of the secondary market and skill development are estimated to be greater than the foregone tax revenue. When I grew up (in Ireland) the usual approach was for the government to give a 10 year tax holiday in return for building a factory and training the employees, on the theory that the business would be OK with paying tax at the normal rate after a decade. But quite a few companies just shut down their factories when the 10 years ran out, because paying taxes was more expensive than setting up anew in some other developing economy and shipping the product. Of course, then the secondary market that had grown up servicing the industrial and consumer demand for local services would collapse.
So gradually there was a shift towards less rent-seeking (by allowing this sort of accounting manipulation) in return for the hope of increased long-term stability in secondary markets and skill growth. Unfortunately IMO, what has happened with a lot of tech and financial companies that moved to Ireland in particular is that that little technology transfer takes place. For example, Microsoft used to be a fairly big employer in both the UK and Ireland (not sure about now), but the bulk of the work was technical support and localization, rather than software engineering. Similarly most of the financial business in Dublin was backoffice processing because it was cheaper to do it there than in London or Paris (plus it gave UK companies an easy in to the European market). Jobs like that are less sticky if the tax regime changes, and while they probably do make the country's economy more competitive the gains are smaller and over a longer term than people anticipate - hence the endless supply of stories about some new location attracting a few tech companies and declaring itself to be 'Silicon _______.'
The secondary markets which provide ancillary services to the firm and its local employees thus do best out of such an arrangement, and a lenient tax regime keeps them going for longer - in practice, as long as wage differentials are sustainable for the parent company, and there isn't an equally capable workforce available to do the task for substantially less. Service jobs (at the foreign firm) are somewhat sticky because you can't move your call center from Dublin to Shanghai - but you might be able to find that in Bangalore. Meanwhile, if enough foreign firms set up shop in a country and a thriving secondary market grows up to service their ancillaries - plant, payroll and infrastructure for the firm itself, housing and consumer services for the happy employees. Of course, this tends to overheat the local economy: if you think the US property boom was out of control, you should have seen the Irish one. The price/earnings ratio for housing in Dublin shot up to 100:1.
Predictably, the party stopped right around the time when the cost of living had inflated wages high enough to make Ireland a less attractive destination for multinationals. Irish people were feeling so prosperous and skilled at making money that nobody wanted to do boring things like farm work or child care, and so the country saw an influx of Polish farmhands and nannies who everyone agreed made great workers. Several multinational firms came to the same conclusion; Dell used to have a manufacturing plant near my hometown in Ireland which was the largest local employer, but decided to close it and open a new one in Poland instead, resulting in the loss of ~2000 jobs. Of course the former employees still have their skills, but assembling PCs on an assembly line turns out not to be all that special, and my understanding is that Dell had a policy of not recruiting for management from the local workforce, or even hiring skilled people who were likely to apply for internally-advertised management positions rather than stay on the assembly line.
(Please bear in mind that I'm drastically oversimplifying here, so as not to make this comment even longer.)