#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*/ acc_device_not_host;
int acc_on_device(int /*<<< orphan*/);
int main() {
  int ok = 1;
  int val = 2;
  int ary[32];
  int ondev = 0;
  for (int i = 0; i < 32; i++)
    ary[i] = ~0;
#pragma acc parallel num_gangs(32) copy(ok) firstprivate(val) copy(ary, ondev)
  {
    ondev = acc_on_device(acc_device_not_host);
#pragma acc loop gang(static : 1)
    for (unsigned i = 0; i < 32; i++) {
      if (val != 2)
        ok = 0;
      val += i;
      ary[i] = val;
    }
  }
  if (ondev) {
    if (!ok)
      return 1;
    if (val != 2)
      return 1;
    for (int i = 0; i < 32; i++)
      if (ary[i] != 2 + i)
        return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
cmpl   $0x20,-0x98(%rbp)
jge    1177 <main+0x67>
movslq -0x98(%rbp),%rax
movl   $0xffffffff,-0x90(%rbp,%rax,4)
ff ff ff ff
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1144 <main+0x34>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1030 <acc_on_device@plt>
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x9c(%rbp)
cmpl   $0x20,-0x9c(%rbp)
jae    11e3 <main+0xd3>
cmpl   $0x2,-0xc(%rbp)
je     11b3 <main+0xa3>
movl   $0x0,-0x8(%rbp)
mov    -0x9c(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x9c(%rbp),%eax
mov    %ecx,-0x90(%rbp,%rax,4)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1195 <main+0x85>
cmpl   $0x0,-0x94(%rbp)
je     127c <main+0x16c>
cmpl   $0x0,-0x8(%rbp)
jne    1206 <main+0xf6>
movl   $0x1,-0x4(%rbp)
jmp    1283 <main+0x173>
cmpl   $0x2,-0xc(%rbp)
je     121c <main+0x10c>
movl   $0x1,-0x4(%rbp)
jmp    1283 <main+0x173>
movl   $0x0,-0xa0(%rbp)
cmpl   $0x20,-0xa0(%rbp)
jge    1277 <main+0x167>
movslq -0xa0(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%eax
mov    -0xa0(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
je     125e <main+0x14e>
movl   $0x1,-0x4(%rbp)
jmp    1283 <main+0x173>
jmp    1263 <main+0x153>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    1226 <main+0x116>
jmp    127c <main+0x16c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    (%rax),%edi
call   1030 <acc_on_device@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
@acc_device_not_host = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [32 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i32 2, i32* %3
store i32 0, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %16, %0
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 32
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 %14
store i32 -1, i32* %15
br label %16
16: ; preds = %12
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
br label %9
19: ; preds = %9
%20 = load i32, i32* @acc_device_not_host
%21 = call i32 @acc_on_device(i32 %20)
store i32 %21, i32* %5
store i32 0, i32* %7
br label %22
22: ; preds = %37, %19
%23 = load i32, i32* %7
%24 = icmp ult i32 %23, 32
br i1 %24, label %25, label %40
25: ; preds = %22
%26 = load i32, i32* %3
%27 = icmp ne i32 %26, 2
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %2
br label %29
29: ; preds = %28, %25
%30 = load i32, i32* %7
%31 = load i32, i32* %3
%32 = add i32 %31, %30
store i32 %32, i32* %3
%33 = load i32, i32* %3
%34 = load i32, i32* %7
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 %35
store i32 %33, i32* %36
br label %37
37: ; preds = %29
%38 = load i32, i32* %7
%39 = add i32 %38, 1
store i32 %39, i32* %7
br label %22
40: ; preds = %22
%41 = load i32, i32* %5
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %69
43: ; preds = %40
%44 = load i32, i32* %2
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %43
store i32 1, i32* %1
br label %70
47: ; preds = %43
%48 = load i32, i32* %3
%49 = icmp ne i32 %48, 2
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 1, i32* %1
br label %70
51: ; preds = %47
store i32 0, i32* %8
br label %52
52: ; preds = %65, %51
%53 = load i32, i32* %8
%54 = icmp slt i32 %53, 32
br i1 %54, label %55, label %68
55: ; preds = %52
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = load i32, i32* %8
%61 = add nsw i32 2, %60
%62 = icmp ne i32 %59, %61
br i1 %62, label %63, label %64
63: ; preds = %55
store i32 1, i32* %1
br label %70
64: ; preds = %55
br label %65
65: ; preds = %64
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
br label %52
68: ; preds = %52
br label %69
69: ; preds = %68, %40
store i32 0, i32* %1
br label %70
70: ; preds = %69, %63, %50, %46
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
@acc_device_not_host = global i32 0
define i32 @main() {
%1 = load i32, i32* @acc_device_not_host
%2 = tail call i32 @acc_on_device(i32 %1)
%3 = icmp ne i32 %2, 0
%4 = zext i1 %3 to i32
ret i32 %4
}