US stocks whipsaw but close higher as Wall Street mulls Fed outlook after July CPI