#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__ sqr(double const);
double sqrt(double);
double stddev(const double *ds, int len, double mean) {
  double sum = 0;
  int i = 0;
  for (i = 0; i < len; i++)
    sum += sqr(ds[i] - mean);
  return sqrt(sum / len);
}


x86 assembly (clang, -O0):
<stddev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118a <stddev+0x6a>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1030 <sqr@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114a <stddev+0x2a>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stddev>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movapd %xmm0,%xmm1
mov    %esi,%r14d
xorpd  %xmm0,%xmm0
test   %esi,%esi
jle    1186 <stddev+0x66>
mov    %rdi,%r15
mov    %r14d,%ebp
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
movsd  %xmm1,0x8(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
movsd  (%r15,%rbx,8),%xmm0
subsd  %xmm1,%xmm0
call   1030 <sqr@plt>
movsd  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <stddev+0x30>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
ucomisd 0xe66(%rip),%xmm0
jb     11ab <stddev+0x8b>
sqrtsd %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define double @stddev(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
store i32 0, i32* %8
br label %9
9: ; preds = %25, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load double*, double** %4
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = load double, double* %6
%20 = fsub double %18, %19
%21 = call i64 @sqr(double %20)
%22 = sitofp i64 %21 to double
%23 = load double, double* %7
%24 = fadd double %23, %22
store double %24, double* %7
br label %25
25: ; preds = %13
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %9
28: ; preds = %9
%29 = load double, double* %7
%30 = load i32, i32* %5
%31 = sitofp i32 %30 to double
%32 = fdiv double %29, %31
%33 = call double @sqrt(double %32)
ret double %33
}

LLVM IR (-O2):
define double @stddev(double* nocapture %0, i32 %1, double %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %16, %7 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %15, %7 ]
%10 = getelementptr inbounds double, double* %0, i64 %8
%11 = load double, double* %10
%12 = fsub double %11, %2
%13 = tail call i64 @sqr(double %12)
%14 = sitofp i64 %13 to double
%15 = fadd double %9, %14
%16 = add nuw nsw i64 %8, 1
%17 = icmp eq i64 %16, %6
br i1 %17, label %18, label %7
18: ; preds = %7, %3
%19 = phi double [ 0.000000e+00, %3 ], [ %15, %7 ]
%20 = sitofp i32 %1 to double
%21 = fdiv double %19, %20
%22 = tail call double @sqrt(double %21)
ret double %22
}