#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_host;
scalar_t__ acc_on_device(int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
void parallel_g_1() {
  int x = 5, i, arr[32];
  for (i = 0; i < 32; i++)
    arr[i] = 3;
#pragma acc parallel private(x) copy(arr) num_gangs(32) num_workers(8)         \
    vector_length(32)
  {
#pragma acc loop gang(static : 1)
    for (i = 0; i < 32; i++)
      x = i * 2;
#pragma acc loop gang(static : 1)
    for (i = 0; i < 32; i++) {
      if (acc_on_device(acc_device_host))
        x = i * 2;
      arr[i] += x;
    }
  }
  for (i = 0; i < 32; i++)
    assert(arr[i] == 3 + i * 2);
}


x86 assembly (clang, -O0):
<parallel_g_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x5,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jge    1160 <parallel_g_1+0x40>
movslq -0x8(%rbp),%rax
movl   $0x3,-0x90(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1139 <parallel_g_1+0x19>
movl   $0x0,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jge    1188 <parallel_g_1+0x68>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1167 <parallel_g_1+0x47>
movl   $0x0,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jge    11dd <parallel_g_1+0xbd>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1030 <acc_on_device@plt>
cmp    $0x0,%rax
je     11ba <parallel_g_1+0x9a>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
movslq -0x8(%rbp),%rax
add    -0x90(%rbp,%rax,4),%ecx
mov    %ecx,-0x90(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118f <parallel_g_1+0x6f>
movl   $0x0,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jge    121f <parallel_g_1+0xff>
movslq -0x8(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
add    $0x3,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e4 <parallel_g_1+0xc4>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parallel_g_1>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
movaps 0xece(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x70(%rsp)
mov    $0x3e,%ebp
xor    %ebx,%ebx
mov    0x2e79(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r14),%edi
call   1030 <acc_on_device@plt>
test   %rax,%rax
cmovne %ebx,%ebp
add    %ebp,(%rsp,%rbx,2)
add    $0x2,%rbx
cmp    $0x40,%rbx
jne    1170 <parallel_g_1+0x50>
mov    $0x3,%ebx
mov    -0x6(%rsp,%rbx,2),%eax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1040 <assert@plt>
add    $0x2,%rbx
cmp    $0x43,%rbx
jne    1190 <parallel_g_1+0x70>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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