A small percentage of the profits goes to pay the executive salaries and corporate headquarters staff in the home county. The rest ultimately goes to the shareholders, which could be anybody anywhere.
Any company with a foreign HQ generally repatriates 100%+ of their US profits because of the US Corporate Tax Law.
Let's say your company is going to make $100M this year just stick on a foreign management fee of $110M and you are paying no USA taxes. Not really good for the US and a reason why we need to reform our tax law. If you are a US company like Dell you get pounded on taxes for example where Acer is going to send all that money back to Taiwan and pay no US taxes (and very little TW taxes).
You are correct though that ultimately the shareholders get that money either through dividends directly or through selling stock at a higher share price than they bought it at.