Hopefully, fixes #9447.

Cleanup of the success flag in CAS operations has been reworked. The
flag is automatically cleared by default and only set when the operation
succeeds. Also minor code reformatting and __volatile__ specifications
to prohibit the assembler code moving around.