#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 computeMean(double *, int);
double pow(double, int);
double sqrt(double);
double computeStdDev(double data[], int length) {
  double sum = 0.0;
  double mean = computeMean(data, length);
  int i;
  for (i = 0; i < length; ++i) {
    sum = sum + pow((data[i] - mean), 2);
  }
  return sqrt(sum / length);
}


x86 assembly (clang, -O0):
<computeStdDev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <computeMean@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b0 <computeStdDev+0x80>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x20(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115f <computeStdDev+0x2f>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeStdDev>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <computeMean@plt>
xorpd  %xmm2,%xmm2
test   %r14d,%r14d
jle    1260 <computeStdDev+0x130>
movapd %xmm0,%xmm1
mov    %r14d,%r12d
lea    -0x1(%r12),%rax
mov    %r12d,%r15d
and    $0x3,%r15d
cmp    $0x3,%rax
movsd  %xmm0,0x8(%rsp)
jae    117e <computeStdDev+0x4e>
xorpd  %xmm2,%xmm2
xor    %ebp,%ebp
jmp    1224 <computeStdDev+0xf4>
and    $0xfffffffc,%r12d
xorpd  %xmm2,%xmm2
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rbx,%rbp,8),%xmm0
subsd  0x8(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rbx,%rbp,8),%xmm0
subsd  0x8(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x18(%rbx,%rbp,8),%xmm0
subsd  0x8(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
addsd  (%rsp),%xmm2
add    $0x4,%rbp
cmp    %rbp,%r12
jne    1190 <computeStdDev+0x60>
test   %r15,%r15
je     1260 <computeStdDev+0x130>
lea    (%rbx,%rbp,8),%rbx
xor    %ebp,%ebp
nop
movsd  %xmm2,(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm2
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1230 <computeStdDev+0x100>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
divsd  %xmm0,%xmm2
ucomisd 0xd8c(%rip),%xmm2
jb     128a <computeStdDev+0x15a>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movapd %xmm2,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sqrt@plt>

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

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