double variance(double mean, double *times) {
  int i;
  double sum = 0.0;
  for (i = 0; i < 5; i++) {
    double diff = mean - times[i];
    sum += diff * diff;
  }
  return sum / (5 - 1);
}


x86 assembly (clang, -O0):
<variance>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1167 <variance+0x67>
movsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    111c <variance+0x1c>
movsd  -0x20(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
divsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance>:
movapd %xmm0,%xmm1
subsd  (%rdi),%xmm1
mulsd  %xmm1,%xmm1
xorpd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
movapd %xmm0,%xmm1
subsd  0x8(%rdi),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm0,%xmm2
subsd  0x10(%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
movapd %xmm0,%xmm1
subsd  0x18(%rdi),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
subsd  0x20(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xea4(%rip),%xmm0
ret

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

LLVM IR (-O2):
define double @variance(double %0, double* nocapture %1) {
%3 = load double, double* %1
%4 = fsub double %0, %3
%5 = tail call double @llvm.fmuladd.f64(double %4, double %4, double 0.000000e+00)
%6 = getelementptr inbounds double, double* %1, i64 1
%7 = load double, double* %6
%8 = fsub double %0, %7
%9 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %5)
%10 = getelementptr inbounds double, double* %1, i64 2
%11 = load double, double* %10
%12 = fsub double %0, %11
%13 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %9)
%14 = getelementptr inbounds double, double* %1, i64 3
%15 = load double, double* %14
%16 = fsub double %0, %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %13)
%18 = getelementptr inbounds double, double* %1, i64 4
%19 = load double, double* %18
%20 = fsub double %0, %19
%21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %17)
%22 = fmul double %21, 2.500000e-01
ret double %22
}