What is the purpose of the US in the Middle East, why it supports terrorist organizations?
It depends on who you ask. But the Middle East is a region which has been constantly fought over and in dispute - not just because of religion, but because of its strategic location and importance to commerce and trade. Oil is another major consideration, since oil is the lifeblood of the industrialized world.
Prior to WW2, the US had no real presence in the Middle East, no claims in the region, and no real business being there at all. That was mainly the domain of Britain and France, who took control from the Ottoman Empire after WW1.
But after WW2, both Britain and France were in a weakened state, and there were fears that the Russians would exert their own hegemony as a result of the power vacuum left by Britain and France. Because Britain and France were US allies, their interests became our interests - which is how the US got involved in the Middle East (along with many other troubled areas in the former colonial world).
As for which organizations America supports, my observation is that our government supports anything and anyone they consider to be "anti-communist." The people who run America's government and political system are capitalists, and capitalists have no real principles - other than wanting to make money. They support any faction or organization which they believe will give them the highest return on their investment, no matter if they engage in terrorism or tyranny.