You're assuming too many things and nobody here has even mentioned any visa. In fact the IRS rules specifically say they don't care if you have a visa for that country or not, that's not their concern. I'm not going to get into a discussion about this because I'm sure even the IRS employees don't agree on some things.
Consult a tax specialist for your specific case, that's what I'm going to do.