#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*/ fflush(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ stdout;
int main(void) {
  int i;
  int *A = (int *)malloc(512 * 1024 * sizeof(int));
  int B[1];
  for (i = 0; i < 512 * 1024; i++) {
    A[i] = 1;
  }
  B[0] = 0;
#pragma scop
  {
#pragma species kernel B[0 : 0] | full ^ A[0 : SIZE - 1] | element->B[0 : 0] | \
                                                                      shared
    for (i = 0; i < 512 * 1024; i++) {
      B[0] = B[0] + A[i];
    }
#pragma species endkernel example01_k1
  }
#pragma endscop
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x200000,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x80000,-0x8(%rbp)
jge    116e <main+0x4e>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1144 <main+0x24>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x80000,-0x8(%rbp)
jge    11a8 <main+0x88>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x8(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117c <main+0x5c>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x200000,%edi
call   1030 <malloc@plt>
xor    %ecx,%ecx
movaps 0xecc(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movups %xmm0,(%rax,%rcx,4)
movups %xmm0,0x10(%rax,%rcx,4)
movups %xmm0,0x20(%rax,%rcx,4)
movups %xmm0,0x30(%rax,%rcx,4)
movups %xmm0,0x40(%rax,%rcx,4)
movups %xmm0,0x50(%rax,%rcx,4)
movups %xmm0,0x60(%rax,%rcx,4)
movups %xmm0,0x70(%rax,%rcx,4)
movups %xmm0,0x80(%rax,%rcx,4)
movups %xmm0,0x90(%rax,%rcx,4)
movups %xmm0,0xa0(%rax,%rcx,4)
movups %xmm0,0xb0(%rax,%rcx,4)
movups %xmm0,0xc0(%rax,%rcx,4)
movups %xmm0,0xd0(%rax,%rcx,4)
movups %xmm0,0xe0(%rax,%rcx,4)
movups %xmm0,0xf0(%rax,%rcx,4)
add    $0x40,%rcx
cmp    $0x80000,%rcx
jne    1140 <main+0x20>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [1 x i32]
store i32 0, i32* %1
%5 = call i64 @malloc(i32 2097152)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %3
store i32 0, i32* %2
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 524288
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = load i32*, i32** %3
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
store i32 1, i32* %14
br label %15
15: ; preds = %10
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %7
18: ; preds = %7
%19 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
store i32 0, i32* %19
store i32 0, i32* %2
br label %20
20: ; preds = %33, %18
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 524288
br i1 %22, label %23, label %36
23: ; preds = %20
%24 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
%25 = load i32, i32* %24
%26 = load i32*, i32** %3
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = add nsw i32 %25, %30
%32 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
store i32 %31, i32* %32
br label %33
33: ; preds = %23
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %20
36: ; preds = %20
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
ret i32 0
}

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