#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 EXIT_SUCCESS;
int /*<<< orphan*/ free(double *);
double *malloc(int);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double);
double sum(double *, int);
int main(int argc, char *argv[]) {
  int N, i;
  double *list, res, kgo;
  double t_start, t_end;
  N = 400000000;
  list = malloc(N * sizeof(double));
  for (i = 0; i < N; i++) {
    list[i] = (double)i;
  }
  t_start = omp_get_wtime();
#pragma omp parallel
  {
#pragma omp single nowait
    res = sum(list, N);
  }
  t_end = omp_get_wtime();
  kgo = 0.5 * N * (N - 1);
  printf("error=%g\n", res - kgo);
  printf("Took %g s\n", t_end - t_start);
  free(list);
  return EXIT_SUCCESS;
}


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   $0x17d78400,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b3 <main+0x63>
cvtsi2sdl -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1187 <main+0x37>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <sum@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe17(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
lea    0xdeb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    $0xbebc2000,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movdqa 0xe96(%rip),%xmm0
mov    $0x6,%eax
movdqa 0xe99(%rip),%xmm1
movdqa 0xea1(%rip),%xmm2
movdqa 0xea9(%rip),%xmm3
movdqa 0xeb1(%rip),%xmm4
nop
movdqa %xmm0,%xmm5
cvtdq2pd %xmm0,%xmm6
paddd  %xmm1,%xmm5
cvtdq2pd %xmm5,%xmm5
movups %xmm6,-0x30(%rbx,%rax,8)
movups %xmm5,-0x20(%rbx,%rax,8)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
cvtdq2pd %xmm5,%xmm5
paddd  %xmm3,%xmm6
cvtdq2pd %xmm6,%xmm6
movups %xmm5,-0x10(%rbx,%rax,8)
movups %xmm6,(%rbx,%rax,8)
paddd  %xmm4,%xmm0
add    $0x8,%rax
cmp    $0x17d78406,%rax
jne    1190 <main+0x40>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movq   %xmm0,0x18(%rsp)
mov    %rbx,%rdi
mov    $0x17d78400,%esi
call   1060 <sum@plt>
movq   %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movq   %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xe3a(%rip),%xmm0
lea    0xe3b(%rip),%rdi
call   1050 <printf@plt>
movsd  0x10(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
lea    0xe2d(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"error=%g\0A\00"
@.str.1 = [11 x i8] c"Took %g s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double* @malloc(i32 -1094967296)
br label %4
4: ; preds = %4, %2
%5 = phi i64 [ 0, %2 ], [ %23, %4 ]
%6 = phi <2 x i32> [ <i32 0, i32 1>, %2 ], [ %24, %4 ]
%7 = add <2 x i32> %6, <i32 2, i32 2>
%8 = sitofp <2 x i32> %6 to <2 x double>
%9 = sitofp <2 x i32> %7 to <2 x double>
%10 = getelementptr inbounds double, double* %3, i64 %5
%11 = bitcast double* %10 to <2 x double>*
store <2 x double> %8, <2 x double>* %11
%12 = getelementptr inbounds double, double* %10, i64 2
%13 = bitcast double* %12 to <2 x double>*
store <2 x double> %9, <2 x double>* %13
%14 = or i64 %5, 4
%15 = add <2 x i32> %6, <i32 4, i32 4>
%16 = add <2 x i32> %6, <i32 6, i32 6>
%17 = sitofp <2 x i32> %15 to <2 x double>
%18 = sitofp <2 x i32> %16 to <2 x double>
%19 = getelementptr inbounds double, double* %3, i64 %14
%20 = bitcast double* %19 to <2 x double>*
store <2 x double> %17, <2 x double>* %20
%21 = getelementptr inbounds double, double* %19, i64 2
%22 = bitcast double* %21 to <2 x double>*
store <2 x double> %18, <2 x double>* %22
%23 = add nuw nsw i64 %5, 8
%24 = add <2 x i32> %6, <i32 8, i32 8>
%25 = icmp eq i64 %23, 400000000
br i1 %25, label %26, label %4
26: ; preds = %4
%27 = tail call double (...) @omp_get_wtime()
%28 = tail call double @sum(double* %3, i32 400000000)
%29 = tail call double (...) @omp_get_wtime()
%30 = fadd double %28, 0xC371C3793721C3E0
%31 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %30)
%32 = fsub double %29, %27
%33 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %32)
%34 = tail call i32 @free(double* %3)
%35 = load i32, i32* @EXIT_SUCCESS
ret i32 %35
}