Both of them. AQ started an insurgency in KSA during the early 2000's that failed but nevertheless made some noise. This was way before ISIS became a thing.
en.wikipedia.org
en.wikipedia.org
AQ itself was funded by OBL who we all know eventually turned anti-establishment after the Afghan-Soviet war. I think the overall view was that every Muslim regime/government was a Western henchman, not Islamic enough (if at all) etc. Outside of Sudan in the 1990's and later Taliban that is.
KSA was the favourite target of ISIS/AQ in terms of Muslim regimes. Far more than the likes of Iran for instance. One just need to recall all those audio messages from their leaderships during the years.
But anyway both ISIS and AQ were/are infiltrated by foreign intelligence services no doubt and were used as such for various different gains. Outside of truly independent cells within.
For instance it is no secret that ISIS was largely formed by former military Ba'athi Iraqi Sunni Arabs discontent with losing control of Iraq mixed with AQI elements. Many of the leadership were once secular nationalists. I always saw ISIS as an local fringe Iraqi Sunni Arab supremacist movement turned armed Jihadis with their main goal being the toppling of the Iraqi Shia Arab-dominated government and the re-establishment of Iraqi Sunni Arab dominance, this time around under a Jihadi/Islamist banner.
It is all about creating slogans to achieve political gains.
I have no doubt that Al-Jolani is an Syrian Sunni Arab nationalist who for the very same reasons used Islamism to help topple the Alawite Al-Assad regime and establishment.
Being both at the same time (Islamists + nationalist) can easily be connected.
Hence the informal racial hierarchies within the likes of ISIS.