build: check for libatomic and __atomic operations
compat: use __atomic operations instead of __sync, when present