int main(void) {
  __int128_t result;
  __int128_t value;
  __int128_t and_input = ((((__int128_t)0x1234567890abcdefULL) << 64) |
                          ((__int128_t)0xfedcba0987654321ULL));
  __int128_t and_value = ((((__int128_t)0xfffffffffffffff0ULL) << 64) |
                          ((__int128_t)0xfffffffffffffff0ULL));
  __int128_t and_exp = ((((__int128_t)0x1234567890abcde0ULL) << 64) |
                        ((__int128_t)0xfedcba0987654320ULL));
  __int128_t or_input = ((((__int128_t)0x1234567890abcdefULL) << 64) |
                         ((__int128_t)0xfedcba0987654321ULL));
  __int128_t or_value = ((((__int128_t)0x0000000000000010ULL) << 64) |
                         ((__int128_t)0x000000000000000eULL));
  __int128_t or_exp = ((((__int128_t)0x1234567890abcdffULL) << 64) |
                       ((__int128_t)0xfedcba098765432fULL));
  __int128_t add_input = ((((__int128_t)0x1234567890abcdefULL) << 64) |
                          ((__int128_t)0xfedcba0987654321ULL));
  __int128_t add_value = ((((__int128_t)0x0000000001000000ULL) << 64) |
                          ((__int128_t)0x0000001000000000ULL));
  __int128_t add_exp = ((((__int128_t)0x1234567891abcdefULL) << 64) |
                        ((__int128_t)0xfedcba1987654321ULL));
  value = and_input;
  result = quad_fetch_and(&value, and_value);
  if (result != and_input || value != and_exp)
    abort();
  value = or_input;
  result = quad_fetch_or(&value, or_value);
  if (result != or_input || value != or_exp)
    abort();
  value = add_input;
  result = quad_fetch_add(&value, add_value);
  if (result != add_input || value != add_exp)
    abort();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x1234567890abcdef,%rcx
56 34 12
mov    %rcx,-0x38(%rbp)
movabs $0xfedcba0987654321,%rax
ba dc fe
mov    %rax,-0x40(%rbp)
movq   $0xfffffffffffffff0,-0x48(%rbp)
ff
movq   $0xfffffffffffffff0,-0x50(%rbp)
ff
movabs $0x1234567890abcde0,%rdx
56 34 12
mov    %rdx,-0x58(%rbp)
movabs $0xfedcba0987654320,%rdx
ba dc fe
mov    %rdx,-0x60(%rbp)
mov    %rcx,-0x68(%rbp)
mov    %rax,-0x70(%rbp)
movq   $0x10,-0x78(%rbp)
movq   $0xe,-0x80(%rbp)
movabs $0x1234567890abcdff,%rdx
56 34 12
mov    %rdx,-0x88(%rbp)
movabs $0xfedcba098765432f,%rdx
ba dc fe
mov    %rdx,-0x90(%rbp)
mov    %rcx,-0x98(%rbp)
mov    %rax,-0xa0(%rbp)
movabs $0x1000000000,%rax
mov    %rax,-0xb0(%rbp)
movq   $0x1000000,-0xa8(%rbp)
movabs $0x1234567891abcdef,%rax
56 34 12
mov    %rax,-0xb8(%rbp)
movabs $0xfedcba1987654321,%rax
ba dc fe
mov    %rax,-0xc0(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    %rcx,-0xc8(%rbp)
mov    %rax,-0xd0(%rbp)
mov    -0xd0(%rbp),%rsi
mov    -0xc8(%rbp),%rdx
xor    %eax,%eax
lea    -0x30(%rbp),%rdi
call   1060 <quad_fetch_and@plt>
movslq %eax,%rcx
mov    %rcx,%rax
sar    $0x3f,%rax
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
movaps -0x20(%rbp),%xmm0
movaps -0x40(%rbp),%xmm1
pcmpeqb %xmm1,%xmm0
pmovmskb %xmm0,%eax
sub    $0xffff,%eax
jne    12b1 <main+0x171>
jmp    1291 <main+0x151>
movaps -0x30(%rbp),%xmm0
movaps -0x60(%rbp),%xmm1
pcmpeqb %xmm1,%xmm0
pmovmskb %xmm0,%eax
sub    $0xffff,%eax
je     12b6 <main+0x176>
jmp    12b1 <main+0x171>
call   1030 <abort@plt>
mov    -0x70(%rbp),%rax
mov    -0x68(%rbp),%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x80(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    %rcx,-0xd8(%rbp)
mov    %rax,-0xe0(%rbp)
mov    -0xe0(%rbp),%rsi
mov    -0xd8(%rbp),%rdx
xor    %eax,%eax
lea    -0x30(%rbp),%rdi
call   1050 <quad_fetch_or@plt>
movslq %eax,%rcx
mov    %rcx,%rax
sar    $0x3f,%rax
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
movaps -0x20(%rbp),%xmm0
movaps -0x70(%rbp),%xmm1
pcmpeqb %xmm1,%xmm0
pmovmskb %xmm0,%eax
sub    $0xffff,%eax
jne    134a <main+0x20a>
jmp    1327 <main+0x1e7>
movaps -0x30(%rbp),%xmm0
movaps -0x90(%rbp),%xmm1
pcmpeqb %xmm1,%xmm0
pmovmskb %xmm0,%eax
sub    $0xffff,%eax
je     134f <main+0x20f>
jmp    134a <main+0x20a>
call   1030 <abort@plt>
mov    -0xa0(%rbp),%rax
mov    -0x98(%rbp),%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0xb0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
mov    %rcx,-0xe8(%rbp)
mov    %rax,-0xf0(%rbp)
mov    -0xf0(%rbp),%rsi
mov    -0xe8(%rbp),%rdx
xor    %eax,%eax
lea    -0x30(%rbp),%rdi
call   1040 <quad_fetch_add@plt>
movslq %eax,%rcx
mov    %rcx,%rax
sar    $0x3f,%rax
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
movaps -0x20(%rbp),%xmm0
movaps -0xa0(%rbp),%xmm1
pcmpeqb %xmm1,%xmm0
pmovmskb %xmm0,%eax
sub    $0xffff,%eax
jne    13f2 <main+0x2b2>
jmp    13cf <main+0x28f>
movaps -0x30(%rbp),%xmm0
movaps -0xc0(%rbp),%xmm1
pcmpeqb %xmm1,%xmm0
pmovmskb %xmm0,%eax
sub    $0xffff,%eax
je     13f7 <main+0x2b7>
jmp    13f2 <main+0x2b2>
call   1030 <abort@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movabs $0x1234567890abcdef,%rax
56 34 12
mov    %rax,0x8(%rsp)
movabs $0xfedcba0987654321,%rax
ba dc fe
mov    %rax,(%rsp)
mov    %rsp,%rdi
mov    $0xfffffffffffffff0,%rsi
mov    $0xfffffffffffffff0,%rdx
xor    %eax,%eax
call   1040 <quad_fetch_and@plt>
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i128
%3 = alloca i128
%4 = alloca i128
%5 = alloca i128
%6 = alloca i128
%7 = alloca i128
%8 = alloca i128
%9 = alloca i128
%10 = alloca i128
%11 = alloca i128
%12 = alloca i128
%13 = alloca i128
%14 = alloca i128
%15 = alloca i128
store i32 0, i32* %1
store i128 24197857200151252746022454892744229665, i128* %4
store i128 -276701161105643274256, i128* %5
store i128 24197857200151252469321293787100955424, i128* %6
store i128 24197857200151252746022454892744229665, i128* %7
store i128 295147905179352825870, i128* %8
store i128 24197857200151253041170360072097055535, i128* %9
store i128 24197857200151252746022454892744229665, i128* %10
store i128 309485009821345137444257792, i128* %11
store i128 24197857200460737755843800030188487457, i128* %12
%16 = load i128, i128* %4
store i128 %16, i128* %3
%17 = load i128, i128* %5
store i128 %17, i128* %13
%18 = bitcast i128* %13 to { i64, i64 }*
%19 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %18, i32 0, i32 1
%22 = load i64, i64* %21
%23 = call i32 (i128*, i64, i64, ...) bitcast (i32 (...)* @quad_fetch_and to i32 (i128*, i64, i64, ...)*)(i128* %3, i64 %20, i64 %22)
%24 = sext i32 %23 to i128
store i128 %24, i128* %2
%25 = load i128, i128* %2
%26 = load i128, i128* %4
%27 = icmp ne i128 %25, %26
br i1 %27, label %32, label %28
28: ; preds = %0
%29 = load i128, i128* %3
%30 = load i128, i128* %6
%31 = icmp ne i128 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28, %0
unreachable
33: ; preds = %28
%34 = load i128, i128* %7
store i128 %34, i128* %3
%35 = load i128, i128* %8
store i128 %35, i128* %14
%36 = bitcast i128* %14 to { i64, i64 }*
%37 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %36, i32 0, i32 0
%38 = load i64, i64* %37
%39 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %36, i32 0, i32 1
%40 = load i64, i64* %39
%41 = call i32 (i128*, i64, i64, ...) bitcast (i32 (...)* @quad_fetch_or to i32 (i128*, i64, i64, ...)*)(i128* %3, i64 %38, i64 %40)
%42 = sext i32 %41 to i128
store i128 %42, i128* %2
%43 = load i128, i128* %2
%44 = load i128, i128* %7
%45 = icmp ne i128 %43, %44
br i1 %45, label %50, label %46
46: ; preds = %33
%47 = load i128, i128* %3
%48 = load i128, i128* %9
%49 = icmp ne i128 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %46, %33
unreachable
51: ; preds = %46
%52 = load i128, i128* %10
store i128 %52, i128* %3
%53 = load i128, i128* %11
store i128 %53, i128* %15
%54 = bitcast i128* %15 to { i64, i64 }*
%55 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %54, i32 0, i32 0
%56 = load i64, i64* %55
%57 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %54, i32 0, i32 1
%58 = load i64, i64* %57
%59 = call i32 (i128*, i64, i64, ...) bitcast (i32 (...)* @quad_fetch_add to i32 (i128*, i64, i64, ...)*)(i128* %3, i64 %56, i64 %58)
%60 = sext i32 %59 to i128
store i128 %60, i128* %2
%61 = load i128, i128* %2
%62 = load i128, i128* %10
%63 = icmp ne i128 %61, %62
br i1 %63, label %68, label %64
64: ; preds = %51
%65 = load i128, i128* %3
%66 = load i128, i128* %12
%67 = icmp ne i128 %65, %66
br i1 %67, label %68, label %69
68: ; preds = %64, %51
unreachable
69: ; preds = %64
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i128
%2 = bitcast i128* %1 to i8*
store i128 24197857200151252746022454892744229665, i128* %1
%3 = call i32 (i128*, i64, i64, ...) bitcast (i32 (...)* @quad_fetch_and to i32 (i128*, i64, i64, ...)*)(i128* %1, i64 -16, i64 -16)
unreachable
}