#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double sqrt(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void variance(double *s, unsigned long l, double *av, double *var) {
  unsigned long i;
  double h;
  *av = *var = 0.0;
  for (i = 0; i < l; i++) {
    h = s[i];
    *av += h;
    *var += h * h;
  }
  *av /= (double)l;
  *var = sqrt(fabs((*var) / (double)l - (*av) * (*av)));
  if (*var == 0.0) {
    fprintf(stderr, "Variance of the data is zero. Exiting!\n\n");
    exit(23);
  }
}


x86 assembly (clang, -O0):
<variance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11d6 <variance+0x96>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1176 <variance+0x36>
movq   -0x10(%rbp),%xmm1
movaps 0xe1e(%rip),%xmm3
punpckldq %xmm3,%xmm1
movapd 0xe22(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
movq   -0x10(%rbp),%xmm0
punpckldq %xmm3,%xmm0
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
call   1050 <sqrt@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12ae <variance+0x16e>
jp     12ae <variance+0x16e>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x17,%edi
call   1060 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance>:
push   %rbx
mov    %rcx,%rbx
movq   $0x0,(%rcx)
movq   $0x0,(%rdx)
xorpd  %xmm1,%xmm1
test   %rsi,%rsi
je     11e7 <variance+0xa7>
cmp    $0x1,%rsi
jne    116d <variance+0x2d>
xorpd  %xmm1,%xmm1
xor    %eax,%eax
jmp    11c4 <variance+0x84>
mov    %rsi,%rcx
and    $0xfffffffffffffffe,%rcx
xorpd  %xmm1,%xmm1
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movsd  (%rdi,%rax,8),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdx)
mulsd  %xmm0,%xmm0
addsd  (%rbx),%xmm0
movsd  %xmm0,(%rbx)
movsd  0x8(%rdi,%rax,8),%xmm0
movsd  (%rdx),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdx)
mulsd  %xmm0,%xmm0
addsd  (%rbx),%xmm0
movsd  %xmm0,(%rbx)
add    $0x2,%rax
movsd  (%rdx),%xmm1
cmp    %rax,%rcx
jne    1180 <variance+0x40>
test   $0x1,%sil
je     11e7 <variance+0xa7>
movsd  (%rdi,%rax,8),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdx)
mulsd  %xmm0,%xmm0
addsd  (%rbx),%xmm0
movsd  %xmm0,(%rbx)
movsd  (%rdx),%xmm1
movq   %rsi,%xmm0
punpckldq 0xe0c(%rip),%xmm0
subpd  0xe14(%rip),%xmm0
movapd %xmm0,%xmm2
unpckhpd %xmm0,%xmm2
addsd  %xmm0,%xmm2
divsd  %xmm2,%xmm1
movsd  %xmm1,(%rdx)
movsd  (%rbx),%xmm0
divsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,(%rbx)
ucomisd 0xde8(%rip),%xmm0
jne    123c <variance+0xfc>
jnp    123e <variance+0xfe>
pop    %rbx
ret
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x17,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Variance of the data is zero. Exiting!\0A\0A\00"
define void @variance(double* %0, i64 %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca i64
%7 = alloca double*
%8 = alloca double*
%9 = alloca i64
%10 = alloca double
store double* %0, double** %5
store i64 %1, i64* %6
store double* %2, double** %7
store double* %3, double** %8
%11 = load double*, double** %8
store double 0.000000e+00, double* %11
%12 = load double*, double** %7
store double 0.000000e+00, double* %12
store i64 0, i64* %9
br label %13
13: ; preds = %31, %4
%14 = load i64, i64* %9
%15 = load i64, i64* %6
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %34
17: ; preds = %13
%18 = load double*, double** %5
%19 = load i64, i64* %9
%20 = getelementptr inbounds double, double* %18, i64 %19
%21 = load double, double* %20
store double %21, double* %10
%22 = load double, double* %10
%23 = load double*, double** %7
%24 = load double, double* %23
%25 = fadd double %24, %22
store double %25, double* %23
%26 = load double, double* %10
%27 = load double, double* %10
%28 = load double*, double** %8
%29 = load double, double* %28
%30 = call double @llvm.fmuladd.f64(double %26, double %27, double %29)
store double %30, double* %28
br label %31
31: ; preds = %17
%32 = load i64, i64* %9
%33 = add i64 %32, 1
store i64 %33, i64* %9
br label %13
34: ; preds = %13
%35 = load i64, i64* %6
%36 = uitofp i64 %35 to double
%37 = load double*, double** %7
%38 = load double, double* %37
%39 = fdiv double %38, %36
store double %39, double* %37
%40 = load double*, double** %8
%41 = load double, double* %40
%42 = load i64, i64* %6
%43 = uitofp i64 %42 to double
%44 = fdiv double %41, %43
%45 = load double*, double** %7
%46 = load double, double* %45
%47 = load double*, double** %7
%48 = load double, double* %47
%49 = fneg double %46
%50 = call double @llvm.fmuladd.f64(double %49, double %48, double %44)
%51 = call i32 @fabs(double %50)
%52 = call double @sqrt(i32 %51)
%53 = load double*, double** %8
store double %52, double* %53
%54 = load double*, double** %8
%55 = load double, double* %54
%56 = fcmp oeq double %55, 0.000000e+00
br i1 %56, label %57, label %61
57: ; preds = %34
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%60 = call i32 @exit(i32 23)
unreachable
61: ; preds = %34
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Variance of the data is zero. Exiting!\0A\0A\00"
define void @variance(double* nocapture %0, i64 %1, double* nocapture %2, double* nocapture %3) {
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %2
%5 = icmp eq i64 %1, 0
br i1 %5, label %43, label %6
6: ; preds = %4
%7 = and i64 %1, 1
%8 = icmp eq i64 %1, 1
br i1 %8, label %31, label %9
9: ; preds = %6
%10 = and i64 %1, -2
br label %11
11: ; preds = %11, %9
%12 = phi double [ 0.000000e+00, %9 ], [ %28, %11 ]
%13 = phi i64 [ 0, %9 ], [ %27, %11 ]
%14 = phi i64 [ 0, %9 ], [ %29, %11 ]
%15 = getelementptr inbounds double, double* %0, i64 %13
%16 = load double, double* %15
%17 = fadd double %16, %12
store double %17, double* %2
%18 = load double, double* %3
%19 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %18)
store double %19, double* %3
%20 = or i64 %13, 1
%21 = load double, double* %2
%22 = getelementptr inbounds double, double* %0, i64 %20
%23 = load double, double* %22
%24 = fadd double %23, %21
store double %24, double* %2
%25 = load double, double* %3
%26 = tail call double @llvm.fmuladd.f64(double %23, double %23, double %25)
store double %26, double* %3
%27 = add nuw i64 %13, 2
%28 = load double, double* %2
%29 = add i64 %14, 2
%30 = icmp eq i64 %29, %10
br i1 %30, label %31, label %11
31: ; preds = %11, %6
%32 = phi double [ undef, %6 ], [ %28, %11 ]
%33 = phi double [ 0.000000e+00, %6 ], [ %28, %11 ]
%34 = phi i64 [ 0, %6 ], [ %27, %11 ]
%35 = icmp eq i64 %7, 0
br i1 %35, label %43, label %36
36: ; preds = %31
%37 = getelementptr inbounds double, double* %0, i64 %34
%38 = load double, double* %37
%39 = fadd double %38, %33
store double %39, double* %2
%40 = load double, double* %3
%41 = tail call double @llvm.fmuladd.f64(double %38, double %38, double %40)
store double %41, double* %3
%42 = load double, double* %2
br label %43
43: ; preds = %36, %31, %4
%44 = phi double [ 0.000000e+00, %4 ], [ %32, %31 ], [ %42, %36 ]
%45 = uitofp i64 %1 to double
%46 = fdiv double %44, %45
store double %46, double* %2
%47 = load double, double* %3
%48 = fdiv double %47, %45
%49 = fneg double %46
%50 = tail call double @llvm.fmuladd.f64(double %49, double %46, double %48)
%51 = tail call i32 @fabs(double %50)
%52 = tail call double @sqrt(i32 %51)
store double %52, double* %3
%53 = fcmp oeq double %52, 0.000000e+00
br i1 %53, label %54, label %58
54: ; preds = %43
%55 = load i32, i32* @stderr
%56 = tail call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%57 = tail call i32 @exit(i32 23)
unreachable
58: ; preds = %43
ret void
}