The winners and losers from a so-so August that threatened to stop the 2023 stock market rally in its tracks