#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*/ atomic_compare_exchange_strong_explicit(int /*<<< orphan*/ *,
                                                           int *,
                                                           int /*<<< orphan*/,
                                                           int /*<<< orphan*/,
                                                           int /*<<< orphan*/);
int /*<<< orphan*/ atomic_compare_exchange_weak_explicit(int /*<<< orphan*/ *,
                                                         int *,
                                                         int /*<<< orphan*/,
                                                         int /*<<< orphan*/,
                                                         int /*<<< orphan*/);
int /*<<< orphan*/ memory_order_acq_rel;
int /*<<< orphan*/ memory_order_consume;
int /*<<< orphan*/ memory_order_relaxed;
int /*<<< orphan*/ memory_order_release;
int /*<<< orphan*/ memory_order_seq_cst;
void exchange(atomic_int *i) {
  int r;
  atomic_compare_exchange_strong_explicit(i, &r, 0, memory_order_seq_cst,
                                          memory_order_release);
  atomic_compare_exchange_strong_explicit(i, &r, 0, memory_order_seq_cst,
                                          memory_order_acq_rel);
  atomic_compare_exchange_strong_explicit(i, &r, 0, memory_order_relaxed,
                                          memory_order_consume);
  atomic_compare_exchange_weak_explicit(i, &r, 0, memory_order_seq_cst,
                                        memory_order_release);
  atomic_compare_exchange_weak_explicit(i, &r, 0, memory_order_seq_cst,
                                        memory_order_acq_rel);
  atomic_compare_exchange_weak_explicit(i, &r, 0, memory_order_relaxed,
                                        memory_order_consume);
}


x86 assembly (clang, -O0):
<exchange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%ecx
mov    0x2ea0(%rip),%rax
mov    (%rax),%r8d
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1030 <atomic_compare_exchange_strong_explicit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e7f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e66(%rip),%rax
mov    (%rax),%r8d
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1030 <atomic_compare_exchange_strong_explicit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3c(%rip),%rax
mov    (%rax),%r8d
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1030 <atomic_compare_exchange_strong_explicit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3a(%rip),%rax
mov    (%rax),%r8d
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1040 <atomic_compare_exchange_weak_explicit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%ecx
mov    0x2e00(%rip),%rax
mov    (%rax),%r8d
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1040 <atomic_compare_exchange_weak_explicit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%ecx
mov    0x2dd6(%rip),%rax
mov    (%rax),%r8d
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1040 <atomic_compare_exchange_weak_explicit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exchange>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ea3(%rip),%r15
mov    (%r15),%ecx
mov    0x2ea1(%rip),%rax
mov    (%rax),%r8d
lea    0x4(%rsp),%r14
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <atomic_compare_exchange_strong_explicit@plt>
mov    (%r15),%ecx
mov    0x2e6d(%rip),%r13
mov    0x0(%r13),%r8d
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <atomic_compare_exchange_strong_explicit@plt>
mov    0x2e75(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    0x2e43(%rip),%r12
mov    (%r12),%r8d
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <atomic_compare_exchange_strong_explicit@plt>
mov    (%r15),%ecx
mov    0x2e48(%rip),%rax
mov    (%rax),%r8d
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <atomic_compare_exchange_weak_explicit@plt>
mov    (%r15),%ecx
mov    0x0(%r13),%r8d
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <atomic_compare_exchange_weak_explicit@plt>
mov    0x0(%rbp),%ecx
mov    (%r12),%r8d
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <atomic_compare_exchange_weak_explicit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@memory_order_seq_cst = global i32 0
@memory_order_release = global i32 0
@memory_order_acq_rel = global i32 0
@memory_order_relaxed = global i32 0
@memory_order_consume = global i32 0
define void @exchange(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = load i32, i32* @memory_order_seq_cst
%6 = load i32, i32* @memory_order_release
%7 = call i32 @atomic_compare_exchange_strong_explicit(i32* %4, i32* %3, i32 0, i32 %5, i32 %6)
%8 = load i32*, i32** %2
%9 = load i32, i32* @memory_order_seq_cst
%10 = load i32, i32* @memory_order_acq_rel
%11 = call i32 @atomic_compare_exchange_strong_explicit(i32* %8, i32* %3, i32 0, i32 %9, i32 %10)
%12 = load i32*, i32** %2
%13 = load i32, i32* @memory_order_relaxed
%14 = load i32, i32* @memory_order_consume
%15 = call i32 @atomic_compare_exchange_strong_explicit(i32* %12, i32* %3, i32 0, i32 %13, i32 %14)
%16 = load i32*, i32** %2
%17 = load i32, i32* @memory_order_seq_cst
%18 = load i32, i32* @memory_order_release
%19 = call i32 @atomic_compare_exchange_weak_explicit(i32* %16, i32* %3, i32 0, i32 %17, i32 %18)
%20 = load i32*, i32** %2
%21 = load i32, i32* @memory_order_seq_cst
%22 = load i32, i32* @memory_order_acq_rel
%23 = call i32 @atomic_compare_exchange_weak_explicit(i32* %20, i32* %3, i32 0, i32 %21, i32 %22)
%24 = load i32*, i32** %2
%25 = load i32, i32* @memory_order_relaxed
%26 = load i32, i32* @memory_order_consume
%27 = call i32 @atomic_compare_exchange_weak_explicit(i32* %24, i32* %3, i32 0, i32 %25, i32 %26)
ret void
}

LLVM IR (-O2):
@memory_order_seq_cst = global i32 0
@memory_order_release = global i32 0
@memory_order_acq_rel = global i32 0
@memory_order_relaxed = global i32 0
@memory_order_consume = global i32 0
define void @exchange(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @memory_order_seq_cst
%5 = load i32, i32* @memory_order_release
%6 = call i32 @atomic_compare_exchange_strong_explicit(i32* %0, i32* %2, i32 0, i32 %4, i32 %5)
%7 = load i32, i32* @memory_order_seq_cst
%8 = load i32, i32* @memory_order_acq_rel
%9 = call i32 @atomic_compare_exchange_strong_explicit(i32* %0, i32* %2, i32 0, i32 %7, i32 %8)
%10 = load i32, i32* @memory_order_relaxed
%11 = load i32, i32* @memory_order_consume
%12 = call i32 @atomic_compare_exchange_strong_explicit(i32* %0, i32* %2, i32 0, i32 %10, i32 %11)
%13 = load i32, i32* @memory_order_seq_cst
%14 = load i32, i32* @memory_order_release
%15 = call i32 @atomic_compare_exchange_weak_explicit(i32* %0, i32* %2, i32 0, i32 %13, i32 %14)
%16 = load i32, i32* @memory_order_seq_cst
%17 = load i32, i32* @memory_order_acq_rel
%18 = call i32 @atomic_compare_exchange_weak_explicit(i32* %0, i32* %2, i32 0, i32 %16, i32 %17)
%19 = load i32, i32* @memory_order_relaxed
%20 = load i32, i32* @memory_order_consume
%21 = call i32 @atomic_compare_exchange_weak_explicit(i32* %0, i32* %2, i32 0, i32 %19, i32 %20)
ret void
}