Where to allocate ...
Upvoted because you're correct. Determining profits vs expenses vs tax-advantaged accounting catagories is difficult and allocating profits to countries is even harder. Moreover, there are brigades of clever folks in every large company whose livelihood depends on obsfucating where money is and whether it is profits or expenses or investments or indeed exists at all.
There would seem to be at least three possible approaches to deal with this.
Say "screw it" and let the companies do as they wish. This is basically the libertarian approach. I disagree with it. It has a certain appeal, but it's intellectually lazy. And it almost certainly won't result in much taxation.
Leave it up to the often corrupt and even more often confused legal and political systems of some 200 countries to sort out. Probably not a good idea.
Create one or more international commissions tasked to evaluate the books of large international corporations, determine profits, and allocate them to countries. The commission(s) will probably do a lousy job, but it'll likely be better than what 200 autonomous legal systems would do. And it should discourage most venue shopping. Note that countries would still be free to set their own tax rates and tax rules within the scope of whatever treaty arrangements they have agreed to (and choose to honor).