#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ atomic_int;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ atomic_compare_exchange_weak_explicit(int /*<<< orphan*/ *,
                                                         int *, int,
                                                         int /*<<< orphan*/,
                                                         int /*<<< orphan*/);
int atomic_exchange_explicit(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ atomic_fetch_add_explicit(int /*<<< orphan*/ *, int,
                                             int /*<<< orphan*/);
int atomic_load_explicit(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ atomic_store_explicit(int /*<<< orphan*/ *, int,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ memory_order_relaxed;
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  atomic_int a, b;
  int c;
  atomic_store_explicit(&a, 0, memory_order_relaxed);
  atomic_store_explicit(&b, 1, memory_order_relaxed);
  atomic_fetch_add_explicit(&a, 10, memory_order_relaxed);
  assert(10 == atomic_load_explicit(&a, memory_order_relaxed));
  {
    int old = 10;
    int new = 11;
    atomic_compare_exchange_weak_explicit(&a, &old, new, memory_order_relaxed,
                                          memory_order_relaxed);
    c = old;
  }
  assert(10 == c);
  c = atomic_exchange_explicit(
      &a, atomic_load_explicit(&b, memory_order_relaxed), memory_order_relaxed);
  assert(11 == c);
  assert(1 == atomic_load_explicit(&a, memory_order_relaxed));
  printf("success!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
call   1070 <atomic_store_explicit@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1070 <atomic_store_explicit@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rdi
mov    $0xa,%esi
call   1080 <atomic_fetch_add_explicit@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1040 <atomic_load_explicit@plt>
mov    %eax,%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0xa,-0x20(%rbp)
movl   $0xb,-0x24(%rbp)
mov    -0x24(%rbp),%edx
mov    0x2de0(%rip),%rax
mov    (%rax),%ecx
mov    0x2dd7(%rip),%rax
mov    (%rax),%r8d
lea    -0x14(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <atomic_compare_exchange_weak_explicit@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xa,%eax
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1040 <atomic_load_explicit@plt>
mov    %eax,%esi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rdi
call   1030 <atomic_exchange_explicit@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xb,%eax
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1040 <atomic_load_explicit@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xd57(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e68(%rip),%rbx
mov    (%rbx),%edx
lea    0xc(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <atomic_store_explicit@plt>
mov    (%rbx),%edx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   1070 <atomic_store_explicit@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0xa,%esi
call   1080 <atomic_fetch_add_explicit@plt>
mov    (%rbx),%esi
mov    %r15,%rdi
call   1050 <atomic_load_explicit@plt>
xor    %edi,%edi
cmp    $0xa,%eax
sete   %dil
call   1060 <assert@plt>
movl   $0xa,0x4(%rsp)
mov    (%rbx),%ecx
lea    0x4(%rsp),%rsi
mov    %r15,%rdi
mov    $0xb,%edx
mov    %ecx,%r8d
call   1090 <atomic_compare_exchange_weak_explicit@plt>
xor    %edi,%edi
cmpl   $0xa,0x4(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1050 <atomic_load_explicit@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <atomic_exchange_explicit@plt>
xor    %edi,%edi
cmp    $0xb,%eax
sete   %dil
call   1060 <assert@plt>
mov    (%rbx),%esi
mov    %r15,%rdi
call   1050 <atomic_load_explicit@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1060 <assert@plt>
lea    0xdc2(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@memory_order_relaxed = global i32 0
@.str = [10 x i8] c"success!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @memory_order_relaxed
%12 = call i32 @atomic_store_explicit(i32* %6, i32 0, i32 %11)
%13 = load i32, i32* @memory_order_relaxed
%14 = call i32 @atomic_store_explicit(i32* %7, i32 1, i32 %13)
%15 = load i32, i32* @memory_order_relaxed
%16 = call i32 @atomic_fetch_add_explicit(i32* %6, i32 10, i32 %15)
%17 = load i32, i32* @memory_order_relaxed
%18 = call i32 @atomic_load_explicit(i32* %6, i32 %17)
%19 = icmp eq i32 10, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
store i32 10, i32* %9
store i32 11, i32* %10
%22 = load i32, i32* %10
%23 = load i32, i32* @memory_order_relaxed
%24 = load i32, i32* @memory_order_relaxed
%25 = call i32 @atomic_compare_exchange_weak_explicit(i32* %6, i32* %9, i32 %22, i32 %23, i32 %24)
%26 = load i32, i32* %9
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 10, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* @memory_order_relaxed
%32 = call i32 @atomic_load_explicit(i32* %7, i32 %31)
%33 = load i32, i32* @memory_order_relaxed
%34 = call i32 @atomic_exchange_explicit(i32* %6, i32 %32, i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp eq i32 11, %35
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i32, i32* @memory_order_relaxed
%40 = call i32 @atomic_load_explicit(i32* %6, i32 %39)
%41 = icmp eq i32 1, %40
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@memory_order_relaxed = global i32 0
@str = [9 x i8] c"success!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = load i32, i32* @memory_order_relaxed
%9 = call i32 @atomic_store_explicit(i32* %3, i32 0, i32 %8)
%10 = load i32, i32* @memory_order_relaxed
%11 = call i32 @atomic_store_explicit(i32* %4, i32 1, i32 %10)
%12 = load i32, i32* @memory_order_relaxed
%13 = call i32 @atomic_fetch_add_explicit(i32* %3, i32 10, i32 %12)
%14 = load i32, i32* @memory_order_relaxed
%15 = call i32 @atomic_load_explicit(i32* %3, i32 %14)
%16 = icmp eq i32 %15, 10
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = bitcast i32* %5 to i8*
store i32 10, i32* %5
%20 = load i32, i32* @memory_order_relaxed
%21 = call i32 @atomic_compare_exchange_weak_explicit(i32* %3, i32* %5, i32 11, i32 %20, i32 %20)
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 10
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* @memory_order_relaxed
%27 = call i32 @atomic_load_explicit(i32* %4, i32 %26)
%28 = load i32, i32* @memory_order_relaxed
%29 = call i32 @atomic_exchange_explicit(i32* %3, i32 %27, i32 %28)
%30 = icmp eq i32 %29, 11
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i32, i32* @memory_order_relaxed
%34 = call i32 @atomic_load_explicit(i32* %3, i32 %33)
%35 = icmp eq i32 %34, 1
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 0
}