#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 *malloc(int);
int /*<<< orphan*/ printf(char *, long, double);
int /*<<< orphan*/ reduce_parallel(int *, int, long *);
int /*<<< orphan*/ reduce_sequential(int *, int, long *);
double wtime();
int main(int argc, const char *argv[]) {
  long sum;
  int n;
  n = 300000000;
  int *v = malloc(sizeof(int) * n);
  if (v == NULL)
    return 1;
  for (int i = 0; i < n; i++) {
    v[i] = i;
  }
  double t = wtime();
  reduce_sequential(v, n, &sum);
  t = wtime() - t;
  printf("sum sequential: %ld, Execution time: %.6f\n", sum, t);
  t = wtime();
  reduce_parallel(v, n, &sum);
  t = wtime() - t;
  printf("sum parallel: %ld, Execution time: %.6f\n", sum, t);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x11e1a300,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1197 <main+0x47>
movl   $0x1,-0x4(%rbp)
jmp    1251 <main+0x101>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c6 <main+0x76>
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119e <main+0x4e>
mov    $0x0,%al
call   1040 <wtime@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1050 <reduce_sequential@plt>
mov    $0x0,%al
call   1040 <wtime@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
movsd  -0x38(%rbp),%xmm0
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <wtime@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1070 <reduce_parallel@plt>
mov    $0x0,%al
call   1040 <wtime@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
movsd  -0x38(%rbp),%xmm0
lea    0xde6(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x47868c00,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     12ea <main+0x19a>
mov    %rax,%rbx
movdqa 0xe8a(%rip),%xmm0
mov    $0x24,%eax
movdqa 0xe8c(%rip),%xmm8
movdqa 0xe93(%rip),%xmm9
movdqa 0xe9a(%rip),%xmm10
movdqa 0xea1(%rip),%xmm11
movdqa 0xea8(%rip),%xmm12
movdqa 0xeb0(%rip),%xmm6
movdqa 0xeb8(%rip),%xmm7
movdqa 0xec0(%rip),%xmm1
movdqa 0xec8(%rip),%xmm2
movdqa 0xed0(%rip),%xmm3
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqu %xmm0,-0x90(%rbx,%rax,4)
ff ff
movdqu %xmm4,-0x80(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqu %xmm4,-0x70(%rbx,%rax,4)
movdqu %xmm5,-0x60(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqu %xmm4,-0x50(%rbx,%rax,4)
movdqu %xmm5,-0x40(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqu %xmm4,-0x30(%rbx,%rax,4)
movdqu %xmm5,-0x20(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqu %xmm4,-0x10(%rbx,%rax,4)
movdqu %xmm5,(%rbx,%rax,4)
paddd  %xmm3,%xmm0
add    $0x28,%rax
cmp    $0x11e1a324,%rax
jne    11d0 <main+0x80>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <wtime@plt>
movq   %xmm0,(%rsp)
lea    0x8(%rsp),%r14
mov    %rbx,%rdi
mov    $0x11e1a300,%esi
mov    %r14,%rdx
call   1050 <reduce_sequential@plt>
xor    %eax,%eax
call   1040 <wtime@plt>
subsd  (%rsp),%xmm0
mov    0x8(%rsp),%rsi
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <wtime@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
mov    $0x11e1a300,%esi
mov    %r14,%rdx
call   1070 <reduce_parallel@plt>
xor    %eax,%eax
call   1040 <wtime@plt>
subsd  (%rsp),%xmm0
mov    0x8(%rsp),%rsi
lea    0xdf8(%rip),%rdi
call   1030 <printf@plt>
jmp    12ef <main+0x19f>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"sum sequential: %ld, Execution time: %.6f\0A\00"
@.str.1 = [41 x i8] c"sum parallel: %ld, Execution time: %.6f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 300000000, i32* %7
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = mul i64 4, %12
%14 = trunc i64 %13 to i32
%15 = call i32* @malloc(i32 %14)
store i32* %15, i32** %8
%16 = load i32*, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 1, i32* %3
br label %54
19: ; preds = %2
store i32 0, i32* %9
br label %20
20: ; preds = %30, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i32, i32* %9
%26 = load i32*, i32** %8
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
store i32 %25, i32* %29
br label %30
30: ; preds = %24
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %20
33: ; preds = %20
%34 = call double (...) @wtime()
store double %34, double* %10
%35 = load i32*, i32** %8
%36 = load i32, i32* %7
%37 = call i32 @reduce_sequential(i32* %35, i32 %36, i64* %6)
%38 = call double (...) @wtime()
%39 = load double, double* %10
%40 = fsub double %38, %39
store double %40, double* %10
%41 = load i64, i64* %6
%42 = load double, double* %10
%43 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i64 %41, double %42)
%44 = call double (...) @wtime()
store double %44, double* %10
%45 = load i32*, i32** %8
%46 = load i32, i32* %7
%47 = call i32 @reduce_parallel(i32* %45, i32 %46, i64* %6)
%48 = call double (...) @wtime()
%49 = load double, double* %10
%50 = fsub double %48, %49
store double %50, double* %10
%51 = load i64, i64* %6
%52 = load double, double* %10
%53 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %51, double %52)
store i32 0, i32* %3
br label %54
54: ; preds = %33, %18
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [43 x i8] c"sum sequential: %ld, Execution time: %.6f\0A\00"
@.str.1 = [41 x i8] c"sum parallel: %ld, Execution time: %.6f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = tail call i32* @malloc(i32 1200000000)
%6 = icmp eq i32* %5, null
br i1 %6, label %59, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %43, %7 ], [ 0, %2 ]
%9 = phi <4 x i32> [ %44, %7 ], [ <i32 0, i32 1, i32 2, i32 3>, %2 ]
%10 = add <4 x i32> %9, <i32 4, i32 4, i32 4, i32 4>
%11 = getelementptr inbounds i32, i32* %5, i64 %8
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %9, <4 x i32>* %12
%13 = getelementptr inbounds i32, i32* %11, i64 4
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> %10, <4 x i32>* %14
%15 = add nuw nsw i64 %8, 8
%16 = add <4 x i32> %9, <i32 8, i32 8, i32 8, i32 8>
%17 = add <4 x i32> %9, <i32 12, i32 12, i32 12, i32 12>
%18 = getelementptr inbounds i32, i32* %5, i64 %15
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %16, <4 x i32>* %19
%20 = getelementptr inbounds i32, i32* %18, i64 4
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> %17, <4 x i32>* %21
%22 = add nuw nsw i64 %8, 16
%23 = add <4 x i32> %9, <i32 16, i32 16, i32 16, i32 16>
%24 = add <4 x i32> %9, <i32 20, i32 20, i32 20, i32 20>
%25 = getelementptr inbounds i32, i32* %5, i64 %22
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %23, <4 x i32>* %26
%27 = getelementptr inbounds i32, i32* %25, i64 4
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> %24, <4 x i32>* %28
%29 = add nuw nsw i64 %8, 24
%30 = add <4 x i32> %9, <i32 24, i32 24, i32 24, i32 24>
%31 = add <4 x i32> %9, <i32 28, i32 28, i32 28, i32 28>
%32 = getelementptr inbounds i32, i32* %5, i64 %29
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> %30, <4 x i32>* %33
%34 = getelementptr inbounds i32, i32* %32, i64 4
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> %31, <4 x i32>* %35
%36 = add nuw nsw i64 %8, 32
%37 = add <4 x i32> %9, <i32 32, i32 32, i32 32, i32 32>
%38 = add <4 x i32> %9, <i32 36, i32 36, i32 36, i32 36>
%39 = getelementptr inbounds i32, i32* %5, i64 %36
%40 = bitcast i32* %39 to <4 x i32>*
store <4 x i32> %37, <4 x i32>* %40
%41 = getelementptr inbounds i32, i32* %39, i64 4
%42 = bitcast i32* %41 to <4 x i32>*
store <4 x i32> %38, <4 x i32>* %42
%43 = add nuw nsw i64 %8, 40
%44 = add <4 x i32> %9, <i32 40, i32 40, i32 40, i32 40>
%45 = icmp eq i64 %43, 300000000
br i1 %45, label %46, label %7
46: ; preds = %7
%47 = tail call double (...) @wtime()
%48 = call i32 @reduce_sequential(i32* %5, i32 300000000, i64* %3)
%49 = call double (...) @wtime()
%50 = fsub double %49, %47
%51 = load i64, i64* %3
%52 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i64 %51, double %50)
%53 = call double (...) @wtime()
%54 = call i32 @reduce_parallel(i32* %5, i32 300000000, i64* %3)
%55 = call double (...) @wtime()
%56 = fsub double %55, %53
%57 = load i64, i64* %3
%58 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %57, double %56)
br label %59
59: ; preds = %2, %46
%60 = phi i32 [ 0, %46 ], [ 1, %2 ]
ret i32 %60
}