US stocks give up earlier gains to close lower