S&P 500 closes at highest level in 2023 as US stocks post gains