#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 atoi(char *);
scalar_t__ malloc(int);
double omp_get_wtime();
int /*<<< orphan*/ ppsum(int *, int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc < 2)
    printf("Error. Provide size.\n");
  int n = atoi(argv[1]);
  int *A = (int *)malloc(n * sizeof(int));
  for (int i = 0, j = 0; i < n; i++, j++)
    A[i] = j & 0xFF;
  int *p = (int *)malloc(n * sizeof(int));
  printf("%d threads\n", 2);
  printf("%d task levels\n", 1);
  int nit = 1;
  double ctime1 = omp_get_wtime();
#pragma omp parallel num_threads(MAX_THREADS)
#pragma omp single
  while (nit--)
    ppsum(A, p, n, 1);
  double ctime2 = omp_get_wtime();
  printf("%f seconds elapsed.\n", ctime2 - ctime1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117e <main+0x2e>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e6 <main+0x96>
mov    -0x28(%rbp),%edx
and    $0xff,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11af <main+0x5f>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
lea    0xe16(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0f(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x34(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x34(%rbp)
cmp    $0x0,%eax
je     1260 <main+0x110>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x1,%ecx
call   1060 <ppsum@plt>
jmp    1232 <main+0xe2>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
lea    0xdb5(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     117c <main+0x1c>
lea    0xf1a(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    12af <main+0x14f>
mov    %r14d,%eax
cmp    $0x8,%r14d
jae    11b3 <main+0x53>
xor    %ecx,%ecx
jmp    12a0 <main+0x140>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
lea    -0x8(%rcx),%rdx
mov    %rdx,%rsi
shr    $0x3,%rsi
add    $0x1,%rsi
test   %rdx,%rdx
je     1325 <main+0x1c5>
mov    %rsi,%rdi
and    $0xfffffffffffffffe,%rdi
movdqa 0xe21(%rip),%xmm0
xor    %edx,%edx
movdqa 0xe27(%rip),%xmm1
movdqa 0xe2f(%rip),%xmm2
movdqa 0xe37(%rip),%xmm3
movdqa 0xe3f(%rip),%xmm4
movdqa 0xe47(%rip),%xmm5
nopl   0x0(%rax)
movdqa %xmm0,%xmm6
paddd  %xmm1,%xmm6
movdqa %xmm0,%xmm7
pand   %xmm2,%xmm7
pand   %xmm2,%xmm6
movdqu %xmm7,(%rbx,%rdx,4)
movdqu %xmm6,0x10(%rbx,%rdx,4)
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
movdqa %xmm0,%xmm7
paddd  %xmm4,%xmm7
pand   %xmm2,%xmm6
pand   %xmm2,%xmm7
movdqu %xmm6,0x20(%rbx,%rdx,4)
movdqu %xmm7,0x30(%rbx,%rdx,4)
add    $0x10,%rdx
paddd  %xmm5,%xmm0
add    $0xfffffffffffffffe,%rdi
jne    1210 <main+0xb0>
test   $0x1,%sil
je     128e <main+0x12e>
movdqa 0xda1(%rip),%xmm1
paddd  %xmm0,%xmm1
movdqa 0xda5(%rip),%xmm2
pand   %xmm2,%xmm0
pand   %xmm2,%xmm1
movdqu %xmm0,(%rbx,%rdx,4)
movdqu %xmm1,0x10(%rbx,%rdx,4)
cmp    %rax,%rcx
je     12af <main+0x14f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl %cl,%edx
mov    %edx,(%rbx,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    12a0 <main+0x140>
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0xda0(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd99(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movq   %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
mov    $0x1,%ecx
call   1070 <ppsum@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
lea    0xd69(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
movdqa 0xcd3(%rip),%xmm0
xor    %edx,%edx
test   $0x1,%sil
jne    1267 <main+0x107>
jmp    128e <main+0x12e>

LLVM IR (-O0):
@.str = [22 x i8] c"Error. Provide size.\0A\00"
@.str.1 = [12 x i8] c"%d threads\0A\00"
@.str.2 = [16 x i8] c"%d task levels\0A\00"
@.str.3 = [21 x i8] c"%f seconds elapsed.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 4
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i32*
store i32* %28, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %29
29: ; preds = %40, %18
%30 = load i32, i32* %8
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i32, i32* %9
%35 = and i32 %34, 255
%36 = load i32*, i32** %7
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
store i32 %35, i32* %39
br label %40
40: ; preds = %33
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %29
45: ; preds = %29
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = mul i64 %47, 4
%49 = trunc i64 %48 to i32
%50 = call i64 @malloc(i32 %49)
%51 = inttoptr i64 %50 to i32*
store i32* %51, i32** %10
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 2)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i32 1, i32* %11
%54 = call double (...) @omp_get_wtime()
store double %54, double* %12
br label %55
55: ; preds = %59, %45
%56 = load i32, i32* %11
%57 = add nsw i32 %56, -1
store i32 %57, i32* %11
%58 = icmp ne i32 %56, 0
br i1 %58, label %59, label %64
59: ; preds = %55
%60 = load i32*, i32** %7
%61 = load i32*, i32** %10
%62 = load i32, i32* %6
%63 = call i32 @ppsum(i32* %60, i32* %61, i32 %62, i32 1)
br label %55
64: ; preds = %55
%65 = call double (...) @omp_get_wtime()
store double %65, double* %13
%66 = load double, double* %13
%67 = load double, double* %12
%68 = fsub double %66, %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), double %68)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"%d threads\0A\00"
@.str.2 = [16 x i8] c"%d task levels\0A\00"
@.str.3 = [21 x i8] c"%f seconds elapsed.\0A\00"
@str = [21 x i8] c"Error. Provide size.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = shl i32 %9, 2
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = icmp sgt i32 %9, 0
br i1 %13, label %14, label %66
14: ; preds = %6
%15 = zext i32 %9 to i64
%16 = icmp ult i32 %9, 8
br i1 %16, label %64, label %17
17: ; preds = %14
%18 = and i64 %15, 4294967288
%19 = add nsw i64 %18, -8
%20 = lshr exact i64 %19, 3
%21 = add nuw nsw i64 %20, 1
%22 = and i64 %21, 1
%23 = icmp eq i64 %19, 0
br i1 %23, label %50, label %24
24: ; preds = %17
%25 = and i64 %21, 4611686018427387902
br label %26
26: ; preds = %26, %24
%27 = phi i64 [ 0, %24 ], [ %46, %26 ]
%28 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %24 ], [ %47, %26 ]
%29 = phi i64 [ 0, %24 ], [ %48, %26 ]
%30 = add <4 x i32> %28, <i32 4, i32 4, i32 4, i32 4>
%31 = and <4 x i32> %28, <i32 255, i32 255, i32 255, i32 255>
%32 = and <4 x i32> %30, <i32 255, i32 255, i32 255, i32 255>
%33 = getelementptr inbounds i32, i32* %12, i64 %27
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> %31, <4 x i32>* %34
%35 = getelementptr inbounds i32, i32* %33, i64 4
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> %32, <4 x i32>* %36
%37 = or i64 %27, 8
%38 = add <4 x i32> %28, <i32 8, i32 8, i32 8, i32 8>
%39 = add <4 x i32> %28, <i32 12, i32 12, i32 12, i32 12>
%40 = and <4 x i32> %38, <i32 255, i32 255, i32 255, i32 255>
%41 = and <4 x i32> %39, <i32 255, i32 255, i32 255, i32 255>
%42 = getelementptr inbounds i32, i32* %12, i64 %37
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %43
%44 = getelementptr inbounds i32, i32* %42, i64 4
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> %41, <4 x i32>* %45
%46 = add nuw i64 %27, 16
%47 = add <4 x i32> %28, <i32 16, i32 16, i32 16, i32 16>
%48 = add i64 %29, 2
%49 = icmp eq i64 %48, %25
br i1 %49, label %50, label %26
50: ; preds = %26, %17
%51 = phi i64 [ 0, %17 ], [ %46, %26 ]
%52 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %17 ], [ %47, %26 ]
%53 = icmp eq i64 %22, 0
br i1 %53, label %62, label %54
54: ; preds = %50
%55 = add <4 x i32> %52, <i32 4, i32 4, i32 4, i32 4>
%56 = and <4 x i32> %52, <i32 255, i32 255, i32 255, i32 255>
%57 = and <4 x i32> %55, <i32 255, i32 255, i32 255, i32 255>
%58 = getelementptr inbounds i32, i32* %12, i64 %51
%59 = bitcast i32* %58 to <4 x i32>*
store <4 x i32> %56, <4 x i32>* %59
%60 = getelementptr inbounds i32, i32* %58, i64 4
%61 = bitcast i32* %60 to <4 x i32>*
store <4 x i32> %57, <4 x i32>* %61
br label %62
62: ; preds = %50, %54
%63 = icmp eq i64 %18, %15
br i1 %63, label %66, label %64
64: ; preds = %14, %62
%65 = phi i64 [ 0, %14 ], [ %18, %62 ]
br label %76
66: ; preds = %76, %62, %6
%67 = tail call i64 @malloc(i32 %10)
%68 = inttoptr i64 %67 to i32*
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 2)
%70 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 1)
%71 = tail call double (...) @omp_get_wtime()
%72 = tail call i32 @ppsum(i32* %12, i32* %68, i32 %9, i32 1)
%73 = tail call double (...) @omp_get_wtime()
%74 = fsub double %73, %71
%75 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), double %74)
ret i32 0
76: ; preds = %64, %76
%77 = phi i64 [ %81, %76 ], [ %65, %64 ]
%78 = trunc i64 %77 to i32
%79 = and i32 %78, 255
%80 = getelementptr inbounds i32, i32* %12, i64 %77
store i32 %79, i32* %80
%81 = add nuw nsw i64 %77, 1
%82 = icmp eq i64 %81, %15
br i1 %82, label %66, label %76
}