#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(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stdout;
int main(void) {
  int i, p, q;
  int index1, index2;
  int *in = (int *)malloc(1024 * sizeof(int));
  int B[20][10];
  for (i = 0; i < 1024; i++) {
    in[i] = (1024 - i);
  }
  for (p = 0; p < 20; p++) {
    for (q = 0; q < 10; q++) {
      B[p][q] = 0;
    }
  }
#pragma scop
  {
#pragma species kernel in[0 : SIZE - 1] | element ^ B[0 : 19, 0 : 9] |         \
                                                      full->B[0 : 19,          \
                                                              0 : 9] | shared
    for (i = 0; i < 1024; i++) {
      index1 = in[i] % 20;
      index2 = in[i] % 10;
      B[index1][index2] = B[index1][index2] + 1;
    }
#pragma species endkernel example03_k1
  }
#pragma endscop
  free(in);
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jge    1185 <main+0x55>
mov    $0x400,%edx
sub    -0x8(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1157 <main+0x27>
movl   $0x0,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jge    11e5 <main+0xb5>
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    11d2 <main+0xa2>
movslq -0xc(%rbp),%rcx
lea    -0x340(%rbp),%rax
imul   $0x28,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119d <main+0x6d>
jmp    11d7 <main+0xa7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118c <main+0x5c>
movl   $0x0,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jge    1268 <main+0x138>
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x14,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
movslq -0x14(%rbp),%rcx
lea    -0x340(%rbp),%rax
imul   $0x28,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
movslq -0x14(%rbp),%rcx
lea    -0x340(%rbp),%rax
imul   $0x28,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ec <main+0xbc>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %eax,%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x328,%rsp
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movdqa 0xea1(%rip),%xmm0
mov    $0x1c,%eax
movdqa 0xea3(%rip),%xmm8
movdqa 0xeaa(%rip),%xmm9
movdqa 0xeb1(%rip),%xmm10
movdqa 0xeb8(%rip),%xmm11
movdqa 0xec0(%rip),%xmm5
movdqa 0xec8(%rip),%xmm6
movdqa 0xed0(%rip),%xmm7
movdqa 0xed8(%rip),%xmm1
movdqa 0xee0(%rip),%xmm2
movdqa %xmm8,%xmm3
psubd  %xmm0,%xmm3
movdqa %xmm9,%xmm4
psubd  %xmm0,%xmm4
movdqu %xmm3,-0x70(%r14,%rax,4)
movdqu %xmm4,-0x60(%r14,%rax,4)
movdqa %xmm10,%xmm3
psubd  %xmm0,%xmm3
movdqa %xmm11,%xmm4
psubd  %xmm0,%xmm4
movdqu %xmm3,-0x50(%r14,%rax,4)
movdqu %xmm4,-0x40(%r14,%rax,4)
movdqa %xmm5,%xmm3
psubd  %xmm0,%xmm3
movdqa %xmm6,%xmm4
psubd  %xmm0,%xmm4
movdqu %xmm3,-0x30(%r14,%rax,4)
movdqu %xmm4,-0x20(%r14,%rax,4)
movdqa %xmm7,%xmm3
psubd  %xmm0,%xmm3
movdqa %xmm1,%xmm4
psubd  %xmm0,%xmm4
movdqu %xmm3,-0x10(%r14,%rax,4)
movdqu %xmm4,(%r14,%rax,4)
paddd  %xmm2,%xmm0
add    $0x20,%rax
cmp    $0x41c,%rax
jne    11b0 <main+0x70>
mov    %rsp,%rdi
xor    %ebx,%ebx
mov    $0x320,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movslq (%r14,%rbx,4),%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
sar    $0x23,%rdx
mov    %rcx,%rsi
shr    $0x3f,%rsi
add    %esi,%edx
shl    $0x2,%edx
lea    (%rdx,%rdx,4),%edx
mov    %eax,%edi
sub    %edx,%edi
sar    $0x22,%rcx
add    %esi,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
movslq %edi,%rcx
cltq
lea    (%rcx,%rcx,4),%rcx
lea    (%rsp,%rcx,8),%rcx
addl   $0x1,(%rcx,%rax,4)
add    $0x1,%rbx
cmp    $0x400,%rbx
jne    1250 <main+0x110>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
xor    %eax,%eax
add    $0x328,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32 0
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 [20 x [10 x i32]]
store i32 0, i32* %1
%9 = call i64 @malloc(i32 4096)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %7
store i32 0, i32* %2
br label %11
11: ; preds = %21, %0
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 1024
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i32, i32* %2
%16 = sub nsw i32 1024, %15
%17 = load i32*, i32** %7
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 %16, i32* %20
br label %21
21: ; preds = %14
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %11
24: ; preds = %11
store i32 0, i32* %3
br label %25
25: ; preds = %43, %24
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 20
br i1 %27, label %28, label %46
28: ; preds = %25
store i32 0, i32* %4
br label %29
29: ; preds = %39, %28
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 10
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [20 x [10 x i32]], [20 x [10 x i32]]* %8, i64 0, i64 %34
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %35, i64 0, i64 %37
store i32 0, i32* %38
br label %39
39: ; preds = %32
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %29
42: ; preds = %29
br label %43
43: ; preds = %42
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %25
46: ; preds = %25
store i32 0, i32* %2
br label %47
47: ; preds = %77, %46
%48 = load i32, i32* %2
%49 = icmp slt i32 %48, 1024
br i1 %49, label %50, label %80
50: ; preds = %47
%51 = load i32*, i32** %7
%52 = load i32, i32* %2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = srem i32 %55, 20
store i32 %56, i32* %5
%57 = load i32*, i32** %7
%58 = load i32, i32* %2
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = srem i32 %61, 10
store i32 %62, i32* %6
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [20 x [10 x i32]], [20 x [10 x i32]]* %8, i64 0, i64 %64
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [10 x i32], [10 x i32]* %65, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = add nsw i32 %69, 1
%71 = load i32, i32* %5
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [20 x [10 x i32]], [20 x [10 x i32]]* %8, i64 0, i64 %72
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [10 x i32], [10 x i32]* %73, i64 0, i64 %75
store i32 %70, i32* %76
br label %77
77: ; preds = %50
%78 = load i32, i32* %2
%79 = add nsw i32 %78, 1
store i32 %79, i32* %2
br label %47
80: ; preds = %47
%81 = load i32*, i32** %7
%82 = call i32 @free(i32* %81)
%83 = load i32, i32* @stdout
%84 = call i32 @fflush(i32 %83)
ret i32 0
}

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