"Seemed the Vietnamese, Iraqis, and Somalia did all right "
Some knowledge of history would help.
Not at all. Vietnamese weren't just the Vietcong with a rifle you saw in movies. They were heavily armed (by Russia and China) - fighter jets, SAMs, artillery and mortars, mines, heavy machine guns, etc. They also had armored vehicles and tanks. Plus a terrain which made advanced weaponry like big tanks useless. The US armed forces were designed to fight a war in Europe against division of battle tanks in open terrain, not in the South-East jungle. You have to accept much more casualties in such war - and of course you have to destroy supply lines and enemy cities like done in WWII. Nothing of that of course, was acceptable in Vietnam.
A-10 entered service in 1977, thus was never used in Vietnam. Even attack helicopters were in their infancy in the Vietnam era, and would have been of little use anyway in the jungle.
In Somalia, US troops were sent as a "peace and humanitarian relief corp" - with only light weapons, no armored vehicles, no attack helicopters and planes, albeit they were tasked also to fight the local warlords. Just, the Somali pick-up mounted heavy machine guns and RPGs outgunned them easily, and while usually fighting each other, they allied against the US attempt.
It was a big, bit mistake made by US military planners, which needed to resort to ask help from other nations tanks and armored vehicles to save their troops under siege.
Iraqi regular troops and the Republican Guard couldn't sustain a fight against US and allies troops - did you forget the prisoners herder by helicopters?
Insurgents, especially suicidal ones, are always an issue, if they have enough support from the local population, and have supply lines which feeds them the required weapons, which usually go far beyond assault rifles, usually including RPGs, heavy machine guns, small missiles, explosives.
Even in Afghanistan Talibans had to accept US help to fight Russians. You may need to adopt an approach like the one Russia adopted in Chechenya, but it's a bit bloody, and with large collateral damages. Cutting supply lines may mean to enter into a conflict with a larger power, i.e. Russia and/or China in Korea and Vietnam, Iran in Iraq.
Being on someone's own territory and being invaded may matter, but it's not really decisive. France couldn't stop the Nazi invasion, nor Italy the Allied one. Egyptian forces were routed by Israeli ones on their own soil. Finns were able to resist the Russia invasion in Winter, when they could take advantage of terrain and better equipment against the ill-equipped and badly organized Russian army, but as soon Spring came, the numbers were against them.
It works better with highly indoctrinated populations, of course, which can be got convinced to die "for the cause" in big numbers, especially if you can leverage their deepest fears about the "invader".
What's the chance the US armed forces turn against the citizens? Wouldn't it turn far earlier in another civil war fought using any available military weapon, with army forces split among factions? Anyway, if it ever happens, it will be too late to fight them with some assault rifle.
Any invading force able to defeat them, anyway, would come from nations that would have no problems to utterly wipe out fat bearded white men and their AR-15s. And there would be no country able to help them.