Clean up some duplicated code, make clang emit valid IR for atomic
operations on capabilities.