#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 */
scalar_t__ isfinite(double);
double sqrt(double);
void estimate_mu_and_std(const double *series, size_t n_values, double *mu,
                         double *std) {
  double mean = 0;
  double s2 = 0;
  size_t n = 0;
  for (size_t i = 0; i < n_values; ++i) {
    double value = series[i];
    if (isfinite(value)) {
      ++n;
      s2 += ((value - mean) * (value - mean) * (n - 1)) / n;
      mean += (value - mean) / n;
    }
  }
  if (n == 0) {
    *mu = 0;
    *std = 0;
  } else {
    *mu = mean;
    *std = sqrt(s2 / n);
  }
}


x86 assembly (clang, -O0):
<estimate_mu_and_std>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1254 <estimate_mu_and_std+0x134>
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <isfinite@plt>
cmp    $0x0,%rax
je     123e <estimate_mu_and_std+0x11e>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm1
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
movq   %rcx,%xmm0
movaps 0xe3f(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xe43(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm4
unpckhpd %xmm0,%xmm0
addsd  %xmm4,%xmm0
mulsd  %xmm0,%xmm1
movq   %rax,%xmm0
punpckldq %xmm3,%xmm0
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm4
unpckhpd %xmm0,%xmm0
addsd  %xmm4,%xmm0
divsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
movq   -0x38(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1243 <estimate_mu_and_std+0x123>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1158 <estimate_mu_and_std+0x38>
cmpq   $0x0,-0x38(%rbp)
jne    127a <estimate_mu_and_std+0x15a>
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    12c4 <estimate_mu_and_std+0x1a4>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
movaps 0xd6d(%rip),%xmm2
movq   -0x38(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xd6c(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<estimate_mu_and_std>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
test   %rsi,%rsi
je     1236 <estimate_mu_and_std+0x116>
mov    %rsi,%r13
mov    %rdi,%r12
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    11d2 <estimate_mu_and_std+0xb2>
movapd (%rsp),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm6
subsd  %xmm1,%xmm6
movapd %xmm6,%xmm3
mulsd  %xmm6,%xmm3
movq   %rbx,%xmm1
add    $0x1,%rbx
movdqa 0xe80(%rip),%xmm4
punpckldq %xmm4,%xmm1
movapd 0xe84(%rip),%xmm5
subpd  %xmm5,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm3,%xmm2
movq   %rbx,%xmm3
punpckldq %xmm4,%xmm3
subpd  %xmm5,%xmm3
unpcklpd %xmm6,%xmm2
movapd %xmm3,%xmm1
unpcklpd %xmm3,%xmm1
unpckhpd %xmm3,%xmm3
addpd  %xmm1,%xmm3
divpd  %xmm3,%xmm2
addpd  %xmm2,%xmm0
add    $0x1,%rbp
cmp    %rbp,%r13
je     11f7 <estimate_mu_and_std+0xd7>
movapd %xmm0,(%rsp)
movsd  (%r12,%rbp,8),%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <isfinite@plt>
test   %rax,%rax
jne    1150 <estimate_mu_and_std+0x30>
movapd (%rsp),%xmm0
jmp    11c9 <estimate_mu_and_std+0xa9>
test   %rbx,%rbx
je     1236 <estimate_mu_and_std+0x116>
movhpd %xmm0,(%r15)
movq   %rbx,%xmm2
punpckldq 0xdf2(%rip),%xmm2
subpd  0xdfa(%rip),%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1243 <estimate_mu_and_std+0x123>
sqrtsd %xmm0,%xmm0
jmp    1248 <estimate_mu_and_std+0x128>
movq   $0x0,(%r15)
xorpd  %xmm0,%xmm0
jmp    1248 <estimate_mu_and_std+0x128>
call   1040 <sqrt@plt>
movsd  %xmm0,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @estimate_mu_and_std(double* %0, i64 %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca i64
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca i64
%12 = alloca i64
%13 = alloca double
store double* %0, double** %5
store i64 %1, i64* %6
store double* %2, double** %7
store double* %3, double** %8
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store i64 0, i64* %11
store i64 0, i64* %12
br label %14
14: ; preds = %54, %4
%15 = load i64, i64* %12
%16 = load i64, i64* %6
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %57
18: ; preds = %14
%19 = load double*, double** %5
%20 = load i64, i64* %12
%21 = getelementptr inbounds double, double* %19, i64 %20
%22 = load double, double* %21
store double %22, double* %13
%23 = load double, double* %13
%24 = call i64 @isfinite(double %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %53
26: ; preds = %18
%27 = load i64, i64* %11
%28 = add i64 %27, 1
store i64 %28, i64* %11
%29 = load double, double* %13
%30 = load double, double* %9
%31 = fsub double %29, %30
%32 = load double, double* %13
%33 = load double, double* %9
%34 = fsub double %32, %33
%35 = fmul double %31, %34
%36 = load i64, i64* %11
%37 = sub i64 %36, 1
%38 = uitofp i64 %37 to double
%39 = fmul double %35, %38
%40 = load i64, i64* %11
%41 = uitofp i64 %40 to double
%42 = fdiv double %39, %41
%43 = load double, double* %10
%44 = fadd double %43, %42
store double %44, double* %10
%45 = load double, double* %13
%46 = load double, double* %9
%47 = fsub double %45, %46
%48 = load i64, i64* %11
%49 = uitofp i64 %48 to double
%50 = fdiv double %47, %49
%51 = load double, double* %9
%52 = fadd double %51, %50
store double %52, double* %9
br label %53
53: ; preds = %26, %18
br label %54
54: ; preds = %53
%55 = load i64, i64* %12
%56 = add i64 %55, 1
store i64 %56, i64* %12
br label %14
57: ; preds = %14
%58 = load i64, i64* %11
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load double*, double** %7
store double 0.000000e+00, double* %61
%62 = load double*, double** %8
store double 0.000000e+00, double* %62
br label %72
63: ; preds = %57
%64 = load double, double* %9
%65 = load double*, double** %7
store double %64, double* %65
%66 = load double, double* %10
%67 = load i64, i64* %11
%68 = uitofp i64 %67 to double
%69 = fdiv double %66, %68
%70 = call double @sqrt(double %69)
%71 = load double*, double** %8
store double %70, double* %71
br label %72
72: ; preds = %63, %60
ret void
}

LLVM IR (-O2):
define void @estimate_mu_and_std(double* nocapture %0, i64 %1, double* nocapture writeonly %2, double* nocapture writeonly %3) {
%5 = icmp eq i64 %1, 0
br i1 %5, label %35, label %8
6: ; preds = %30
%7 = icmp eq i64 %31, 0
br i1 %7, label %35, label %36
8: ; preds = %4, %30
%9 = phi i64 [ %33, %30 ], [ 0, %4 ]
%10 = phi i64 [ %31, %30 ], [ 0, %4 ]
%11 = phi <2 x double> [ %32, %30 ], [ zeroinitializer, %4 ]
%12 = getelementptr inbounds double, double* %0, i64 %9
%13 = load double, double* %12
%14 = tail call i64 @isfinite(double %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %8
%17 = add i64 %10, 1
%18 = extractelement <2 x double> %11, i64 1
%19 = fsub double %13, %18
%20 = fmul double %19, %19
%21 = uitofp i64 %10 to double
%22 = fmul double %20, %21
%23 = uitofp i64 %17 to double
%24 = insertelement <2 x double> poison, double %22, i64 0
%25 = insertelement <2 x double> %24, double %19, i64 1
%26 = insertelement <2 x double> poison, double %23, i64 0
%27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> zeroinitializer
%28 = fdiv <2 x double> %25, %27
%29 = fadd <2 x double> %11, %28
br label %30
30: ; preds = %16, %8
%31 = phi i64 [ %17, %16 ], [ %10, %8 ]
%32 = phi <2 x double> [ %29, %16 ], [ %11, %8 ]
%33 = add nuw i64 %9, 1
%34 = icmp eq i64 %33, %1
br i1 %34, label %6, label %8
35: ; preds = %4, %6
store double 0.000000e+00, double* %2
br label %42
36: ; preds = %6
%37 = extractelement <2 x double> %32, i64 1
store double %37, double* %2
%38 = uitofp i64 %31 to double
%39 = extractelement <2 x double> %32, i64 0
%40 = fdiv double %39, %38
%41 = tail call double @sqrt(double %40)
br label %42
42: ; preds = %36, %35
%43 = phi double [ %41, %36 ], [ 0.000000e+00, %35 ]
store double %43, double* %3
ret void
}