#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;
  int 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++;
  }
  int result = a;
  int expect = 100;
  if (result != expect) {
    printf("update (implicit) a %d != %d (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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    1163 <main+0x53>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <main+0x32>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x64,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11a0 <main+0x90>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11bd <main+0xad>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c4 <main+0xb4>
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
lea    0xecc(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"update (implicit) a %d != %d (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 i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %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 i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %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 i32, i32* %4
store i32 %18, i32* %6
store i32 100, i32* %7
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i32, i32* %6
%24 = load i32, i32* %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), i32 %23, i32 %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.2 = [21 x i8] c"done with %d errors\0A\00"
@str = [11 x i8] c"successful\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 0)
ret i32 0
}