double owl_stats_cov_stable(double *x, double *y, double mean_x, double mean_y,
                            int n) {
  double t = 0.;
  for (int i = 0; i < n; i++) {
    double d1 = (*(x + i) - mean_x);
    double d2 = (*(y + i) - mean_y);
    t += (d1 * d2 - t) / (i + 1);
  }
  return t;
}


x86 assembly (clang, -O0):
<owl_stats_cov_stable>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11b6 <owl_stats_cov_stable+0xb6>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1128 <owl_stats_cov_stable+0x28>
movsd  -0x30(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<owl_stats_cov_stable>:
test   %edx,%edx
jle    114b <owl_stats_cov_stable+0x4b>
mov    %edx,%eax
xorpd  %xmm3,%xmm3
xor    %ecx,%ecx
nopl   0x0(%rax)
movsd  (%rdi,%rcx,8),%xmm4
subsd  %xmm0,%xmm4
movsd  (%rsi,%rcx,8),%xmm2
subsd  %xmm1,%xmm2
mulsd  %xmm4,%xmm2
add    $0x1,%rcx
xorps  %xmm4,%xmm4
cvtsi2sd %ecx,%xmm4
subsd  %xmm3,%xmm2
divsd  %xmm4,%xmm2
addsd  %xmm3,%xmm2
movapd %xmm2,%xmm3
cmp    %rcx,%rax
jne    1110 <owl_stats_cov_stable+0x10>
movapd %xmm2,%xmm0
ret
xorps  %xmm2,%xmm2
movaps %xmm2,%xmm0
ret

LLVM IR (-O0):
define double @owl_stats_cov_stable(double* %0, double* %1, double %2, double %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double %2, double* %8
store double %3, double* %9
store i32 %4, i32* %10
store double 0.000000e+00, double* %11
store i32 0, i32* %12
br label %15
15: ; preds = %45, %5
%16 = load i32, i32* %12
%17 = load i32, i32* %10
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %48
19: ; preds = %15
%20 = load double*, double** %6
%21 = load i32, i32* %12
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = load double, double* %8
%26 = fsub double %24, %25
store double %26, double* %13
%27 = load double*, double** %7
%28 = load i32, i32* %12
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = load double, double* %9
%33 = fsub double %31, %32
store double %33, double* %14
%34 = load double, double* %13
%35 = load double, double* %14
%36 = load double, double* %11
%37 = fneg double %36
%38 = call double @llvm.fmuladd.f64(double %34, double %35, double %37)
%39 = load i32, i32* %12
%40 = add nsw i32 %39, 1
%41 = sitofp i32 %40 to double
%42 = fdiv double %38, %41
%43 = load double, double* %11
%44 = fadd double %43, %42
store double %44, double* %11
br label %45
45: ; preds = %19
%46 = load i32, i32* %12
%47 = add nsw i32 %46, 1
store i32 %47, i32* %12
br label %15
48: ; preds = %15
%49 = load double, double* %11
ret double %49
}

LLVM IR (-O2):
define double @owl_stats_cov_stable(double* nocapture %0, double* nocapture %1, double %2, double %3, i32 %4) {
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = zext i32 %4 to i64
br label %11
9: ; preds = %11, %5
%10 = phi double [ 0.000000e+00, %5 ], [ %26, %11 ]
ret double %10
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %22, %11 ]
%13 = phi double [ 0.000000e+00, %7 ], [ %26, %11 ]
%14 = getelementptr inbounds double, double* %0, i64 %12
%15 = load double, double* %14
%16 = fsub double %15, %2
%17 = getelementptr inbounds double, double* %1, i64 %12
%18 = load double, double* %17
%19 = fsub double %18, %3
%20 = fneg double %13
%21 = tail call double @llvm.fmuladd.f64(double %16, double %19, double %20)
%22 = add nuw nsw i64 %12, 1
%23 = trunc i64 %22 to i32
%24 = sitofp i32 %23 to double
%25 = fdiv double %21, %24
%26 = fadd double %13, %25
%27 = icmp eq i64 %22, %8
br i1 %27, label %9, label %11
}