#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 sum = 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 for shared(n, a) private(thread) reduction(+ : sum)
  for (i = 0; i < n; i++) {
    sum += a[i];
  }
  end = omp_get_wtime();
  time = end - start;
  printf("Total Sum at End:  %d\nTime:  %0.9lf\n", sum, 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)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11ca <main+0x8a>
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    119f <main+0x5f>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movss  %xmm0,-0x2c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1208 <main+0xc8>
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    11dd <main+0x9d>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
subss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x24(%rbp),%esi
movss  -0x34(%rbp),%xmm0
lea    0xdce(%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 = [37 x i8] c"Total Sum at End: %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 float
%12 = alloca float
%13 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32* @malloc(i32 100)
store i32* %14, i32** %6
store i32 0, i32* %7
store i32 25, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store float 0.000000e+00, float* %11
store float 0.000000e+00, float* %12
store float 0.000000e+00, float* %13
store i32 0, i32* %7
br label %15
15: ; preds = %26, %2
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
%22 = load i32*, i32** %6
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
br label %26
26: ; preds = %19
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %15
29: ; preds = %15
%30 = call float (...) @omp_get_wtime()
store float %30, float* %11
store i32 0, i32* %7
br label %31
31: ; preds = %43, %29
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = load i32*, i32** %6
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %9
%42 = add nsw i32 %41, %40
store i32 %42, i32* %9
br label %43
43: ; preds = %35
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %31
46: ; preds = %31
%47 = call float (...) @omp_get_wtime()
store float %47, float* %12
%48 = load float, float* %12
%49 = load float, float* %11
%50 = fsub float %48, %49
store float %50, float* %13
%51 = load i32, i32* %9
%52 = load float, float* %13
%53 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %51, float %52)
%54 = load i32*, i32** %6
%55 = call i32 @free(i32* %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Total Sum at End: %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 ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %27, float %29)
%31 = tail call i32 @free(i32* %3)
ret i32 0
}