#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 uint32_t;
typedef int /*<<< orphan*/ atomic_size_t;

/* Variables and functions */
scalar_t__ UINT16_MAX;
int /*<<< orphan*/ atomic_fetch_add_explicit(int /*<<< orphan*/ *, int,
                                             int /*<<< orphan*/);
int /*<<< orphan*/ memory_order_relaxed;
void *adder_simple(void *arg) {
  size_t step;
  atomic_size_t *counter = arg;
  for (step = 0; step < ((uint32_t)UINT16_MAX * 4); ++step)
    atomic_fetch_add_explicit(counter, 1, memory_order_relaxed);
  return NULL;
}


x86 assembly (clang, -O0):
<adder_simple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%rcx
shl    $0x2,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    1171 <adder_simple+0x61>
mov    -0x18(%rbp),%rdi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1030 <atomic_fetch_add_explicit@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112c <adder_simple+0x1c>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adder_simple>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2eb9(%rip),%r14
cmpl   $0x0,(%r14)
je     1162 <adder_simple+0x52>
mov    %rdi,%r15
xor    %ebx,%ebx
mov    0x2eb7(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x1,%esi
call   1030 <atomic_fetch_add_explicit@plt>
add    $0x1,%rbx
mov    (%r14),%eax
shl    $0x2,%eax
cltq
cmp    %rax,%rbx
jb     1140 <adder_simple+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@UINT16_MAX = global i64 0
@memory_order_relaxed = global i32 0
define i8* @adder_simple(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i32*
store i32* %6, i32** %4
store i64 0, i64* %3
br label %7
7: ; preds = %18, %1
%8 = load i64, i64* %3
%9 = load i64, i64* @UINT16_MAX
%10 = trunc i64 %9 to i32
%11 = mul nsw i32 %10, 4
%12 = sext i32 %11 to i64
%13 = icmp ult i64 %8, %12
br i1 %13, label %14, label %21
14: ; preds = %7
%15 = load i32*, i32** %4
%16 = load i32, i32* @memory_order_relaxed
%17 = call i32 @atomic_fetch_add_explicit(i32* %15, i32 1, i32 %16)
br label %18
18: ; preds = %14
%19 = load i64, i64* %3
%20 = add i64 %19, 1
store i64 %20, i64* %3
br label %7
21: ; preds = %7
ret i8* null
}

LLVM IR (-O2):
@UINT16_MAX = global i64 0
@memory_order_relaxed = global i32 0
define noalias i8* @adder_simple(i8* %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i64, i64* @UINT16_MAX
%4 = trunc i64 %3 to i32
%5 = icmp eq i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %10, %6 ], [ 0, %1 ]
%8 = load i32, i32* @memory_order_relaxed
%9 = tail call i32 @atomic_fetch_add_explicit(i32* %2, i32 1, i32 %8)
%10 = add nuw i64 %7, 1
%11 = load i64, i64* @UINT16_MAX
%12 = trunc i64 %11 to i32
%13 = shl nsw i32 %12, 2
%14 = sext i32 %13 to i64
%15 = icmp ult i64 %10, %14
br i1 %15, label %6, label %16
16: ; preds = %6, %1
ret i8* null
}