#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 check(int *, int, int, int, int);
int /*<<< orphan*/ clear(int *, int);
int place();
int gang_2(int *ary, int size) {
  clear(ary, size);
#pragma acc parallel num_gangs(32) num_workers(32) vector_length(32)           \
    copy(ary [0:size]) firstprivate(size)
  {
#pragma acc loop auto
    for (int kx = 0; kx < size / (32 * 32); kx++)
#pragma acc loop auto
      for (int jx = 0; jx < 32; jx++)
#pragma acc loop auto
        for (int ix = 0; ix < 32; ix++)
          ary[ix + jx * 32 + kx * 32 * 32] = place();
  }
  return check(ary, size, 1, 1, 1);
}


x86 assembly (clang, -O0):
<gang_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <clear@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11ef <gang_2+0xbf>
movl   $0x0,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jge    11dc <gang_2+0xac>
movl   $0x0,-0x18(%rbp)
cmpl   $0x20,-0x18(%rbp)
jge    11c9 <gang_2+0x99>
mov    $0x0,%al
call   1030 <place@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%esi
shl    $0x5,%esi
add    %esi,%ecx
mov    -0x10(%rbp),%esi
shl    $0x5,%esi
shl    $0x5,%esi
add    %esi,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1188 <gang_2+0x58>
jmp    11ce <gang_2+0x9e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <gang_2+0x47>
jmp    11e1 <gang_2+0xb1>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1152 <gang_2+0x22>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x1,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1040 <check@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gang_2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,0x10(%rsp)
call   1050 <clear@plt>
mov    %ebx,0xc(%rsp)
cmp    $0x400,%ebx
jl     11c4 <gang_2+0x94>
mov    0xc(%rsp),%eax
mov    %eax,%r12d
shr    $0xa,%r12d
mov    0x10(%rsp),%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r13,%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <place@plt>
mov    %eax,0x0(%rbp,%r15,4)
add    $0x1,%r15
cmp    $0x20,%r15
jne    1190 <gang_2+0x60>
add    $0x1,%r14
sub    $0xffffffffffffff80,%rbp
cmp    $0x20,%r14
jne    1180 <gang_2+0x50>
add    $0x1,%rbx
add    $0x1000,%r13
cmp    %r12,%rbx
jne    1170 <gang_2+0x40>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    $0x1,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <check@plt>

LLVM IR (-O0):
define i32 @gang_2(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32*, i32** %3
%9 = load i32, i32* %4
%10 = call i32 @clear(i32* %8, i32 %9)
store i32 0, i32* %5
br label %11
11: ; preds = %45, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = sdiv i32 %13, 1024
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %48
16: ; preds = %11
store i32 0, i32* %6
br label %17
17: ; preds = %41, %16
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 32
br i1 %19, label %20, label %44
20: ; preds = %17
store i32 0, i32* %7
br label %21
21: ; preds = %37, %20
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 32
br i1 %23, label %24, label %40
24: ; preds = %21
%25 = call i32 (...) @place()
%26 = load i32*, i32** %3
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = mul nsw i32 %28, 32
%30 = add nsw i32 %27, %29
%31 = load i32, i32* %5
%32 = mul nsw i32 %31, 32
%33 = mul nsw i32 %32, 32
%34 = add nsw i32 %30, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %26, i64 %35
store i32 %25, i32* %36
br label %37
37: ; preds = %24
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %21
40: ; preds = %21
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %17
44: ; preds = %17
br label %45
45: ; preds = %44
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %11
48: ; preds = %11
%49 = load i32*, i32** %3
%50 = load i32, i32* %4
%51 = call i32 @check(i32* %49, i32 %50, i32 1, i32 1, i32 1)
ret i32 %51
}

LLVM IR (-O2):
define i32 @gang_2(i32* %0, i32 %1) {
%3 = tail call i32 @clear(i32* %0, i32 %1)
%4 = icmp sgt i32 %1, 1023
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = lshr i32 %1, 10
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %5, %17
%9 = phi i64 [ 0, %5 ], [ %18, %17 ]
%10 = shl nsw i64 %9, 10
br label %13
11: ; preds = %17, %2
%12 = tail call i32 @check(i32* %0, i32 %1, i32 1, i32 1, i32 1)
ret i32 %12
13: ; preds = %8, %20
%14 = phi i64 [ 0, %8 ], [ %21, %20 ]
%15 = shl nsw i64 %14, 5
%16 = add nuw nsw i64 %15, %10
br label %23
17: ; preds = %20
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %7
br i1 %19, label %11, label %8
20: ; preds = %23
%21 = add nuw nsw i64 %14, 1
%22 = icmp eq i64 %21, 32
br i1 %22, label %17, label %13
23: ; preds = %13, %23
%24 = phi i64 [ 0, %13 ], [ %28, %23 ]
%25 = tail call i32 (...) @place()
%26 = add nuw nsw i64 %16, %24
%27 = getelementptr inbounds i32, i32* %0, i64 %26
store i32 %25, i32* %27
%28 = add nuw nsw i64 %24, 1
%29 = icmp eq i64 %28, 32
br i1 %29, label %20, label %23
}