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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x100000,-0x8(%rbp)
jge    1188 <main+0x58>
mov    -0x8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1157 <main+0x27>
movl   $0x0,-0x8(%rbp)
cmpl   $0x100,-0x8(%rbp)
jge    11b9 <main+0x89>
movslq -0x8(%rbp),%rax
movl   $0x0,-0x420(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118f <main+0x5f>
movl   $0x0,-0x8(%rbp)
cmpl   $0x100000,-0x8(%rbp)
jge    11fe <main+0xce>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
mov    -0x420(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x420(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c0 <main+0x90>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    $0x100000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movdqa 0xea3(%rip),%xmm2
mov    $0x70,%eax
movdqa 0xea5(%rip),%xmm8
movdqa 0xeac(%rip),%xmm9
movdqa 0xeb4(%rip),%xmm3
movdqa 0xebc(%rip),%xmm4
movdqa 0xec4(%rip),%xmm5
movdqa 0xecc(%rip),%xmm6
movdqa 0xed4(%rip),%xmm7
movdqa 0xedc(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqu %xmm2,-0x70(%rbx,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm8,%xmm0
movdqu %xmm0,-0x60(%rbx,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm9,%xmm0
movdqu %xmm0,-0x50(%rbx,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm3,%xmm0
movdqu %xmm0,-0x40(%rbx,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm4,%xmm0
movdqu %xmm0,-0x30(%rbx,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm5,%xmm0
movdqu %xmm0,-0x20(%rbx,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm6,%xmm0
movdqu %xmm0,-0x10(%rbx,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm7,%xmm0
movdqu %xmm0,(%rbx,%rax,1)
pxor   %xmm1,%xmm2
sub    $0xffffffffffffff80,%rax
cmp    $0x100070,%rax
jne    11b0 <main+0x70>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0x3,%eax
nopl   (%rax)
movzbl -0x3(%rbx,%rax,1),%ecx
addl   $0x1,(%rsp,%rcx,4)
movzbl -0x2(%rbx,%rax,1),%ecx
addl   $0x1,(%rsp,%rcx,4)
movzbl -0x1(%rbx,%rax,1),%ecx
addl   $0x1,(%rsp,%rcx,4)
movzbl (%rbx,%rax,1),%ecx
addl   $0x1,(%rsp,%rcx,4)
add    $0x4,%rax
cmp    $0x100003,%rax
jne    1240 <main+0x100>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8*
%5 = alloca [256 x i32]
store i32 0, i32* %1
%6 = call i64 @malloc(i32 1048576)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %4
store i32 0, i32* %2
br label %8
8: ; preds = %19, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 1048576
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i32, i32* %2
%13 = srem i32 %12, 256
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %4
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 %14, i8* %18
br label %19
19: ; preds = %11
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %8
22: ; preds = %8
store i32 0, i32* %2
br label %23
23: ; preds = %30, %22
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, 256
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 %28
store i32 0, i32* %29
br label %30
30: ; preds = %26
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
br label %23
33: ; preds = %23
store i32 0, i32* %2
br label %34
34: ; preds = %48, %33
%35 = load i32, i32* %2
%36 = icmp slt i32 %35, 1048576
br i1 %36, label %37, label %51
37: ; preds = %34
%38 = load i8*, i8** %4
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
store i8 %42, i8* %3
%43 = load i8, i8* %3
%44 = zext i8 %43 to i64
%45 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = add nsw i32 %46, 1
store i32 %47, i32* %45
br label %48
48: ; preds = %37
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
store i32 %50, i32* %2
br label %34
51: ; preds = %34
%52 = load i8*, i8** %4
%53 = call i32 @free(i8* %52)
%54 = load i32, i32* @stdout
%55 = call i32 @fflush(i32 %54)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @main() {
%1 = alloca [256 x i32]
%2 = bitcast [256 x i32]* %1 to i8*
%3 = tail call i64 @malloc(i32 1048576)
%4 = inttoptr i64 %3 to i8*
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %38, %5 ]
%7 = phi <16 x i8> [ <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, %0 ], [ %39, %5 ]
%8 = getelementptr inbounds i8, i8* %4, i64 %6
%9 = bitcast i8* %8 to <16 x i8>*
store <16 x i8> %7, <16 x i8>* %9
%10 = or i64 %6, 16
%11 = add <16 x i8> %7, <i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16>
%12 = getelementptr inbounds i8, i8* %4, i64 %10
%13 = bitcast i8* %12 to <16 x i8>*
store <16 x i8> %11, <16 x i8>* %13
%14 = or i64 %6, 32
%15 = add <16 x i8> %7, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%16 = getelementptr inbounds i8, i8* %4, i64 %14
%17 = bitcast i8* %16 to <16 x i8>*
store <16 x i8> %15, <16 x i8>* %17
%18 = or i64 %6, 48
%19 = add <16 x i8> %7, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%20 = getelementptr inbounds i8, i8* %4, i64 %18
%21 = bitcast i8* %20 to <16 x i8>*
store <16 x i8> %19, <16 x i8>* %21
%22 = or i64 %6, 64
%23 = add <16 x i8> %7, <i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64>
%24 = getelementptr inbounds i8, i8* %4, i64 %22
%25 = bitcast i8* %24 to <16 x i8>*
store <16 x i8> %23, <16 x i8>* %25
%26 = or i64 %6, 80
%27 = add <16 x i8> %7, <i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80>
%28 = getelementptr inbounds i8, i8* %4, i64 %26
%29 = bitcast i8* %28 to <16 x i8>*
store <16 x i8> %27, <16 x i8>* %29
%30 = or i64 %6, 96
%31 = add <16 x i8> %7, <i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96>
%32 = getelementptr inbounds i8, i8* %4, i64 %30
%33 = bitcast i8* %32 to <16 x i8>*
store <16 x i8> %31, <16 x i8>* %33
%34 = or i64 %6, 112
%35 = add <16 x i8> %7, <i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112>
%36 = getelementptr inbounds i8, i8* %4, i64 %34
%37 = bitcast i8* %36 to <16 x i8>*
store <16 x i8> %35, <16 x i8>* %37
%38 = add nuw nsw i64 %6, 128
%39 = xor <16 x i8> %7, <i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128>
%40 = icmp eq i64 %38, 1048576
br i1 %40, label %41, label %5
41: ; preds = %5
br label %42
42: ; preds = %42, %41
%43 = phi i64 [ 0, %41 ], [ %71, %42 ]
%44 = getelementptr inbounds i8, i8* %4, i64 %43
%45 = load i8, i8* %44
%46 = zext i8 %45 to i64
%47 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = add nsw i32 %48, 1
store i32 %49, i32* %47
%50 = or i64 %43, 1
%51 = getelementptr inbounds i8, i8* %4, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i64
%54 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = add nsw i32 %55, 1
store i32 %56, i32* %54
%57 = or i64 %43, 2
%58 = getelementptr inbounds i8, i8* %4, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i64
%61 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = add nsw i32 %62, 1
store i32 %63, i32* %61
%64 = or i64 %43, 3
%65 = getelementptr inbounds i8, i8* %4, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %66 to i64
%68 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = add nsw i32 %69, 1
store i32 %70, i32* %68
%71 = add nuw nsw i64 %43, 4
%72 = icmp eq i64 %71, 1048576
br i1 %72, label %73, label %42
73: ; preds = %42
%74 = tail call i32 @free(i8* %4)
%75 = load i32, i32* @stdout
%76 = tail call i32 @fflush(i32 %75)
ret i32 0
}