I initially wrote a response about why it isn't worth it. Many downsides and not as many upsides, but on second thought I realized I was prejudging the HN community and I don't like that I was doing that. Considering this is a day old and probably only people particularly interested in the topic are still reading, I'll give a go.

I'm not fully sure how to structure this, so I'm just going to dive into a list of potential answers to the original question: What was/is there to win? While I am aiming at the question about Afghanistan, general region topics and Iraq factor in very much as well.

1. Destabilization: Much of the problem in the GWOT was and is due to the confusion of purpose. Some saw it as to defeat Al Qaeda. Some as revenge for 9/11 (despite the fact that most of the hijackers were Saudi Wahhabists, even if they had been in the Afghan training camps. That eventually evolved over time to issues with the Taliban, and it's various networks like the Haqqani and the Quetta councils in Pakistan. The problem is that while certain groups like the military leadership (such as Petraeus) bought into this, they didn't understand or weren't empowered to counter the underlying desire for instability at the political and above level. When I say above I mean what I call the political "shadow players", the ones that exist through multiple presidencies and have a huge influence over top-down decision trees in government. I like to use Zbigniew Brzezinski and Henry Kissinger as prime examples. They in turn influenced the top level political entities to make moves often counter to the surface purpose of the war(s). A great example of this would be when Ian Bremmer and Rumsfeld, despite protestation from the military, decided to tell the Iraqi commander with 40k troops asking what to do with them to go fuck off. In the end, much of actions of that type were very much geared towards keeping things unstable, for reasons I will go into further, and it's worth noting that's pretty much exactly what has happened.

2. Containment: Let's be frank. Iran is sandwiched in between Iraq and Afghanistan and it has been in the crosshairs for quite some time now. Also worth remembering in context is that much of Saddams power was increased when we quietly backed him in the Iran-Iraq war. The joke on the ground used to be "How do we know Saddam has WMDs? Because we still have the receipts!" Not much actually changed from the 90's and destabilization of the region plays into keeping Iran busy there instead of elsewhere such as in Lebanon and Syria, at least to a degree. It's more than that, but Iran is the main target of containment. It also was used as a draw to get fighters to show up there instead of in western countries, another form of containment. Lots of foreign fighters started showing up the body count.

3. Presence: By establishing and expanding the middle east and western asian connections, infrastructure, bases, etc, we have closer inroads for conflicts in the future, and that's not even necessarily geared towards ME countries. It could be China, Russia, Africa, etc. Africa in particular happened to play this out with Libya, Sudan, etc, and it continues to this day.

4. Combat hardiness: at a more Machiavellian level, the relatively tame conflict(s) on blue-side were seen as a good proving ground to refine modern combat techniques, tools, tactics and strategies. Lots of think-tank analysis after the fact to help gear up towards conflicts in a future that might be more tri-polar conflict likely. It's a dirty business to be a general and have to think like that, but it is what it is.

5. Black markets: Just as in Vietnam, the destabilization and control offered a great opportunity for certain organizations to participate in black markets. See, for example, congress is supposed to have purse string control of the CIA... but if they can pull some Iran-Contra esque gun-drug running on a suddenly booming opium producing country that has almost no rule of law and is swarming with military who don't ask too many questions, they can essentially remove themselves from congressional oversight. Just look at the growth of the opioid epidemic in America in time with Afghanistan. Ignoring the pharma part, a huge percentage of tested heroin in America traces it's origins too... yep, Afghanistan. It's an age old playbook the 3-letters have been using for a while. (Cocaine cowboys like Barry Seal into Arkansas... who was the governor there again?)

6. Kickbacks: You also have to realize that a lot of the policy influencers tend to be old white guys who own or on the boards of defense companies in Virginia (or oil companies like Halliburton), and those good ol boys have lots of power. Lots of what happened was just plain old money laundering from taxpayers/the treasury into their pockets. There is a reason a few counties in Virginia have had the highest growth of millions in the country since the GWOT started.

7. Resource control: along with presence and control of these places, comes the ability to influence resource flow routes (and who gets those contracts, see above). This is one of the most important and oft overlooked aspects of the whole thing. See cries that the wars were about us taking the oil weren't quite true. It was more about controlling who the oil did go to. Even in the modern context a lot of the action in say Syria has a lot of hidden resource control route justifications the public never hears about. On the Afghanistan side one thing it does is help prevent natural gas and oil from reaching China to the east and Russia to the north. I saw the current Russia-gate hysteria coming many years ago because the shadow players like ZB telegraphed it so much... always talking about the return to a tri-polar world.

8. Banking: Banks and economies tend to boom in times of war (until the war is over and things contract, or if you are in the country the war actually happens in). This is also highly under-analyzed.

9. The elephant(s) in the room: Israel and Suadi Arabia. Much of the actions in ME have been due to a large level of influence they both have over policy makers in the US. Many of the above reasons seem to benefit them more than the US, especially when the repeat blowback comes home to roost in another 20 years.

10. Destruction of rights at home: when the people cried out for a response, the military congressional academic think-tank complex immediately used the opportunity to further undermine individual rights at home. They have constantly moved the overton window further and further towards acceptance of a dystopian semi-totalitarian state. Just look at any topic in HN, a forum full of hackers, to see the excuses and servile placations for these things. There are multiple reasons, some of which are a bit over the top to get into, but the more reasonable justification is that technology has changed the threat model away from nation states and more and more towards single actors being able to pull off big things (bio-engineering, infrastructure hacking, etc). Many of the MICC/good ol boys in DC/VA buy into this reasoning on the surface, despite really understanding they are undermining the foundational principles of America (and lining their pockets at the same time). A prime example of this would be William Binney's report that he had designed a surveillance program called ThinThread that would have protected American's privacy and still enabled the gov to track threats, and implimentation would costed in the 10s of millions. The program was scrapped in favor of a multi-billion dollar program that didn't protect Americans privacy and lost threats in the haystack of information.

Just a few off the top of my head. Hanlon's razor just can't account for all these things. Yes incompetence runs rampant, but incompetence in these cases is often just as bad as malice, or is easily manipulable by those with malice.