#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 */
scalar_t__ malloc(int);
int main() {
  int *array;
  int i, j;
  array = (int *)malloc(1000 * sizeof(int));
  if (array == NULL) {
    return 1;
  }
  for (i = 0; i < 1000; i++) {
    array[i] = i;
  }
#pragma acc data copyin(array [0:1000])
  {
    int n;
    for (n = 100; n < 10000; n += 100) {
      int sum = 0;
#pragma acc parallel loop collapse(2) firstprivate(n) reduction(+ : sum)
      for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
          sum += array[(i + j) % 1000];
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xfa0,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <main+0x34>
movl   $0x1,-0x4(%rbp)
jmp    1216 <main+0x106>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    1174 <main+0x64>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <main+0x3b>
movl   $0x64,-0x1c(%rbp)
cmpl   $0x2710,-0x1c(%rbp)
jge    120f <main+0xff>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11fc <main+0xec>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e9 <main+0xd9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,4),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a9 <main+0x99>
jmp    11ee <main+0xde>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1196 <main+0x86>
jmp    1201 <main+0xf1>
mov    -0x1c(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x1c(%rbp)
jmp    117b <main+0x6b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0xfa0,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1235 <main+0x125>
mov    %rax,%rcx
movdqa 0xed1(%rip),%xmm0
xor    %eax,%eax
movdqa 0xed6(%rip),%xmm8
movdqa 0xedd(%rip),%xmm9
movdqa 0xee4(%rip),%xmm10
movdqa 0xeeb(%rip),%xmm11
movdqa 0xef2(%rip),%xmm12
movdqa 0xefa(%rip),%xmm6
movdqa 0xf02(%rip),%xmm7
movdqa 0xf0a(%rip),%xmm1
movdqa 0xf12(%rip),%xmm2
movdqa 0xf1a(%rip),%xmm3
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqu %xmm0,(%rcx,%rdx,4)
movdqu %xmm4,0x10(%rcx,%rdx,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqu %xmm4,0x20(%rcx,%rdx,4)
movdqu %xmm5,0x30(%rcx,%rdx,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqu %xmm4,0x40(%rcx,%rdx,4)
movdqu %xmm5,0x50(%rcx,%rdx,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqu %xmm4,0x60(%rcx,%rdx,4)
movdqu %xmm5,0x70(%rcx,%rdx,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqu %xmm4,0x80(%rcx,%rdx,4)
movdqu %xmm5,0x90(%rcx,%rdx,4)
add    $0x28,%rdx
paddd  %xmm3,%xmm0
cmp    $0x3e8,%rdx
jne    1190 <main+0x80>
pop    %rcx
ret
mov    $0x1,%eax
pop    %rcx
ret

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

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