#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 /*<<< orphan*/ assert(int);
void t27() {
  int n, arr[32], i;
  int ondev;
  for (i = 0; i < 32; i++)
    arr[i] = 0;
  n = 0;
#pragma acc parallel copy(n, arr) copyout(ondev) num_gangs(ACTUAL_GANGS)       \
    num_workers(8) vector_length(32)
  {
    int j;
    ondev = acc_on_device(acc_device_not_host);
#pragma acc atomic
    n++;
#pragma acc loop vector
    for (j = 0; j < 32; j++) {
#pragma acc atomic
      arr[j] += 1;
    }
#pragma acc atomic
    n++;
  }
  int m = ondev ? 8 : 1;
  assert(n == m * 2);
  for (i = 0; i < 32; i++)
    assert(arr[i] == m);
}


x86 assembly (clang, -O0):
<t27>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x94(%rbp)
cmpl   $0x20,-0x94(%rbp)
jge    1168 <t27+0x48>
movslq -0x94(%rbp),%rax
movl   $0x0,-0x90(%rbp,%rax,4)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1135 <t27+0x15>
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1030 <acc_on_device@plt>
mov    %eax,-0x98(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x9c(%rbp)
cmpl   $0x20,-0x9c(%rbp)
jge    11cf <t27+0xaf>
movslq -0x9c(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x90(%rbp,%rax,4)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1196 <t27+0x76>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x98(%rbp),%edx
mov    $0x1,%eax
mov    $0x8,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0xa0(%rbp)
mov    -0x4(%rbp),%eax
mov    -0xa0(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x20,-0x94(%rbp)
jge    125b <t27+0x13b>
movslq -0x94(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%eax
cmp    -0xa0(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1219 <t27+0xf9>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t27>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
pxor   %xmm0,%xmm0
movdqa %xmm0,0x70(%rsp)
movdqa %xmm0,0x60(%rsp)
movdqa %xmm0,0x50(%rsp)
movdqa %xmm0,0x40(%rsp)
movdqa %xmm0,0x30(%rsp)
movdqa %xmm0,0x20(%rsp)
movdqa %xmm0,0x10(%rsp)
movdqa %xmm0,(%rsp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1030 <acc_on_device@plt>
pcmpeqd %xmm0,%xmm0
movdqa (%rsp),%xmm1
movdqa 0x10(%rsp),%xmm2
movdqa 0x20(%rsp),%xmm3
movdqa 0x30(%rsp),%xmm4
psubd  %xmm0,%xmm1
movdqa %xmm1,(%rsp)
psubd  %xmm0,%xmm2
movdqa %xmm2,0x10(%rsp)
psubd  %xmm0,%xmm3
movdqa %xmm3,0x20(%rsp)
psubd  %xmm0,%xmm4
movdqa %xmm4,0x30(%rsp)
movdqa 0x40(%rsp),%xmm1
psubd  %xmm0,%xmm1
movdqa %xmm1,0x40(%rsp)
movdqa 0x50(%rsp),%xmm1
psubd  %xmm0,%xmm1
movdqa %xmm1,0x50(%rsp)
movdqa 0x60(%rsp),%xmm1
psubd  %xmm0,%xmm1
movdqa %xmm1,0x60(%rsp)
movdqa 0x70(%rsp),%xmm1
psubd  %xmm0,%xmm1
movdqa %xmm1,0x70(%rsp)
xor    %edi,%edi
test   %eax,%eax
sete   %dil
mov    $0x1,%eax
mov    $0x8,%ebp
cmove  %eax,%ebp
call   1040 <assert@plt>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
cmp    %ebp,(%rsp,%rbx,4)
sete   %dil
call   1040 <assert@plt>
add    $0x1,%rbx
cmp    $0x20,%rbx
jne    1210 <t27+0xf0>
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret

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

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