#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 somx(double **, long);
double somx2(double **, long);
double sqrt(double);
double ect(double **a, long stop) {
  long N;
  double ret = 0;
  double lsomx = somx(a, stop);
  double lsomx2 = somx2(a, stop);
  N = ((stop * (stop - 1)) / 2) + stop;
  ret = sqrt((lsomx2 - (lsomx * lsomx) / N) / (N - 1));
  return ret;
}


x86 assembly (clang, -O0):
<ect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <somx@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <somx2@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
imul   %rcx,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
add    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
cvtsi2sdq -0x18(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ect>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <somx@plt>
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <somx2@plt>
lea    -0x1(%rbx),%rax
imul   %rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
add    %rax,%rcx
sar    %rcx
lea    (%rcx,%rbx,1),%rax
movsd  (%rsp),%xmm2
mulsd  %xmm2,%xmm2
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
lea    -0x1(%rcx,%rbx,1),%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11a5 <ect+0x75>
sqrtsd %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <sqrt@plt>

LLVM IR (-O0):
define double @ect(double** %0, i64 %1) {
%3 = alloca double**
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double** %0, double*** %3
store i64 %1, i64* %4
store double 0.000000e+00, double* %6
%9 = load double**, double*** %3
%10 = load i64, i64* %4
%11 = call double @somx(double** %9, i64 %10)
store double %11, double* %7
%12 = load double**, double*** %3
%13 = load i64, i64* %4
%14 = call double @somx2(double** %12, i64 %13)
store double %14, double* %8
%15 = load i64, i64* %4
%16 = load i64, i64* %4
%17 = sub nsw i64 %16, 1
%18 = mul nsw i64 %15, %17
%19 = sdiv i64 %18, 2
%20 = load i64, i64* %4
%21 = add nsw i64 %19, %20
store i64 %21, i64* %5
%22 = load double, double* %8
%23 = load double, double* %7
%24 = load double, double* %7
%25 = fmul double %23, %24
%26 = load i64, i64* %5
%27 = sitofp i64 %26 to double
%28 = fdiv double %25, %27
%29 = fsub double %22, %28
%30 = load i64, i64* %5
%31 = sub nsw i64 %30, 1
%32 = sitofp i64 %31 to double
%33 = fdiv double %29, %32
%34 = call double @sqrt(double %33)
store double %34, double* %6
%35 = load double, double* %6
ret double %35
}

LLVM IR (-O2):
define double @ect(double** %0, i64 %1) {
%3 = tail call double @somx(double** %0, i64 %1)
%4 = tail call double @somx2(double** %0, i64 %1)
%5 = add nsw i64 %1, -1
%6 = mul nsw i64 %5, %1
%7 = sdiv i64 %6, 2
%8 = add nsw i64 %7, %1
%9 = fmul double %3, %3
%10 = sitofp i64 %8 to double
%11 = fdiv double %9, %10
%12 = fsub double %4, %11
%13 = add nsw i64 %8, -1
%14 = sitofp i64 %13 to double
%15 = fdiv double %12, %14
%16 = tail call double @sqrt(double %15)
ret double %16
}