#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*/ free(int *);
int *malloc(int);
float omp_get_wtime();
int /*<<< orphan*/ printf(char *, int, float);
int main(int argc, char **argv) {
  int *a = malloc(25 * sizeof(int));
  int i = 0;
  int n = 25;
  int localSum = 0;
  int totalSum = 0;
  int thread = 0;
  float start = 0.0;
  float end = 0.0;
  float time = 0.0;
  for (i = 0; i < n; i++) {
    a[i] = i + 1;
  }
  start = omp_get_wtime();
#pragma omp parallel shared(n, a, totalSum) private(thread, localSum)
  {
    localSum = 0;
#pragma omp for
    for (i = 0; i < n; i++) {
      localSum += a[i];
    }
#pragma omp atomic
    totalSum += localSum;
  }
  end = omp_get_wtime();
  time = end - start;
  printf("Total sum at end is %d.\nTime:  %0.9lf\n", totalSum, time);
  free(a);
  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)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x19,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d1 <main+0x91>
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a6 <main+0x66>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movss  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1216 <main+0xd6>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11eb <main+0xab>
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
subss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%esi
movss  -0x38(%rbp),%xmm0
lea    0xdb7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movaps 0xea9(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xeaf(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xeb4(%rip),%xmm0
movups %xmm0,0x20(%rax)
movaps 0xeb9(%rip),%xmm0
movups %xmm0,0x30(%rax)
movaps 0xebe(%rip),%xmm0
movups %xmm0,0x40(%rax)
movaps 0xec3(%rip),%xmm0
movups %xmm0,0x50(%rax)
movl   $0x19,0x60(%rax)
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movss  %xmm0,0x4(%rsp)
movdqu 0x44(%rbx),%xmm0
movdqu 0x54(%rbx),%xmm1
movdqu 0x4(%rbx),%xmm2
movdqu 0x14(%rbx),%xmm3
paddd  %xmm2,%xmm3
movdqu 0x24(%rbx),%xmm2
paddd  %xmm0,%xmm2
movdqu 0x34(%rbx),%xmm0
paddd  %xmm1,%xmm0
paddd  %xmm2,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
pshufd $0xee,%xmm3,%xmm0
paddd  %xmm3,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%ebp
add    %eax,%ebp
add    (%rbx),%ebp
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subss  0x4(%rsp),%xmm0
lea    0xe49(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Total sum at end is %d.\0ATime: %0.9lf\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 float
%13 = alloca float
%14 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32* @malloc(i32 100)
store i32* %15, i32** %6
store i32 0, i32* %7
store i32 25, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store float 0.000000e+00, float* %12
store float 0.000000e+00, float* %13
store float 0.000000e+00, float* %14
store i32 0, i32* %7
br label %16
16: ; preds = %27, %2
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
%23 = load i32*, i32** %6
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
br label %27
27: ; preds = %20
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %16
30: ; preds = %16
%31 = call float (...) @omp_get_wtime()
store float %31, float* %12
store i32 0, i32* %9
store i32 0, i32* %7
br label %32
32: ; preds = %44, %30
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %47
36: ; preds = %32
%37 = load i32*, i32** %6
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, %41
store i32 %43, i32* %9
br label %44
44: ; preds = %36
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %32
47: ; preds = %32
%48 = load i32, i32* %9
%49 = load i32, i32* %10
%50 = add nsw i32 %49, %48
store i32 %50, i32* %10
%51 = call float (...) @omp_get_wtime()
store float %51, float* %13
%52 = load float, float* %13
%53 = load float, float* %12
%54 = fsub float %52, %53
store float %54, float* %14
%55 = load i32, i32* %10
%56 = load float, float* %14
%57 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %55, float %56)
%58 = load i32*, i32** %6
%59 = call i32 @free(i32* %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"Total sum at end is %d.\0ATime: %0.9lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 100)
%4 = getelementptr inbounds i32, i32* %3, i64 1
%5 = bitcast i32* %3 to <4 x i32>*
store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, <4 x i32>* %5
%6 = getelementptr inbounds i32, i32* %3, i64 4
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 5, i32 6, i32 7, i32 8>, <4 x i32>* %7
%8 = getelementptr inbounds i32, i32* %3, i64 8
%9 = getelementptr inbounds i32, i32* %3, i64 9
%10 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 9, i32 10, i32 11, i32 12>, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %3, i64 12
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> <i32 13, i32 14, i32 15, i32 16>, <4 x i32>* %12
%13 = getelementptr inbounds i32, i32* %3, i64 16
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> <i32 17, i32 18, i32 19, i32 20>, <4 x i32>* %14
%15 = getelementptr inbounds i32, i32* %3, i64 20
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> <i32 21, i32 22, i32 23, i32 24>, <4 x i32>* %16
%17 = getelementptr inbounds i32, i32* %3, i64 24
store i32 25, i32* %17
%18 = tail call float (...) @omp_get_wtime()
%19 = load i32, i32* %3
%20 = bitcast i32* %4 to <8 x i32>*
%21 = load <8 x i32>, <8 x i32>* %20
%22 = bitcast i32* %9 to <16 x i32>*
%23 = load <16 x i32>, <16 x i32>* %22
%24 = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %23)
%25 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %21)
%26 = add nsw i32 %24, %25
%27 = add nsw i32 %26, %19
%28 = tail call float (...) @omp_get_wtime()
%29 = fsub float %28, %18
%30 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %27, float %29)
%31 = tail call i32 @free(i32* %3)
ret i32 0
}