#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);
double get_std_dev(int n, double sum_x_squared, double av_x) {
  double std_dev;
  if (n <= 1) {
    std_dev = 0.;
  } else {
    std_dev = (sum_x_squared - n * av_x * av_x) / (double)(n - 1);
  }
  if (std_dev > 0.) {
    std_dev = sqrt(std_dev);
  } else {
    std_dev = 0.;
  }
  return (std_dev);
}


x86 assembly (clang, -O0):
<get_std_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
cmpl   $0x1,-0x4(%rbp)
jg     113c <get_std_dev+0x2c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1182 <get_std_dev+0x72>
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x4(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11a8 <get_std_dev+0x98>
movsd  -0x20(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    11b0 <get_std_dev+0xa0>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_std_dev>:
xorpd  %xmm2,%xmm2
cmp    $0x2,%edi
jl     1155 <get_std_dev+0x45>
xorps  %xmm2,%xmm2
cvtsi2sd %edi,%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
add    $0xffffffff,%edi
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
divsd  %xmm1,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jbe    1155 <get_std_dev+0x45>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     115a <get_std_dev+0x4a>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
movapd %xmm2,%xmm0
ret
jmp    1030 <sqrt@plt>

LLVM IR (-O0):
define double @get_std_dev(i32 %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
store double %2, double* %6
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %3
store double 0.000000e+00, double* %7
br label %24
11: ; preds = %3
%12 = load double, double* %5
%13 = load i32, i32* %4
%14 = sitofp i32 %13 to double
%15 = load double, double* %6
%16 = fmul double %14, %15
%17 = load double, double* %6
%18 = fneg double %16
%19 = call double @llvm.fmuladd.f64(double %18, double %17, double %12)
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
%22 = sitofp i32 %21 to double
%23 = fdiv double %19, %22
store double %23, double* %7
br label %24
24: ; preds = %11, %10
%25 = load double, double* %7
%26 = fcmp ogt double %25, 0.000000e+00
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load double, double* %7
%29 = call double @sqrt(double %28)
store double %29, double* %7
br label %31
30: ; preds = %24
store double 0.000000e+00, double* %7
br label %31
31: ; preds = %30, %27
%32 = load double, double* %7
ret double %32
}

LLVM IR (-O2):
define double @get_std_dev(i32 %0, double %1, double %2) {
%4 = icmp slt i32 %0, 2
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = sitofp i32 %0 to double
%7 = fneg double %6
%8 = fmul double %7, %2
%9 = tail call double @llvm.fmuladd.f64(double %8, double %2, double %1)
%10 = add nsw i32 %0, -1
%11 = sitofp i32 %10 to double
%12 = fdiv double %9, %11
%13 = fcmp ogt double %12, 0.000000e+00
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = tail call double @sqrt(double %12)
br label %16
16: ; preds = %3, %5, %14
%17 = phi double [ %15, %14 ], [ 0.000000e+00, %5 ], [ 0.000000e+00, %3 ]
ret double %17
}