If you only have a US company, then it can pay salary to workers in other countries and have those workers pay local tax. I think that your country has to have a Double Tax Agreement for that to work. The US company pays US corporate tax.
If you want the money to be funnelled to a company in your local country then you need a set up a Transfer Pricing Agreement. This basically means that your local company charges the US company for services rendered, and the US company charges your customers. You pay local tax on whatever goes to your local company and US tax on whatever remains. The hard part is determining a percentage.
I believe that the rules for this are different per country, but in our case (New Zealand), we needed to set up what is called an "Arms Length Agreement". That is to say, you need to be able to prove that the relationship you have could have formed between any two unrelated companies.
As we are a game company, we called our US company a publisher of our game and we did a 70/30 split with it. This is justified by the fact that you can get a 70/30 split with a fair number of other methods for publishing independent games (for example, the apple app store).
All up we paid several thousand for legal advice and incorporation costs.
Transfer pricing requires you to pay market-based rates for services actually rendered by foreign related companies. This generally means the foreign company's costs in performing the service plus a profit percentage.
The percentage is determined based on a "Transfer Pricing Study" of related service companies in the foreign jurisdiction (or region, depending on the industry).
Tax authorities are very quick to challenge transfer pricing arrangements, especially those arrangements lacking documentation of how the percentage was selected. (The agreement will do nothing to help you in this regard. The % is what matters in proving that the relationship could have been formed between unrelated companies.) If the TP arrangement is disregarded, the money paid to the foreign company will be recharacterized. The danger is that the income will be treated as passive dividend income, rather than as "active" income. The distinction between active and passive can affect applicable tax rates, offsets, and other tax consequences.
Many accounting firms and even some law firms will provide transfer pricing studies for relatively low cost, but expect to pay low-to-mid 5 figures.
Also: Negativefrag's structure has two companies: a New Zealand parent which owns a U.S. subsidiary. Presumably, the IP is held in the NZ company rather than the U.S. subsidiary.
In the OP's post, Freshdesk only has a single company, located in the U.S. It will be (relatively) expensive for Freshdesk to transition to a multi-entity structure that can take advantage of transfer pricing in the way that Negativefrag's company has.