#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 test_kernels() {
  int val = 2;
  int ary[32];
  int ondev = 0;
  for (int i = 0; i < 32; i++)
    ary[i] = ~0;
#pragma acc kernels copy(ondev)
  {
    ondev = acc_on_device(acc_device_not_host);
#pragma acc loop
    for (unsigned i = 0; i < 32; i++) {
      ary[i] = val;
      val++;
    }
  }
  if (ondev) {
    if (val != 2 + 32)
      return 1;
    for (int i = 0; i < 32; i++)
      if (ary[i] != 2 + i)
        return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_kernels>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x2,-0x8(%rbp)
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
cmpl   $0x20,-0x98(%rbp)
jge    1169 <test_kernels+0x59>
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    1136 <test_kernels+0x26>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
call   1030 <acc_on_device@plt>
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x9c(%rbp)
cmpl   $0x20,-0x9c(%rbp)
jae    11c1 <test_kernels+0xb1>
mov    -0x8(%rbp),%ecx
mov    -0x9c(%rbp),%eax
mov    %ecx,-0x90(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1187 <test_kernels+0x77>
cmpl   $0x0,-0x94(%rbp)
je     1244 <test_kernels+0x134>
cmpl   $0x22,-0x8(%rbp)
je     11e4 <test_kernels+0xd4>
movl   $0x1,-0x4(%rbp)
jmp    124b <test_kernels+0x13b>
movl   $0x0,-0xa0(%rbp)
cmpl   $0x20,-0xa0(%rbp)
jge    123f <test_kernels+0x12f>
movslq -0xa0(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%eax
mov    -0xa0(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
je     1226 <test_kernels+0x116>
movl   $0x1,-0x4(%rbp)
jmp    124b <test_kernels+0x13b>
jmp    122b <test_kernels+0x11b>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    11ee <test_kernels+0xde>
jmp    1244 <test_kernels+0x134>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_kernels>:
sub    $0x88,%rsp
mov    0x2eca(%rip),%rax
mov    (%rax),%edi
call   1030 <acc_on_device@plt>
movaps 0xed4(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xedd(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xee5(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xee9(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeed(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xef1(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
test   %eax,%eax
je     11e5 <test_kernels+0xd5>
mov    $0x5,%ecx
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x10(%rsp,%rcx,4),%edx
lea    -0x2(%rcx),%rsi
cmp    %rdx,%rsi
jne    11dd <test_kernels+0xcd>
mov    -0xc(%rsp,%rcx,4),%edx
lea    -0x1(%rcx),%rsi
cmp    %rdx,%rsi
jne    11dd <test_kernels+0xcd>
mov    -0x8(%rsp,%rcx,4),%edx
cmp    %rdx,%rcx
jne    11dd <test_kernels+0xcd>
cmp    $0x21,%rcx
je     11e5 <test_kernels+0xd5>
mov    -0x4(%rsp,%rcx,4),%edx
lea    0x4(%rcx),%rsi
add    $0x1,%rcx
cmp    %rdx,%rcx
mov    %rsi,%rcx
je     11a0 <test_kernels+0x90>
add    $0x88,%rsp
ret
xor    %eax,%eax
add    $0x88,%rsp
ret

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

LLVM IR (-O2):
@acc_device_not_host = global i32 0
define i32 @test_kernels() {
%1 = alloca [32 x i32]
%2 = bitcast [32 x i32]* %1 to i8*
%3 = load i32, i32* @acc_device_not_host
%4 = tail call i32 @acc_on_device(i32 %3)
%5 = bitcast [32 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 2, i32 3, i32 4, i32 5>, <4 x i32>* %5
%6 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 4
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 6, i32 7, i32 8, i32 9>, <4 x i32>* %7
%8 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 8
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 10, i32 11, i32 12, i32 13>, <4 x i32>* %9
%10 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 12
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 14, i32 15, i32 16, i32 17>, <4 x i32>* %11
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 16
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 18, i32 19, i32 20, i32 21>, <4 x i32>* %13
%14 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 20
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 22, i32 23, i32 24, i32 25>, <4 x i32>* %15
%16 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 24
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 26, i32 27, i32 28, i32 29>, <4 x i32>* %17
%18 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 28
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 30, i32 31, i32 32, i32 33>, <4 x i32>* %19
%20 = icmp eq i32 %4, 0
br i1 %20, label %52, label %21
21: ; preds = %0, %46
%22 = phi i64 [ %44, %46 ], [ 0, %0 ]
%23 = or i64 %22, 1
%24 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = or i64 %22, 3
%27 = zext i32 %25 to i64
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %52
29: ; preds = %21
%30 = or i64 %22, 2
%31 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = add nuw nsw i64 %22, 4
%34 = zext i32 %32 to i64
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %52
36: ; preds = %29
%37 = or i64 %22, 3
%38 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = add nuw nsw i64 %22, 5
%41 = zext i32 %39 to i64
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %52
43: ; preds = %36
%44 = add nuw nsw i64 %22, 4
%45 = icmp eq i64 %44, 32
br i1 %45, label %52, label %46
46: ; preds = %43
%47 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 %44
%48 = load i32, i32* %47
%49 = add nuw i64 %22, 6
%50 = zext i32 %48 to i64
%51 = icmp eq i64 %49, %50
br i1 %51, label %21, label %52
52: ; preds = %21, %29, %36, %43, %46, %0
%53 = phi i32 [ 0, %0 ], [ 1, %21 ], [ 1, %29 ], [ 1, %36 ], [ 0, %43 ], [ 1, %46 ]
ret i32 %53
}