Variational analysis of the asymptotics of the XY model