Slightly less naive implementation of cas()

jnthn++