#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 doubles_mean(double *, int);
double int_max(int, int);
scalar_t__ real_square(double);
double sqrt(double);
double doubles_sdev(double *farr, int size) {
  double mean = doubles_mean(farr, size);
  int i;
  double sum_sqs = 0.0;
  for (i = 0; i < size; i++)
    sum_sqs += real_square(farr[i] - mean);
  return (sqrt(sum_sqs / int_max(size, 1)));
}


x86 assembly (clang, -O0):
<doubles_sdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <doubles_mean@plt>
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11af <doubles_sdev+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1050 <real_square@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116f <doubles_sdev+0x2f>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   1030 <int_max@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_sdev>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
call   1040 <doubles_mean@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
test   %r14d,%r14d
jle    11c2 <doubles_sdev+0x82>
mov    %r14d,%ebp
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
movsd  %xmm1,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
movsd  (%r15,%rbx,8),%xmm0
subsd  %xmm1,%xmm0
call   1050 <real_square@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <doubles_sdev+0x40>
movsd  %xmm0,0x8(%rsp)
mov    %r14d,%edi
mov    $0x1,%esi
call   1030 <int_max@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
ucomisd 0xe0d(%rip),%xmm0
jb     1204 <doubles_sdev+0xc4>
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    1060 <sqrt@plt>

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

LLVM IR (-O2):
define double @doubles_sdev(double* %0, i32 %1) {
%3 = tail call double @doubles_mean(double* %0, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %18
5: ; preds = %2
%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, %3
%13 = tail call i64 @real_square(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, %2
%19 = phi double [ 0.000000e+00, %2 ], [ %15, %7 ]
%20 = tail call double @int_max(i32 %1, i32 1)
%21 = fdiv double %19, %20
%22 = tail call double @sqrt(double %21)
ret double %22
}