How to calculate stock basis on a stock acquired before moving in US

Hello,

I moved in US and become an resisdent in late 2018, before that I have some ESPP and company vested RSU stocks in my ETRADE account not sold, but already paid tax in foreign country when ESPP purchased or RSU vested in earlier 2018.  I sold these stocks in late 2019 and need to file tax for 2019.

How can I calculated the cost basis for these stocks due to the previous tax paid in foreign country? If the foreign tax is not accountable, the cost basis for at least RSU would be zero and induce a lot of double tax.  

Further more, I have some excessive foreign income tax credit generated in 2018, but could not be used in 2019 since I have no foreign income in 2019. So not able to used it to deduct the tax for the double tax either.

Please help to adivise if you have any good options! Appreciate for your kind help!