#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 */
double sqrt(double);
int doublemeanrms(int ndat, double *dat, double *mean, double *sigma) {
  int n = 0, i;
  double x;
  double sx = 0;
  double sx2 = 0;
  for (i = 0; i < ndat; i++) {
    n++;
    x = dat[i] - sx;
    sx += x / (double)n;
    sx2 += (double)(n - 1) * x * x / (double)n;
  }
  *mean = sx;
  if (n > 1)
    *sigma = sqrt(sx2 / ((double)(n - 1)));
  return 0;
}


x86 assembly (clang, -O0):
<doublemeanrms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11be <doublemeanrms+0xae>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1145 <doublemeanrms+0x35>
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0x1,-0x24(%rbp)
jle    11f5 <doublemeanrms+0xe5>
movsd  -0x40(%rbp),%xmm0
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doublemeanrms>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    119e <doublemeanrms+0x8e>
mov    %rcx,%r14
mov    %edi,%eax
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movapd %xmm0,%xmm1
movsd  (%rsi,%rcx,8),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
lea    0x1(%rcx),%rbx
movapd %xmm1,%xmm3
unpckhpd %xmm1,%xmm3
xorps  %xmm4,%xmm4
cvtsi2sd %ebx,%xmm4
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm0
unpcklpd %xmm2,%xmm0
unpcklpd %xmm4,%xmm4
divpd  %xmm4,%xmm0
addpd  %xmm1,%xmm0
mov    %rbx,%rcx
cmp    %rbx,%rax
jne    1130 <doublemeanrms+0x20>
movhpd %xmm0,(%rdx)
cmp    $0x2,%eax
jb     11b1 <doublemeanrms+0xa1>
add    $0xffffffff,%edi
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
divsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11a7 <doublemeanrms+0x97>
sqrtsd %xmm0,%xmm0
jmp    11ac <doublemeanrms+0x9c>
movq   $0x0,(%rdx)
jmp    11b1 <doublemeanrms+0xa1>
call   1030 <sqrt@plt>
movsd  %xmm0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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