I have spent a lot of time with this issue. My dad is a historian about the 20th century and we talked a lot about this at the dinner table.
First of all, forgive my grammar, I'm no native speaker.
The whole thing started after WW2, when the British colonies started to declare their independencies.
One colony was Persia, the former Iran.
The Britains were still in charge of the oil fields and pipelines.
Mohammad Mossadegh was the name of the president. He was democratically elected, relatively liberal (No mandatory hijab, women could study at universities, division between state and religion etc, civil rights etc.)
However he reclaimed the oil fields, partly because his people were starving.
The Britains and Americans thought about getting rid of Mossadegh, but he was democratically elected.
CIA and MI6 bribed the press, hired thugs, conducted false flag operations etc. to basically stage a coup so that they could install the man they wanted (Reza Pahlavi, the "Schah").
I'm not kidding you, this is not propaganda, all the files are released and they admitted it.
The new Schah was a dictator. Still liberal with women's rights, but critics began to disappear etc.
This was also the time of the cold war. The Communists had their Warsaw Pact and the West had the NATO. They tried both to get the "neutral" states on their sides. Iran was armed by the Americans as a bastion against communism until they had the 5th biggest army in the world.
To finance it, Pahlavi oppressed his people so badly that in their desperation, they gathered behind a religious leader to stage a coup themselves (1979).
This is when Iran became from a good ally the evil Nr. 1.
The revolution was at least peaceful, very few (if none?) dead people, but is was a blamage for the US. Take a close look at the diplomats who were taken hostage, it's too long to go into that now.
Basically, this is when it went better for the population in some aspects.
They didn't starve anymore, but lived under Schariah law, which was very bad for the women.
But you feel how desperate the Iranians must have been in order to gather behind a religious leader to get a theocracy.
This is when they got all the hard sanctions against them and also the time of the first gulf war.
Saddam Hussein was a good western ally at that time, so he was pushed in a proxy war with Iran. The US cynically armed both parties.
Saddam was promised that he could keep the oil fields at the border that he conquered.
If you're new to these things, this might sound like propaganda, but it is verifiable and common knowledge amongst historians.
The war took 8 years with many dead people. Saddam had terrible losses and thought to himself "when it's so hard to get my oil in Iran, I just take it in Kuwait".
But this made him an enemy himself even though, from the perspective of a dictator, he did nothing else than what he was encouraged to do before.
To wrap this up, I think Saddam had nothing to do with 911, he was afraid that religious fundamentalists would overthrow him himself and he wasn't very religious. But this is personal opinion, don't use this information without your own research.
I think they want the A-bomb to be sure that they don't get removed like all the other unwanted regimes. They know if they use it, they will get wiped out themselves.
North Corea are pretty much secure from an intervention because they have the A-bomb. They can be as crazy as they want to be.