#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int EXIT_SUCCESS;
scalar_t__ clock();
int /*<<< orphan*/ free(double *);
double *malloc(int);
int /*<<< orphan*/ printf(char *, double);
double sum(double *, int);
int main(int argc, char *argv[]) {
  int N, i;
  double *list, res, kgo;
  clock_t t_start, t_end;
  N = 100000000;
  list = malloc(N * sizeof(double));
  for (i = 0; i < N; i++) {
    list[i] = (double)i;
  }
  t_start = clock();
  res = sum(list, N);
  t_end = clock();
  kgo = 0.5 * N * (N - 1);
  printf("error=%g\n", res - kgo);
  printf("Took %g s\n", (double)(t_end - t_start) / CLOCKS_PER_SEC);
  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   $0x5f5e100,-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 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <sum@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x40(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe19(%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    0xdf9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x40(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dc0(%rip),%rax
divsd  (%rax),%xmm0
lea    0xddf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x2faf0800,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movdqa 0xe92(%rip),%xmm0
mov    $0x6,%eax
movdqa 0xe95(%rip),%xmm1
movdqa 0xe9d(%rip),%xmm2
movdqa 0xea5(%rip),%xmm3
movdqa 0xead(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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    $0x5f5e106,%rax
jne    11a0 <main+0x50>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x5f5e100,%esi
call   1060 <sum@plt>
movq   %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r15
movsd  0x8(%rsp),%xmm0
addsd  0xe30(%rip),%xmm0
lea    0xe31(%rip),%rdi
call   1050 <printf@plt>
sub    %r14,%r15
xorps  %xmm0,%xmm0
cvtsi2sd %r15,%xmm0
mov    0x2daa(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"error=%g\0A\00"
@.str.1 = [11 x i8] c"Took %g s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+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 i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100000000, 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 i64 (...) @clock()
store i64 %33, i64* %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 i64 (...) @clock()
store i64 %37, i64* %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 i64, i64* %12
%50 = load i64, i64* %11
%51 = sub nsw i64 %49, %50
%52 = sitofp i64 %51 to double
%53 = load double, double* @CLOCKS_PER_SEC
%54 = fdiv double %52, %53
%55 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %54)
%56 = load double*, double** %8
%57 = call i32 @free(double* %56)
%58 = load i32, i32* @EXIT_SUCCESS
ret i32 %58
}

LLVM IR (-O2):
@.str = [10 x i8] c"error=%g\0A\00"
@.str.1 = [11 x i8] c"Took %g s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double* @malloc(i32 800000000)
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, 100000000
br i1 %25, label %26, label %4
26: ; preds = %4
%27 = tail call i64 (...) @clock()
%28 = tail call double @sum(double* %3, i32 100000000)
%29 = tail call i64 (...) @clock()
%30 = fadd double %28, 0xC331C37934E58F80
%31 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %30)
%32 = sub nsw i64 %29, %27
%33 = sitofp i64 %32 to double
%34 = load double, double* @CLOCKS_PER_SEC
%35 = fdiv double %33, %34
%36 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %35)
%37 = tail call i32 @free(double* %3)
%38 = load i32, i32* @EXIT_SUCCESS
ret i32 %38
}