US stocks give up gains to close lower