With respect to lot identification (what shares did you actually sell for tax purposes), within an account, most brokers will let you elect specific lots or FIFO and I believe the IRS allows you to elect average basis. (There’s no particular advantage to making that election, IMO, so I never looked into it but vaguely recall that being the case.)
Across accounts, except for wash sale treatment, the IRS does not assume that when you sold in account B that you were selling shares acquired in account A.
e.g. if your RSUs are valued at $1000 when they vest and you sell it a few minutes later and the value is now $1005 you'll pay regular income taxes on $1000 and have a $5 capital gain (i.e. when you file your taxes the cost basis for the holding are $1000, not $0)
You surly don't pay income tax on the gain of already owned stock but CGT.
Back in the day 2000's I did own stock that was worth over 1,000,000 certainly wouldn't have had to have paid income tax if we had been bought out at point - but that was in the UK