#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 */
struct timeval {
  int tv_sec;
  double tv_usec;
};

/* Variables and functions */
scalar_t__ RAND_MAX;
int /*<<< orphan*/ acc_device_default;
int /*<<< orphan*/ acc_init(int /*<<< orphan*/);
float fabsf(float);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/);
int main() {
  int i, j, k;
  int NI, NJ, NK;
  int error;
  float sum, known_sum;
  float *input, *temp;
  float rounding_error = 1.E-9;
  struct timeval tim;
  double start, end;
  NK = 1 << 20;
  NJ = 2;
  NI = 32;
  error = 0;
  input = (float *)malloc(NK * NJ * NI * sizeof(float));
  temp = (float *)malloc(NK * NJ * NI * sizeof(float));
  acc_init(acc_device_default);
  srand((unsigned)time(0));
  for (k = 0; k < NK; k++) {
    for (j = 0; j < NJ; j++) {
      for (i = 0; i < NI; i++) {
        input[k * NJ * NI + j * NI + i] = (float)rand() / (float)RAND_MAX + 0.1;
      }
    }
  }
  sum = 0.0;
  gettimeofday(&tim, NULL);
  start = tim.tv_sec * 1000 + (tim.tv_usec / 1000.0);
#pragma acc parallel copyin(input [0:NK * NJ * NI])                            \
    create(temp [0:NK * NJ * NI]) num_gangs(192) num_workers(8)                \
        vector_length(128)
  {
#pragma acc loop gang reduction(+ : sum)
    for (k = 0; k < NK; k++) {
#pragma acc loop worker
      for (j = 0; j < NJ; j++) {
#pragma acc loop vector
        for (i = 0; i < NI; i++)
          temp[k * NJ * NI + j * NI + i] = input[k * NJ * NI + j * NI + i];
      }
      sum += temp[k * NJ * NI];
    }
  }
  gettimeofday(&tim, NULL);
  end = tim.tv_sec * 1000 + (tim.tv_usec / 1000.0);
  known_sum = 0.0;
  for (k = 0; k < NK; k++) {
    known_sum += input[k * NJ * NI];
  }
  if (fabsf(sum - known_sum) > rounding_error) {
    error++;
    printf("gang + FAILED! sum=%f, known_sum=%f\n", sum, known_sum);
  }
  printf("gang + execution time is :%.2lf: ms\n", end - start);
  if (error == 0)
    printf("gang + SUCCESS!\n");
  free(input);
  free(temp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movss  0xe69(%rip),%xmm0
movss  %xmm0,-0x3c(%rbp)
movl   $0x100000,-0x1c(%rbp)
movl   $0x2,-0x18(%rbp)
movl   $0x20,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1090 <acc_init@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12cc <main+0x14c>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12b9 <main+0x139>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a6 <main+0x126>
mov    $0x0,%al
call   10a0 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2d90(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xda3(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0x18(%rbp),%ecx
imul   -0x14(%rbp),%ecx
mov    -0xc(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1239 <main+0xb9>
jmp    12ab <main+0x12b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1226 <main+0xa6>
jmp    12be <main+0x13e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1213 <main+0x93>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
imul   $0x3e8,-0x50(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  0xd0f(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    13d5 <main+0x255>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13a6 <main+0x226>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1393 <main+0x213>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0x18(%rbp),%ecx
imul   -0x14(%rbp),%ecx
mov    -0xc(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0x18(%rbp),%ecx
imul   -0x14(%rbp),%ecx
mov    -0xc(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1333 <main+0x1b3>
jmp    1398 <main+0x218>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1320 <main+0x1a0>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0x18(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    130d <main+0x18d>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
imul   $0x3e8,-0x50(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  0xc0e(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1451 <main+0x2d1>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0x18(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
addss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1416 <main+0x296>
movss  -0x24(%rbp),%xmm0
subss  -0x28(%rbp),%xmm0
movaps 0xbbe(%rip),%xmm1
pand   %xmm1,%xmm0
ucomiss -0x3c(%rbp),%xmm0
jbe    1499 <main+0x319>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x28(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xb9e(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x60(%rbp),%xmm0
subsd  -0x58(%rbp),%xmm0
lea    0xbab(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jne    14c9 <main+0x349>
lea    0xbb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x10000000,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    $0x10000000,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   10a0 <acc_init@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    0x2e0d(%rip),%r12
mov    %r15,%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   10b0 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq (%r12),%xmm1
divss  %xmm1,%xmm0
movsd  0xddc(%rip),%xmm1
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x20,%rbp
jne    1200 <main+0x70>
mov    $0x20,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   10b0 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq (%r12),%xmm1
divss  %xmm1,%xmm0
movsd  0xd8c(%rip),%xmm1
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x40,%rbp
jne    1250 <main+0xc0>
add    $0x1,%r13
add    $0x100,%rbx
cmp    $0x100000,%r13
jne    11f0 <main+0x60>
xor    %r12d,%r12d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
imul   $0x3e8,0x10(%rsp),%r8d
movsd  0x18(%rsp),%xmm1
divsd  0xd3b(%rip),%xmm1
lea    0xc(%r14),%rcx
lea    0xc(%r15),%rdx
lea    0x8c(%r14),%rsi
lea    0x8c(%r15),%rdi
xorps  %xmm2,%xmm2
jmp    13c4 <main+0x234>
nopl   0x0(%rax,%rax,1)
mov    %r11,%rax
or     $0x20,%rax
movups (%r15,%rax,4),%xmm0
movups %xmm0,(%r14,%rax,4)
lea    0x0(,%r11,4),%rax
mov    %rax,%rbp
or     $0x90,%rbp
movups (%r15,%rbp,1),%xmm0
movups %xmm0,(%r14,%rbp,1)
mov    %rax,%rbp
or     $0xa0,%rbp
movups (%r15,%rbp,1),%xmm0
movups %xmm0,(%r14,%rbp,1)
mov    %rax,%rbp
or     $0xb0,%rbp
movups (%r15,%rbp,1),%xmm0
movups %xmm0,(%r14,%rbp,1)
mov    %rax,%rbp
or     $0xc0,%rbp
movups (%r15,%rbp,1),%xmm0
movups %xmm0,(%r14,%rbp,1)
mov    %rax,%rbp
or     $0xd0,%rbp
movups (%r15,%rbp,1),%xmm0
movups %xmm0,(%r14,%rbp,1)
mov    %rax,%rbp
or     $0xe0,%rbp
movups (%r15,%rbp,1),%xmm0
movups %xmm0,(%r14,%rbp,1)
or     $0xf0,%rax
movups (%r15,%rax,1),%xmm0
movups %xmm0,(%r14,%rax,1)
addss  (%r14,%r11,4),%xmm2
add    $0x1,%r12
add    $0x100,%rcx
add    $0x100,%rdx
add    $0x100,%rsi
add    $0x100,%rdi
cmp    $0x100000,%r12
je     152d <main+0x39d>
mov    %r12,%r11
shl    $0x6,%r11
mov    %r12,%rbx
shl    $0x8,%rbx
lea    (%r14,%rbx,1),%r10
add    $0x80,%r10
lea    (%r15,%rbx,1),%r9
add    $0x80,%r9
lea    (%r14,%rbx,1),%rbp
cmp    %r9,%rbp
jae    1440 <main+0x2b0>
lea    (%r15,%rbx,1),%rbp
cmp    %r10,%rbp
jae    1440 <main+0x2b0>
xor    %ebp,%ebp
nopl   0x0(%rax)
movss  -0xc(%rdx,%rbp,4),%xmm0
movss  %xmm0,-0xc(%rcx,%rbp,4)
movss  -0x8(%rdx,%rbp,4),%xmm0
movss  %xmm0,-0x8(%rcx,%rbp,4)
movss  -0x4(%rdx,%rbp,4),%xmm0
movss  %xmm0,-0x4(%rcx,%rbp,4)
movss  (%rdx,%rbp,4),%xmm0
movss  %xmm0,(%rcx,%rbp,4)
add    $0x4,%rbp
cmp    $0x20,%rbp
jne    1400 <main+0x270>
jmp    14c6 <main+0x336>
nopl   (%rax)
lea    0x0(,%r11,4),%rbp
movups (%r15,%r11,4),%xmm0
movups %xmm0,(%r14,%r11,4)
mov    %rbp,%rax
or     $0x10,%rax
movups (%r15,%rax,1),%xmm0
movups %xmm0,(%r14,%rax,1)
mov    %rbp,%rax
or     $0x20,%rax
movups (%r15,%rax,1),%xmm0
movups %xmm0,(%r14,%rax,1)
mov    %rbp,%rax
or     $0x30,%rax
movups (%r15,%rax,1),%xmm0
movups %xmm0,(%r14,%rax,1)
mov    %rbp,%rax
or     $0x40,%rax
movups (%r15,%rax,1),%xmm0
movups %xmm0,(%r14,%rax,1)
mov    %rbp,%rax
or     $0x50,%rax
movups (%r15,%rax,1),%xmm0
movups %xmm0,(%r14,%rax,1)
mov    %rbp,%rax
or     $0x60,%rax
movups (%r15,%rax,1),%xmm0
movups %xmm0,(%r14,%rax,1)
or     $0x70,%rbp
movups (%r15,%rbp,1),%xmm0
movups %xmm0,(%r14,%rbp,1)
lea    (%r15,%rbx,1),%rax
add    $0x100,%rax
cmp    %rax,%r10
jae    12f0 <main+0x160>
lea    (%r14,%rbx,1),%rax
add    $0x100,%rax
cmp    %rax,%r9
jae    12f0 <main+0x160>
xor    %ebp,%ebp
xchg   %ax,%ax
movss  -0xc(%rdi,%rbp,4),%xmm0
movss  %xmm0,-0xc(%rsi,%rbp,4)
movss  -0x8(%rdi,%rbp,4),%xmm0
movss  %xmm0,-0x8(%rsi,%rbp,4)
movss  -0x4(%rdi,%rbp,4),%xmm0
movss  %xmm0,-0x4(%rsi,%rbp,4)
movss  (%rdi,%rbp,4),%xmm0
movss  %xmm0,(%rsi,%rbp,4)
add    $0x4,%rbp
cmp    $0x20,%rbp
jne    14f0 <main+0x360>
jmp    1391 <main+0x201>
movss  %xmm2,(%rsp)
movsd  %xmm1,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r8d,%xmm0
movsd  %xmm0,0x20(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
imul   $0x3e8,0x10(%rsp),%eax
movsd  0x18(%rsp),%xmm5
divsd  0xaa0(%rip),%xmm5
xorpd  %xmm1,%xmm1
mov    $0x300,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
addss  -0x300(%r15,%rcx,1),%xmm1
fd ff ff
addss  -0x200(%r15,%rcx,1),%xmm1
fe ff ff
addss  -0x100(%r15,%rcx,1),%xmm1
ff ff ff
addss  (%r15,%rcx,1),%xmm1
add    $0x400,%rcx
cmp    $0x10000300,%rcx
jne    1580 <main+0x3f0>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm3
addsd  0x20(%rsp),%xmm3
movss  (%rsp),%xmm4
movaps %xmm4,%xmm2
subss  %xmm1,%xmm2
andps  0xa36(%rip),%xmm2
addsd  %xmm0,%xmm5
ucomiss 0xa3b(%rip),%xmm2
jbe    1626 <main+0x496>
xorps  %xmm0,%xmm0
cvtss2sd %xmm4,%xmm0
cvtss2sd %xmm1,%xmm1
lea    0xa2b(%rip),%rdi
mov    $0x2,%al
movsd  %xmm3,0x8(%rsp)
movsd  %xmm5,(%rsp)
call   1050 <printf@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
lea    0xa2c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    1648 <main+0x4b8>
subsd  %xmm3,%xmm5
lea    0xa18(%rip),%rdi
movapd %xmm5,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xa2b(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, double }
@acc_device_default = global i32 0
@RAND_MAX = global i64 0
@.str = [37 x i8] c"gang + FAILED! sum=%f, known_sum=%f\0A\00"
@.str.1 = [37 x i8] c"gang + execution time is :%.2lf: ms\0A\00"
@.str.2 = [17 x i8] c"gang + SUCCESS!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = alloca float
%11 = alloca float*
%12 = alloca float*
%13 = alloca float
%14 = alloca %struct.timeval
%15 = alloca double
%16 = alloca double
store i32 0, i32* %1
store float 0x3E112E0BE0000000, float* %13
store i32 1048576, i32* %7
store i32 2, i32* %6
store i32 32, i32* %5
store i32 0, i32* %8
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = mul nsw i32 %17, %18
%20 = load i32, i32* %5
%21 = mul nsw i32 %19, %20
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to float*
store float* %26, float** %11
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %5
%31 = mul nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 4
%34 = trunc i64 %33 to i32
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to float*
store float* %36, float** %12
%37 = load i32, i32* @acc_device_default
%38 = call i32 @acc_init(i32 %37)
%39 = call i64 @time(i32 0)
%40 = trunc i64 %39 to i32
%41 = call i32 @srand(i32 %40)
store i32 0, i32* %4
br label %42
42: ; preds = %87, %0
%43 = load i32, i32* %4
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %90
46: ; preds = %42
store i32 0, i32* %3
br label %47
47: ; preds = %83, %46
%48 = load i32, i32* %3
%49 = load i32, i32* %6
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %86
51: ; preds = %47
store i32 0, i32* %2
br label %52
52: ; preds = %79, %51
%53 = load i32, i32* %2
%54 = load i32, i32* %5
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %82
56: ; preds = %52
%57 = call i64 (...) @rand()
%58 = sitofp i64 %57 to float
%59 = load i64, i64* @RAND_MAX
%60 = sitofp i64 %59 to float
%61 = fdiv float %58, %60
%62 = fpext float %61 to double
%63 = fadd double %62, 1.000000e-01
%64 = fptrunc double %63 to float
%65 = load float*, float** %11
%66 = load i32, i32* %4
%67 = load i32, i32* %6
%68 = mul nsw i32 %66, %67
%69 = load i32, i32* %5
%70 = mul nsw i32 %68, %69
%71 = load i32, i32* %3
%72 = load i32, i32* %5
%73 = mul nsw i32 %71, %72
%74 = add nsw i32 %70, %73
%75 = load i32, i32* %2
%76 = add nsw i32 %74, %75
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds float, float* %65, i64 %77
store float %64, float* %78
br label %79
79: ; preds = %56
%80 = load i32, i32* %2
%81 = add nsw i32 %80, 1
store i32 %81, i32* %2
br label %52
82: ; preds = %52
br label %83
83: ; preds = %82
%84 = load i32, i32* %3
%85 = add nsw i32 %84, 1
store i32 %85, i32* %3
br label %47
86: ; preds = %47
br label %87
87: ; preds = %86
%88 = load i32, i32* %4
%89 = add nsw i32 %88, 1
store i32 %89, i32* %4
br label %42
90: ; preds = %42
store float 0.000000e+00, float* %9
%91 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%92 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%93 = load i32, i32* %92
%94 = mul nsw i32 %93, 1000
%95 = sitofp i32 %94 to double
%96 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%97 = load double, double* %96
%98 = fdiv double %97, 1.000000e+03
%99 = fadd double %95, %98
store double %99, double* %15
store i32 0, i32* %4
br label %100
100: ; preds = %163, %90
%101 = load i32, i32* %4
%102 = load i32, i32* %7
%103 = icmp slt i32 %101, %102
br i1 %103, label %104, label %166
104: ; preds = %100
store i32 0, i32* %3
br label %105
105: ; preds = %148, %104
%106 = load i32, i32* %3
%107 = load i32, i32* %6
%108 = icmp slt i32 %106, %107
br i1 %108, label %109, label %151
109: ; preds = %105
store i32 0, i32* %2
br label %110
110: ; preds = %144, %109
%111 = load i32, i32* %2
%112 = load i32, i32* %5
%113 = icmp slt i32 %111, %112
br i1 %113, label %114, label %147
114: ; preds = %110
%115 = load float*, float** %11
%116 = load i32, i32* %4
%117 = load i32, i32* %6
%118 = mul nsw i32 %116, %117
%119 = load i32, i32* %5
%120 = mul nsw i32 %118, %119
%121 = load i32, i32* %3
%122 = load i32, i32* %5
%123 = mul nsw i32 %121, %122
%124 = add nsw i32 %120, %123
%125 = load i32, i32* %2
%126 = add nsw i32 %124, %125
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds float, float* %115, i64 %127
%129 = load float, float* %128
%130 = load float*, float** %12
%131 = load i32, i32* %4
%132 = load i32, i32* %6
%133 = mul nsw i32 %131, %132
%134 = load i32, i32* %5
%135 = mul nsw i32 %133, %134
%136 = load i32, i32* %3
%137 = load i32, i32* %5
%138 = mul nsw i32 %136, %137
%139 = add nsw i32 %135, %138
%140 = load i32, i32* %2
%141 = add nsw i32 %139, %140
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds float, float* %130, i64 %142
store float %129, float* %143
br label %144
144: ; preds = %114
%145 = load i32, i32* %2
%146 = add nsw i32 %145, 1
store i32 %146, i32* %2
br label %110
147: ; preds = %110
br label %148
148: ; preds = %147
%149 = load i32, i32* %3
%150 = add nsw i32 %149, 1
store i32 %150, i32* %3
br label %105
151: ; preds = %105
%152 = load float*, float** %12
%153 = load i32, i32* %4
%154 = load i32, i32* %6
%155 = mul nsw i32 %153, %154
%156 = load i32, i32* %5
%157 = mul nsw i32 %155, %156
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds float, float* %152, i64 %158
%160 = load float, float* %159
%161 = load float, float* %9
%162 = fadd float %161, %160
store float %162, float* %9
br label %163
163: ; preds = %151
%164 = load i32, i32* %4
%165 = add nsw i32 %164, 1
store i32 %165, i32* %4
br label %100
166: ; preds = %100
%167 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%168 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%169 = load i32, i32* %168
%170 = mul nsw i32 %169, 1000
%171 = sitofp i32 %170 to double
%172 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%173 = load double, double* %172
%174 = fdiv double %173, 1.000000e+03
%175 = fadd double %171, %174
store double %175, double* %16
store float 0.000000e+00, float* %10
store i32 0, i32* %4
br label %176
176: ; preds = %192, %166
%177 = load i32, i32* %4
%178 = load i32, i32* %7
%179 = icmp slt i32 %177, %178
br i1 %179, label %180, label %195
180: ; preds = %176
%181 = load float*, float** %11
%182 = load i32, i32* %4
%183 = load i32, i32* %6
%184 = mul nsw i32 %182, %183
%185 = load i32, i32* %5
%186 = mul nsw i32 %184, %185
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds float, float* %181, i64 %187
%189 = load float, float* %188
%190 = load float, float* %10
%191 = fadd float %190, %189
store float %191, float* %10
br label %192
192: ; preds = %180
%193 = load i32, i32* %4
%194 = add nsw i32 %193, 1
store i32 %194, i32* %4
br label %176
195: ; preds = %176
%196 = load float, float* %9
%197 = load float, float* %10
%198 = fsub float %196, %197
%199 = call float @llvm.fabs.f32(float %198)
%200 = load float, float* %13
%201 = fcmp ogt float %199, %200
br i1 %201, label %202, label %210
202: ; preds = %195
%203 = load i32, i32* %8
%204 = add nsw i32 %203, 1
store i32 %204, i32* %8
%205 = load float, float* %9
%206 = fpext float %205 to double
%207 = load float, float* %10
%208 = fpext float %207 to double
%209 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), double %206, double %208)
br label %210
210: ; preds = %202, %195
%211 = load double, double* %16
%212 = load double, double* %15
%213 = fsub double %211, %212
%214 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), double %213)
%215 = load i32, i32* %8
%216 = icmp eq i32 %215, 0
br i1 %216, label %217, label %219
217: ; preds = %210
%218 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %219
219: ; preds = %217, %210
%220 = load float*, float** %11
%221 = call i32 @free(float* %220)
%222 = load float*, float** %12
%223 = call i32 @free(float* %222)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, double }
@acc_device_default = global i32 0
@RAND_MAX = global i64 0
@.str = [37 x i8] c"gang + FAILED! sum=%f, known_sum=%f\0A\00"
@.str.1 = [37 x i8] c"gang + execution time is :%.2lf: ms\0A\00"
@str = [16 x i8] c"gang + SUCCESS!\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = tail call i64 @malloc(i32 268435456)
%4 = inttoptr i64 %3 to float*
%5 = tail call i64 @malloc(i32 268435456)
%6 = load i32, i32* @acc_device_default
%7 = tail call i32 @acc_init(i32 %6)
%8 = tail call i64 @time(i32 0)
%9 = trunc i64 %8 to i32
%10 = tail call i32 @srand(i32 %9)
br label %11
11: ; preds = %0, %44
%12 = phi i64 [ 0, %0 ], [ %45, %44 ]
%13 = shl nsw i64 %12, 6
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %26, %14 ]
%16 = tail call i64 (...) @rand()
%17 = sitofp i64 %16 to float
%18 = load i64, i64* @RAND_MAX
%19 = sitofp i64 %18 to float
%20 = fdiv float %17, %19
%21 = fpext float %20 to double
%22 = fadd double %21, 1.000000e-01
%23 = fptrunc double %22 to float
%24 = add nuw nsw i64 %13, %15
%25 = getelementptr inbounds float, float* %4, i64 %24
store float %23, float* %25
%26 = add nuw nsw i64 %15, 1
%27 = icmp eq i64 %26, 32
br i1 %27, label %28, label %14
28: ; preds = %14
%29 = or i64 %13, 32
br label %30
30: ; preds = %30, %28
%31 = phi i64 [ 0, %28 ], [ %42, %30 ]
%32 = tail call i64 (...) @rand()
%33 = sitofp i64 %32 to float
%34 = load i64, i64* @RAND_MAX
%35 = sitofp i64 %34 to float
%36 = fdiv float %33, %35
%37 = fpext float %36 to double
%38 = fadd double %37, 1.000000e-01
%39 = fptrunc double %38 to float
%40 = add nuw nsw i64 %29, %31
%41 = getelementptr inbounds float, float* %4, i64 %40
store float %39, float* %41
%42 = add nuw nsw i64 %31, 1
%43 = icmp eq i64 %42, 32
br i1 %43, label %44, label %30
44: ; preds = %30
%45 = add nuw nsw i64 %12, 1
%46 = icmp eq i64 %45, 1048576
br i1 %46, label %47, label %11
47: ; preds = %44
%48 = inttoptr i64 %5 to float*
%49 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%51 = load i32, i32* %50
%52 = mul nsw i32 %51, 1000
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%54 = load double, double* %53
%55 = fdiv double %54, 1.000000e+03
br label %56
56: ; preds = %47, %223
%57 = phi i64 [ 0, %47 ], [ %227, %223 ]
%58 = phi float [ 0.000000e+00, %47 ], [ %226, %223 ]
%59 = shl nuw nsw i64 %57, 6
%60 = or i64 %59, 32
%61 = shl nuw nsw i64 %57, 6
%62 = or i64 %61, 32
%63 = getelementptr float, float* %48, i64 %62
%64 = add nuw i64 %61, 64
%65 = getelementptr float, float* %48, i64 %64
%66 = getelementptr float, float* %4, i64 %62
%67 = getelementptr float, float* %4, i64 %64
%68 = shl nsw i64 %57, 6
%69 = getelementptr float, float* %4, i64 %60
%70 = getelementptr float, float* %4, i64 %59
%71 = getelementptr float, float* %48, i64 %60
%72 = getelementptr float, float* %48, i64 %59
%73 = icmp ult float* %72, %69
%74 = icmp ult float* %70, %71
%75 = and i1 %73, %74
br i1 %75, label %124, label %76
76: ; preds = %56
%77 = getelementptr inbounds float, float* %4, i64 %68
%78 = bitcast float* %77 to <4 x float>*
%79 = load <4 x float>, <4 x float>* %78
%80 = getelementptr inbounds float, float* %48, i64 %68
%81 = bitcast float* %80 to <4 x float>*
store <4 x float> %79, <4 x float>* %81
%82 = or i64 %68, 4
%83 = getelementptr inbounds float, float* %4, i64 %82
%84 = bitcast float* %83 to <4 x float>*
%85 = load <4 x float>, <4 x float>* %84
%86 = getelementptr inbounds float, float* %48, i64 %82
%87 = bitcast float* %86 to <4 x float>*
store <4 x float> %85, <4 x float>* %87
%88 = or i64 %68, 8
%89 = getelementptr inbounds float, float* %4, i64 %88
%90 = bitcast float* %89 to <4 x float>*
%91 = load <4 x float>, <4 x float>* %90
%92 = getelementptr inbounds float, float* %48, i64 %88
%93 = bitcast float* %92 to <4 x float>*
store <4 x float> %91, <4 x float>* %93
%94 = or i64 %68, 12
%95 = getelementptr inbounds float, float* %4, i64 %94
%96 = bitcast float* %95 to <4 x float>*
%97 = load <4 x float>, <4 x float>* %96
%98 = getelementptr inbounds float, float* %48, i64 %94
%99 = bitcast float* %98 to <4 x float>*
store <4 x float> %97, <4 x float>* %99
%100 = or i64 %68, 16
%101 = getelementptr inbounds float, float* %4, i64 %100
%102 = bitcast float* %101 to <4 x float>*
%103 = load <4 x float>, <4 x float>* %102
%104 = getelementptr inbounds float, float* %48, i64 %100
%105 = bitcast float* %104 to <4 x float>*
store <4 x float> %103, <4 x float>* %105
%106 = or i64 %68, 20
%107 = getelementptr inbounds float, float* %4, i64 %106
%108 = bitcast float* %107 to <4 x float>*
%109 = load <4 x float>, <4 x float>* %108
%110 = getelementptr inbounds float, float* %48, i64 %106
%111 = bitcast float* %110 to <4 x float>*
store <4 x float> %109, <4 x float>* %111
%112 = or i64 %68, 24
%113 = getelementptr inbounds float, float* %4, i64 %112
%114 = bitcast float* %113 to <4 x float>*
%115 = load <4 x float>, <4 x float>* %114
%116 = getelementptr inbounds float, float* %48, i64 %112
%117 = bitcast float* %116 to <4 x float>*
store <4 x float> %115, <4 x float>* %117
%118 = or i64 %68, 28
%119 = getelementptr inbounds float, float* %4, i64 %118
%120 = bitcast float* %119 to <4 x float>*
%121 = load <4 x float>, <4 x float>* %120
%122 = getelementptr inbounds float, float* %48, i64 %118
%123 = bitcast float* %122 to <4 x float>*
store <4 x float> %121, <4 x float>* %123
br label %147
124: ; preds = %56, %124
%125 = phi i64 [ %145, %124 ], [ 0, %56 ]
%126 = add nuw nsw i64 %68, %125
%127 = getelementptr inbounds float, float* %4, i64 %126
%128 = load float, float* %127
%129 = getelementptr inbounds float, float* %48, i64 %126
store float %128, float* %129
%130 = or i64 %125, 1
%131 = add nuw nsw i64 %68, %130
%132 = getelementptr inbounds float, float* %4, i64 %131
%133 = load float, float* %132
%134 = getelementptr inbounds float, float* %48, i64 %131
store float %133, float* %134
%135 = or i64 %125, 2
%136 = add nuw nsw i64 %68, %135
%137 = getelementptr inbounds float, float* %4, i64 %136
%138 = load float, float* %137
%139 = getelementptr inbounds float, float* %48, i64 %136
store float %138, float* %139
%140 = or i64 %125, 3
%141 = add nuw nsw i64 %68, %140
%142 = getelementptr inbounds float, float* %4, i64 %141
%143 = load float, float* %142
%144 = getelementptr inbounds float, float* %48, i64 %141
store float %143, float* %144
%145 = add nuw nsw i64 %125, 4
%146 = icmp eq i64 %145, 32
br i1 %146, label %147, label %124
147: ; preds = %124, %76
%148 = or i64 %68, 32
%149 = icmp ult float* %63, %67
%150 = icmp ult float* %66, %65
%151 = and i1 %149, %150
br i1 %151, label %200, label %152
152: ; preds = %147
%153 = getelementptr inbounds float, float* %4, i64 %148
%154 = bitcast float* %153 to <4 x float>*
%155 = load <4 x float>, <4 x float>* %154
%156 = getelementptr inbounds float, float* %48, i64 %148
%157 = bitcast float* %156 to <4 x float>*
store <4 x float> %155, <4 x float>* %157
%158 = or i64 %68, 36
%159 = getelementptr inbounds float, float* %4, i64 %158
%160 = bitcast float* %159 to <4 x float>*
%161 = load <4 x float>, <4 x float>* %160
%162 = getelementptr inbounds float, float* %48, i64 %158
%163 = bitcast float* %162 to <4 x float>*
store <4 x float> %161, <4 x float>* %163
%164 = or i64 %68, 40
%165 = getelementptr inbounds float, float* %4, i64 %164
%166 = bitcast float* %165 to <4 x float>*
%167 = load <4 x float>, <4 x float>* %166
%168 = getelementptr inbounds float, float* %48, i64 %164
%169 = bitcast float* %168 to <4 x float>*
store <4 x float> %167, <4 x float>* %169
%170 = or i64 %68, 44
%171 = getelementptr inbounds float, float* %4, i64 %170
%172 = bitcast float* %171 to <4 x float>*
%173 = load <4 x float>, <4 x float>* %172
%174 = getelementptr inbounds float, float* %48, i64 %170
%175 = bitcast float* %174 to <4 x float>*
store <4 x float> %173, <4 x float>* %175
%176 = or i64 %68, 48
%177 = getelementptr inbounds float, float* %4, i64 %176
%178 = bitcast float* %177 to <4 x float>*
%179 = load <4 x float>, <4 x float>* %178
%180 = getelementptr inbounds float, float* %48, i64 %176
%181 = bitcast float* %180 to <4 x float>*
store <4 x float> %179, <4 x float>* %181
%182 = or i64 %68, 52
%183 = getelementptr inbounds float, float* %4, i64 %182
%184 = bitcast float* %183 to <4 x float>*
%185 = load <4 x float>, <4 x float>* %184
%186 = getelementptr inbounds float, float* %48, i64 %182
%187 = bitcast float* %186 to <4 x float>*
store <4 x float> %185, <4 x float>* %187
%188 = or i64 %68, 56
%189 = getelementptr inbounds float, float* %4, i64 %188
%190 = bitcast float* %189 to <4 x float>*
%191 = load <4 x float>, <4 x float>* %190
%192 = getelementptr inbounds float, float* %48, i64 %188
%193 = bitcast float* %192 to <4 x float>*
store <4 x float> %191, <4 x float>* %193
%194 = or i64 %68, 60
%195 = getelementptr inbounds float, float* %4, i64 %194
%196 = bitcast float* %195 to <4 x float>*
%197 = load <4 x float>, <4 x float>* %196
%198 = getelementptr inbounds float, float* %48, i64 %194
%199 = bitcast float* %198 to <4 x float>*
store <4 x float> %197, <4 x float>* %199
br label %223
200: ; preds = %147, %200
%201 = phi i64 [ %221, %200 ], [ 0, %147 ]
%202 = add nuw nsw i64 %148, %201
%203 = getelementptr inbounds float, float* %4, i64 %202
%204 = load float, float* %203
%205 = getelementptr inbounds float, float* %48, i64 %202
store float %204, float* %205
%206 = or i64 %201, 1
%207 = add nuw nsw i64 %148, %206
%208 = getelementptr inbounds float, float* %4, i64 %207
%209 = load float, float* %208
%210 = getelementptr inbounds float, float* %48, i64 %207
store float %209, float* %210
%211 = or i64 %201, 2
%212 = add nuw nsw i64 %148, %211
%213 = getelementptr inbounds float, float* %4, i64 %212
%214 = load float, float* %213
%215 = getelementptr inbounds float, float* %48, i64 %212
store float %214, float* %215
%216 = or i64 %201, 3
%217 = add nuw nsw i64 %148, %216
%218 = getelementptr inbounds float, float* %4, i64 %217
%219 = load float, float* %218
%220 = getelementptr inbounds float, float* %48, i64 %217
store float %219, float* %220
%221 = add nuw nsw i64 %201, 4
%222 = icmp eq i64 %221, 32
br i1 %222, label %223, label %200
223: ; preds = %200, %152
%224 = getelementptr inbounds float, float* %48, i64 %68
%225 = load float, float* %224
%226 = fadd float %58, %225
%227 = add nuw nsw i64 %57, 1
%228 = icmp eq i64 %227, 1048576
br i1 %228, label %229, label %56
229: ; preds = %223
%230 = sitofp i32 %52 to double
%231 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%232 = load i32, i32* %50
%233 = mul nsw i32 %232, 1000
%234 = load double, double* %53
%235 = fdiv double %234, 1.000000e+03
br label %236
236: ; preds = %236, %229
%237 = phi i64 [ 0, %229 ], [ %258, %236 ]
%238 = phi float [ 0.000000e+00, %229 ], [ %257, %236 ]
%239 = shl nuw nsw i64 %237, 6
%240 = getelementptr inbounds float, float* %4, i64 %239
%241 = load float, float* %240
%242 = fadd float %238, %241
%243 = shl i64 %237, 6
%244 = or i64 %243, 64
%245 = getelementptr inbounds float, float* %4, i64 %244
%246 = load float, float* %245
%247 = fadd float %242, %246
%248 = shl i64 %237, 6
%249 = or i64 %248, 128
%250 = getelementptr inbounds float, float* %4, i64 %249
%251 = load float, float* %250
%252 = fadd float %247, %251
%253 = shl i64 %237, 6
%254 = or i64 %253, 192
%255 = getelementptr inbounds float, float* %4, i64 %254
%256 = load float, float* %255
%257 = fadd float %252, %256
%258 = add nuw nsw i64 %237, 4
%259 = icmp eq i64 %258, 1048576
br i1 %259, label %260, label %236
260: ; preds = %236
%261 = fadd double %55, %230
%262 = sitofp i32 %233 to double
%263 = fadd double %235, %262
%264 = fsub float %226, %257
%265 = tail call float @llvm.fabs.f32(float %264)
%266 = fcmp ogt float %265, 0x3E112E0BE0000000
br i1 %266, label %267, label %273
267: ; preds = %260
%268 = fpext float %226 to double
%269 = fpext float %257 to double
%270 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), double %268, double %269)
%271 = fsub double %263, %261
%272 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), double %271)
br label %277
273: ; preds = %260
%274 = fsub double %263, %261
%275 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), double %274)
%276 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %277
277: ; preds = %267, %273
%278 = tail call i32 @free(float* %4)
%279 = tail call i32 @free(float* %48)
ret i32 0
}