#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*/ fprintf(int /*<<< orphan*/, char *, long);
int /*<<< orphan*/ stderr;
void moments_type1d(long N, double *a_x, double *mom) {
  long i;
  double S[5] = {0};
  for (i = 0; i < N; ++i) {
    double x;
    double x2;
    x = a_x[i];
    x2 = x * x;
    S[0] += 1;
    S[1] += x;
    S[2] += x2;
    S[3] += x * x2;
    S[4] += x2 * x2;
  }
  fprintf(stderr, "processed %ld numbers\n", N);
  for (i = 0; i < 5; ++i) {
    mom[i] = S[i] / N;
  }
}


x86 assembly (clang, -O0):
<moments_type1d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11f4 <moments_type1d+0xd4>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xe7d(%rip),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x58(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x60(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114c <moments_type1d+0x2c>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe00(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x5,-0x20(%rbp)
jge    1252 <moments_type1d+0x132>
mov    -0x20(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm0
cvtsi2sdq -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1215 <moments_type1d+0xf5>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<moments_type1d>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
jle    1144 <moments_type1d+0x34>
cmp    $0x1,%rbx
jne    1155 <moments_type1d+0x45>
xorpd  %xmm6,%xmm6
xorpd  %xmm0,%xmm0
xor    %eax,%eax
xorpd  %xmm7,%xmm7
test   $0x1,%bl
jne    11f9 <moments_type1d+0xe9>
jmp    1237 <moments_type1d+0x127>
xorpd  %xmm6,%xmm6
xorpd  %xmm7,%xmm7
xorpd  %xmm1,%xmm1
jmp    1237 <moments_type1d+0x127>
mov    %rbx,%rcx
and    $0xfffffffffffffffe,%rcx
xorpd  %xmm6,%xmm6
xorpd  %xmm0,%xmm0
xor    %eax,%eax
movsd  0xe92(%rip),%xmm1
xorpd  %xmm7,%xmm7
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%rsi,%rax,8),%xmm2
movsd  0x8(%rsi,%rax,8),%xmm3
movapd %xmm2,%xmm4
mulsd  %xmm2,%xmm4
movapd %xmm1,%xmm5
unpcklpd %xmm2,%xmm5
addpd  %xmm6,%xmm5
addsd  %xmm4,%xmm0
movapd %xmm4,%xmm6
unpcklpd %xmm2,%xmm6
unpcklpd %xmm4,%xmm4
mulpd  %xmm6,%xmm4
addpd  %xmm7,%xmm4
movapd %xmm3,%xmm7
mulsd  %xmm3,%xmm7
movapd %xmm1,%xmm6
unpcklpd %xmm3,%xmm6
addpd  %xmm5,%xmm6
addsd  %xmm7,%xmm0
movapd %xmm7,%xmm2
unpcklpd %xmm3,%xmm2
unpcklpd %xmm7,%xmm7
mulpd  %xmm2,%xmm7
addpd  %xmm4,%xmm7
add    $0x2,%rax
cmp    %rax,%rcx
jne    1180 <moments_type1d+0x70>
movapd %xmm7,%xmm1
movsd  %xmm0,%xmm1
test   $0x1,%bl
je     1237 <moments_type1d+0x127>
movsd  (%rsi,%rax,8),%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movapd 0xe02(%rip),%xmm3
unpcklpd %xmm1,%xmm3
addpd  %xmm3,%xmm6
addsd  %xmm2,%xmm0
movapd %xmm2,%xmm3
unpcklpd %xmm1,%xmm3
unpcklpd %xmm2,%xmm2
mulpd  %xmm3,%xmm2
addpd  %xmm2,%xmm7
shufpd $0x2,%xmm7,%xmm0
movapd %xmm0,%xmm1
movapd %xmm7,(%rsp)
movapd %xmm6,0x10(%rsp)
movapd %xmm1,0x20(%rsp)
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movapd (%rsp),%xmm1
divsd  %xmm0,%xmm1
unpcklpd %xmm0,%xmm0
movapd 0x10(%rsp),%xmm2
divpd  %xmm0,%xmm2
movupd %xmm2,(%r14)
movapd 0x20(%rsp),%xmm2
divpd  %xmm0,%xmm2
movupd %xmm2,0x10(%r14)
movsd  %xmm1,0x20(%r14)
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"processed %ld numbers\0A\00"
define void @moments_type1d(i64 %0, double* %1, double* %2) {
%4 = alloca i64
%5 = alloca double*
%6 = alloca double*
%7 = alloca i64
%8 = alloca [5 x double]
%9 = alloca double
%10 = alloca double
store i64 %0, i64* %4
store double* %1, double** %5
store double* %2, double** %6
%11 = bitcast [5 x double]* %8 to i8*
store i64 0, i64* %7
br label %12
12: ; preds = %45, %3
%13 = load i64, i64* %7
%14 = load i64, i64* %4
%15 = icmp slt i64 %13, %14
br i1 %15, label %16, label %48
16: ; preds = %12
%17 = load double*, double** %5
%18 = load i64, i64* %7
%19 = getelementptr inbounds double, double* %17, i64 %18
%20 = load double, double* %19
store double %20, double* %9
%21 = load double, double* %9
%22 = load double, double* %9
%23 = fmul double %21, %22
store double %23, double* %10
%24 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 0
%25 = load double, double* %24
%26 = fadd double %25, 1.000000e+00
store double %26, double* %24
%27 = load double, double* %9
%28 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 1
%29 = load double, double* %28
%30 = fadd double %29, %27
store double %30, double* %28
%31 = load double, double* %10
%32 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 2
%33 = load double, double* %32
%34 = fadd double %33, %31
store double %34, double* %32
%35 = load double, double* %9
%36 = load double, double* %10
%37 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 3
%38 = load double, double* %37
%39 = call double @llvm.fmuladd.f64(double %35, double %36, double %38)
store double %39, double* %37
%40 = load double, double* %10
%41 = load double, double* %10
%42 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 4
%43 = load double, double* %42
%44 = call double @llvm.fmuladd.f64(double %40, double %41, double %43)
store double %44, double* %42
br label %45
45: ; preds = %16
%46 = load i64, i64* %7
%47 = add nsw i64 %46, 1
store i64 %47, i64* %7
br label %12
48: ; preds = %12
%49 = load i32, i32* @stderr
%50 = load i64, i64* %4
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %50)
store i64 0, i64* %7
br label %52
52: ; preds = %65, %48
%53 = load i64, i64* %7
%54 = icmp slt i64 %53, 5
br i1 %54, label %55, label %68
55: ; preds = %52
%56 = load i64, i64* %7
%57 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 %56
%58 = load double, double* %57
%59 = load i64, i64* %4
%60 = sitofp i64 %59 to double
%61 = fdiv double %58, %60
%62 = load double*, double** %6
%63 = load i64, i64* %7
%64 = getelementptr inbounds double, double* %62, i64 %63
store double %61, double* %64
br label %65
65: ; preds = %55
%66 = load i64, i64* %7
%67 = add nsw i64 %66, 1
store i64 %67, i64* %7
br label %52
68: ; preds = %52
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"processed %ld numbers\0A\00"
define void @moments_type1d(i64 %0, double* nocapture %1, double* nocapture writeonly %2) {
%4 = icmp sgt i64 %0, 0
br i1 %4, label %5, label %65
5: ; preds = %3
%6 = and i64 %0, 1
%7 = icmp eq i64 %0, 1
br i1 %7, label %43, label %8
8: ; preds = %5
%9 = and i64 %0, -2
br label %10
10: ; preds = %10, %8
%11 = phi double [ 0.000000e+00, %8 ], [ %32, %10 ]
%12 = phi i64 [ 0, %8 ], [ %37, %10 ]
%13 = phi <2 x double> [ zeroinitializer, %8 ], [ %31, %10 ]
%14 = phi <2 x double> [ zeroinitializer, %8 ], [ %36, %10 ]
%15 = phi i64 [ 0, %8 ], [ %38, %10 ]
%16 = getelementptr inbounds double, double* %1, i64 %12
%17 = load double, double* %16
%18 = fmul double %17, %17
%19 = insertelement <2 x double> <double 1.000000e+00, double poison>, double %17, i64 1
%20 = fadd <2 x double> %19, %13
%21 = fadd double %18, %11
%22 = insertelement <2 x double> poison, double %18, i64 0
%23 = insertelement <2 x double> %22, double %17, i64 1
%24 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
%25 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %23, <2 x double> %24, <2 x double> %14)
%26 = or i64 %12, 1
%27 = getelementptr inbounds double, double* %1, i64 %26
%28 = load double, double* %27
%29 = fmul double %28, %28
%30 = insertelement <2 x double> <double 1.000000e+00, double poison>, double %28, i64 1
%31 = fadd <2 x double> %30, %20
%32 = fadd double %29, %21
%33 = insertelement <2 x double> poison, double %29, i64 0
%34 = insertelement <2 x double> %33, double %28, i64 1
%35 = shufflevector <2 x double> %33, <2 x double> poison, <2 x i32> zeroinitializer
%36 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %34, <2 x double> %35, <2 x double> %25)
%37 = add nuw nsw i64 %12, 2
%38 = add i64 %15, 2
%39 = icmp eq i64 %38, %9
br i1 %39, label %40, label %10
40: ; preds = %10
%41 = extractelement <2 x double> %36, i64 0
%42 = insertelement <2 x double> %36, double %32, i64 0
br label %43
43: ; preds = %40, %5
%44 = phi <2 x double> [ undef, %5 ], [ %31, %40 ]
%45 = phi <2 x double> [ undef, %5 ], [ %42, %40 ]
%46 = phi double [ undef, %5 ], [ %41, %40 ]
%47 = phi double [ 0.000000e+00, %5 ], [ %32, %40 ]
%48 = phi i64 [ 0, %5 ], [ %37, %40 ]
%49 = phi <2 x double> [ zeroinitializer, %5 ], [ %31, %40 ]
%50 = phi <2 x double> [ zeroinitializer, %5 ], [ %36, %40 ]
%51 = icmp eq i64 %6, 0
br i1 %51, label %65, label %52
52: ; preds = %43
%53 = getelementptr inbounds double, double* %1, i64 %48
%54 = load double, double* %53
%55 = fmul double %54, %54
%56 = insertelement <2 x double> <double 1.000000e+00, double poison>, double %54, i64 1
%57 = fadd <2 x double> %56, %49
%58 = fadd double %55, %47
%59 = insertelement <2 x double> poison, double %55, i64 0
%60 = insertelement <2 x double> %59, double %54, i64 1
%61 = shufflevector <2 x double> %59, <2 x double> poison, <2 x i32> zeroinitializer
%62 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %60, <2 x double> %61, <2 x double> %50)
%63 = insertelement <2 x double> %62, double %58, i64 0
%64 = extractelement <2 x double> %62, i64 0
br label %65
65: ; preds = %52, %43, %3
%66 = phi double [ 0.000000e+00, %3 ], [ %46, %43 ], [ %64, %52 ]
%67 = phi <2 x double> [ zeroinitializer, %3 ], [ %44, %43 ], [ %57, %52 ]
%68 = phi <2 x double> [ zeroinitializer, %3 ], [ %45, %43 ], [ %63, %52 ]
%69 = load i32, i32* @stderr
%70 = tail call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %0)
%71 = sitofp i64 %0 to double
%72 = insertelement <2 x double> poison, double %71, i64 0
%73 = shufflevector <2 x double> %72, <2 x double> poison, <2 x i32> zeroinitializer
%74 = fdiv <2 x double> %67, %73
%75 = bitcast double* %2 to <2 x double>*
store <2 x double> %74, <2 x double>* %75
%76 = getelementptr inbounds double, double* %2, i64 2
%77 = fdiv <2 x double> %68, %73
%78 = bitcast double* %76 to <2 x double>*
store <2 x double> %77, <2 x double>* %78
%79 = fdiv double %66, %71
%80 = getelementptr inbounds double, double* %2, i64 4
store double %79, double* %80
ret void
}