Stocks declined Thursday to end a difficult first half for equities.