#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int fail = 0;
  int error = 0;
  double a = 0;
  int ii = 0;
#pragma omp target map(tofrom : a)
  {
#pragma omp parallel for
    for (ii = 0; ii < 100; ++ii)
#pragma omp atomic
      a++;
  }
  double result = a;
  double expect = 100;
  if (result != expect) {
    printf("update (implicit) a %f != %f (error %d)\n", result, expect,
           ++error);
    fail = 1;
  }
  if (!fail)
    printf("successful\n");
  else
    fail = 0;
  printf("done with %d errors\n", error);
  return error;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    116d <main+0x5d>
movsd  0xeb3(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <main+0x33>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe81(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jne    119f <main+0x8f>
jp     119f <main+0x8f>
jmp    11c7 <main+0xb7>
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11e4 <main+0xd4>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11eb <main+0xdb>
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xorpd  %xmm0,%xmm0
mov    $0x64,%eax
movsd  0xece(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
add    $0xfffffff6,%eax
jne    1140 <main+0x20>
ucomisd 0xe93(%rip),%xmm0
jne    1179 <main+0x59>
jnp    119b <main+0x7b>
lea    0xe90(%rip),%rdi
movsd  0xe80(%rip),%xmm1
mov    $0x1,%ebx
mov    $0x1,%esi
mov    $0x2,%al
call   1040 <printf@plt>
jmp    11a9 <main+0x89>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
lea    0xe89(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"update (implicit) a %f != %f (error %d)\0A\00"
@.str.1 = [12 x i8] c"successful\0A\00"
@.str.2 = [21 x i8] c"done with %d errors\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
%6 = alloca double
%7 = alloca double
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store double 0.000000e+00, double* %4
store i32 0, i32* %5
store i32 0, i32* %5
br label %8
8: ; preds = %14, %0
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 100
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load double, double* %4
%13 = fadd double %12, 1.000000e+00
store double %13, double* %4
br label %14
14: ; preds = %11
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5
br label %8
17: ; preds = %8
%18 = load double, double* %4
store double %18, double* %6
store double 1.000000e+02, double* %7
%19 = load double, double* %6
%20 = load double, double* %7
%21 = fcmp une double %19, %20
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load double, double* %6
%24 = load double, double* %7
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), double %23, double %24, i32 %26)
store i32 1, i32* %2
br label %28
28: ; preds = %22, %17
%29 = load i32, i32* %2
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %34
33: ; preds = %28
store i32 0, i32* %2
br label %34
34: ; preds = %33, %31
%35 = load i32, i32* %3
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [41 x i8] c"update (implicit) a %f != %f (error %d)\0A\00"
@.str.2 = [21 x i8] c"done with %d errors\0A\00"
@str = [11 x i8] c"successful\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 0, %0 ], [ %14, %1 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %13, %1 ]
%4 = fadd double %3, 1.000000e+00
%5 = fadd double %4, 1.000000e+00
%6 = fadd double %5, 1.000000e+00
%7 = fadd double %6, 1.000000e+00
%8 = fadd double %7, 1.000000e+00
%9 = fadd double %8, 1.000000e+00
%10 = fadd double %9, 1.000000e+00
%11 = fadd double %10, 1.000000e+00
%12 = fadd double %11, 1.000000e+00
%13 = fadd double %12, 1.000000e+00
%14 = add nuw nsw i32 %2, 10
%15 = icmp eq i32 %14, 100
br i1 %15, label %16, label %1
16: ; preds = %1
%17 = fcmp une double %13, 1.000000e+02
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), double %13, double 1.000000e+02, i32 1)
br label %22
20: ; preds = %16
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %18, %20
%23 = phi i32 [ 1, %18 ], [ 0, %20 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %23)
ret i32 %23
}