Our mission was to stop Al Qaida by obliterating its bases in Afghanistan. This morphed into nation building, which will never, ever work in Muslim nations.
All Middle Eastern Muslim power structures devolve to the tribal, and it matters not whether the leader at the pinnacle of that structure is a tyrannical dictator or a king. Personal power is the only power that matters and personal power is a zero sum game. No one can trust anyone else. The only rule that counts is that the one with the most power.
So, whether it is pirates or terrorists, we deal with both exactly the same. We deal harshly with them when we catch ‘em; a trial by military tribunal and an immediate hanging afterwards.
As to those nations harboring terrorists and pirates, we deal harshly, too. They will be punished until it hurts so much that they literally kill any remaining terrorists and pirates themselves.
No nation building!