In general
If—
(A) any individual is a nonresident alien individual at the beginning of any taxable year but is a resident of the United States at the close of such taxable year,
(B) at the close of such taxable year, such individual is married to a citizen or resident of the United States, and
(C) both individuals elect the benefits of this subsection at the time and in the manner prescribed by the Secretary by regulation,
then the individual referred to in subparagraph (A) shall be treated as a resident of the United States for purposes of chapter 1 for all of such taxable year, and for purposes of chapter 24 (relating to wage withholding) for payments of wages made during such taxable year.