#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 mean(double *, double);
double var(double *x, double n) {
  int i;
  double m, r, sum = 0;
  m = mean(x, n);
  for (i = 0; i < n; i++) {
    r = x[i] - m;
    sum += (r * r);
  }
  return sum / n;
}


x86 assembly (clang, -O0):
<var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
call   1030 <mean@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1198 <var+0x88>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <var+0x33>
movsd  -0x30(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<var>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
call   1030 <mean@plt>
movsd  0x8(%rsp),%xmm3
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jbe    1162 <var+0x52>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
nopl   (%rax)
movsd  (%rbx,%rax,8),%xmm2
subsd  %xmm1,%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%rax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
ucomisd %xmm2,%xmm3
ja     1140 <var+0x30>
divsd  %xmm3,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double @var(double* %0, double %1) {
%3 = tail call double @mean(double* %0, double %1)
%4 = fcmp ogt double %1, 0.000000e+00
br i1 %4, label %5, label %16
5: ; preds = %2, %5
%6 = phi i64 [ %12, %5 ], [ 0, %2 ]
%7 = phi double [ %11, %5 ], [ 0.000000e+00, %2 ]
%8 = getelementptr inbounds double, double* %0, i64 %6
%9 = load double, double* %8
%10 = fsub double %9, %3
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %7)
%12 = add nuw i64 %6, 1
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to double
%15 = fcmp olt double %14, %1
br i1 %15, label %5, label %16
16: ; preds = %5, %2
%17 = phi double [ 0.000000e+00, %2 ], [ %11, %5 ]
%18 = fdiv double %17, %1
ret double %18
}