#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 asum(double *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ vsp(double *, double *, double, int);
double variance(double *a, int n) {
  double *aa;
  double y1, y2;
  if ((aa = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  y1 = asum(a, n) / (double)n;
  vsp(aa, a, -y1, n);
  y2 = asum(aa, n) / (double)n;
  free(aa);
  return y2;
}


x86 assembly (clang, -O0):
<variance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1189 <variance+0x39>
mov    -0xc(%rbp),%esi
lea    0xe7c(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <asum@plt>
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0xc(%rbp),%edx
call   1040 <vsp@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <asum@plt>
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
mov    %esi,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1180 <variance+0x30>
lea    0xe97(%rip),%rdi
mov    %ebx,%esi
call   1050 <fatalx@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <asum@plt>
cvtsi2sd %ebx,%xmm1
movsd  %xmm1,0x8(%rsp)
xorpd  0xe64(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <vsp@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1070 <asum@plt>
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @variance(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double*
%6 = alloca double
%7 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = call i64 @calloc(i32 %8, i32 8)
%10 = inttoptr i64 %9 to double*
store double* %10, double** %5
%11 = icmp eq double* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* %4
%14 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %2
%16 = load double*, double** %3
%17 = load i32, i32* %4
%18 = call double @asum(double* %16, i32 %17)
%19 = load i32, i32* %4
%20 = sitofp i32 %19 to double
%21 = fdiv double %18, %20
store double %21, double* %6
%22 = load double*, double** %5
%23 = load double*, double** %3
%24 = load double, double* %6
%25 = fneg double %24
%26 = load i32, i32* %4
%27 = call i32 @vsp(double* %22, double* %23, double %25, i32 %26)
%28 = load double*, double** %5
%29 = load i32, i32* %4
%30 = call double @asum(double* %28, i32 %29)
%31 = load i32, i32* %4
%32 = sitofp i32 %31 to double
%33 = fdiv double %30, %32
store double %33, double* %7
%34 = load double*, double** %5
%35 = call i32 @free(double* %34)
%36 = load double, double* %7
ret double %36
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @variance(double* %0, i32 %1) {
%3 = tail call i64 @calloc(i32 %1, i32 8)
%4 = inttoptr i64 %3 to double*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %8
8: ; preds = %6, %2
%9 = tail call double @asum(double* %0, i32 %1)
%10 = sitofp i32 %1 to double
%11 = fneg double %9
%12 = fdiv double %11, %10
%13 = tail call i32 @vsp(double* %4, double* %0, double %12, i32 %1)
%14 = tail call double @asum(double* %4, i32 %1)
%15 = fdiv double %14, %10
%16 = tail call i32 @free(double* %4)
ret double %15
}