double stat_pearson(const double *x, const double *y, int n) {
  assert(x);
  assert(y);
  assert(n > 0);
  double x_mean = stat_double_average(x, n);
  double x_stddev = sqrt(stat_double_variance(x, n));
  double y_mean = stat_double_average(y, n);
  double y_stddev = sqrt(stat_double_variance(y, n));
  double r = 0.0;
  int i;
  for (i = 0; i < n; i++) {
    double x_score = (x[i] - x_mean) / x_stddev;
    double y_score = (y[i] - y_mean) / y_stddev;
    r += x_score * y_score / (n - 1);
  }
  return r;
}


x86 assembly (clang, -O0):
<stat_pearson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x0,%al
call   1030 <stat_double_average@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x0,%al
call   1050 <stat_double_variance@plt>
cvtsi2sd %eax,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x0,%al
call   1030 <stat_double_average@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x0,%al
call   1050 <stat_double_variance@plt>
cvtsi2sd %eax,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1265 <stat_pearson+0x125>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11f1 <stat_pearson+0xb1>
movsd  -0x40(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat_pearson>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <assert@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <assert@plt>
xor    %edi,%edi
test   %r15d,%r15d
setg   %dil
xor    %eax,%eax
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <stat_double_average@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <stat_double_variance@plt>
cvtsi2sd %eax,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11a7 <stat_pearson+0x67>
sqrtsd %xmm0,%xmm0
jmp    11ac <stat_pearson+0x6c>
call   1060 <sqrt@plt>
movapd %xmm0,(%rsp)
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <stat_double_average@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <stat_double_variance@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd 0xe24(%rip),%xmm0
jb     11e4 <stat_pearson+0xa4>
sqrtsd %xmm0,%xmm0
jmp    11e9 <stat_pearson+0xa9>
call   1060 <sqrt@plt>
movapd (%rsp),%xmm5
test   %r15d,%r15d
jle    1252 <stat_pearson+0x112>
movd   %ebp,%xmm1
movd   %r12d,%xmm2
punpckldq %xmm1,%xmm2
cvtdq2pd %xmm2,%xmm1
lea    -0x1(%r15),%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
mov    %r15d,%eax
unpcklpd %xmm0,%xmm5
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
nopl   0x0(%rax)
movsd  (%rbx,%rcx,8),%xmm3
movhpd (%r14,%rcx,8),%xmm3
subpd  %xmm1,%xmm3
divpd  %xmm5,%xmm3
movapd %xmm3,%xmm4
unpckhpd %xmm3,%xmm4
mulsd  %xmm3,%xmm4
divsd  %xmm2,%xmm4
addsd  %xmm4,%xmm0
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1220 <stat_pearson+0xe0>
jmp    1256 <stat_pearson+0x116>
xorpd  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @stat_pearson(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%15 = load double*, double** %4
%16 = call i32 (double*, ...) bitcast (i32 (...)* @assert to i32 (double*, ...)*)(double* %15)
%17 = load double*, double** %5
%18 = call i32 (double*, ...) bitcast (i32 (...)* @assert to i32 (double*, ...)*)(double* %17)
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %21)
%23 = load double*, double** %4
%24 = load i32, i32* %6
%25 = call i32 (double*, i32, ...) bitcast (i32 (...)* @stat_double_average to i32 (double*, i32, ...)*)(double* %23, i32 %24)
%26 = sitofp i32 %25 to double
store double %26, double* %7
%27 = load double*, double** %4
%28 = load i32, i32* %6
%29 = call i32 (double*, i32, ...) bitcast (i32 (...)* @stat_double_variance to i32 (double*, i32, ...)*)(double* %27, i32 %28)
%30 = sitofp i32 %29 to double
%31 = call double @sqrt(double %30)
store double %31, double* %8
%32 = load double*, double** %5
%33 = load i32, i32* %6
%34 = call i32 (double*, i32, ...) bitcast (i32 (...)* @stat_double_average to i32 (double*, i32, ...)*)(double* %32, i32 %33)
%35 = sitofp i32 %34 to double
store double %35, double* %9
%36 = load double*, double** %5
%37 = load i32, i32* %6
%38 = call i32 (double*, i32, ...) bitcast (i32 (...)* @stat_double_variance to i32 (double*, i32, ...)*)(double* %36, i32 %37)
%39 = sitofp i32 %38 to double
%40 = call double @sqrt(double %39)
store double %40, double* %10
store double 0.000000e+00, double* %11
store i32 0, i32* %12
br label %41
41: ; preds = %73, %3
%42 = load i32, i32* %12
%43 = load i32, i32* %6
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %76
45: ; preds = %41
%46 = load double*, double** %4
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load double, double* %7
%52 = fsub double %50, %51
%53 = load double, double* %8
%54 = fdiv double %52, %53
store double %54, double* %13
%55 = load double*, double** %5
%56 = load i32, i32* %12
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = load double, double* %9
%61 = fsub double %59, %60
%62 = load double, double* %10
%63 = fdiv double %61, %62
store double %63, double* %14
%64 = load double, double* %13
%65 = load double, double* %14
%66 = fmul double %64, %65
%67 = load i32, i32* %6
%68 = sub nsw i32 %67, 1
%69 = sitofp i32 %68 to double
%70 = fdiv double %66, %69
%71 = load double, double* %11
%72 = fadd double %71, %70
store double %72, double* %11
br label %73
73: ; preds = %45
%74 = load i32, i32* %12
%75 = add nsw i32 %74, 1
store i32 %75, i32* %12
br label %41
76: ; preds = %41
%77 = load double, double* %11
ret double %77
}

LLVM IR (-O2):
define double @stat_pearson(double* %0, double* %1, i32 %2) {
%4 = tail call i32 (double*, ...) bitcast (i32 (...)* @assert to i32 (double*, ...)*)(double* %0)
%5 = tail call i32 (double*, ...) bitcast (i32 (...)* @assert to i32 (double*, ...)*)(double* %1)
%6 = icmp sgt i32 %2, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %7)
%9 = tail call i32 (double*, i32, ...) bitcast (i32 (...)* @stat_double_average to i32 (double*, i32, ...)*)(double* %0, i32 %2)
%10 = tail call i32 (double*, i32, ...) bitcast (i32 (...)* @stat_double_variance to i32 (double*, i32, ...)*)(double* %0, i32 %2)
%11 = sitofp i32 %10 to double
%12 = tail call double @sqrt(double %11)
%13 = tail call i32 (double*, i32, ...) bitcast (i32 (...)* @stat_double_average to i32 (double*, i32, ...)*)(double* %1, i32 %2)
%14 = insertelement <2 x i32> poison, i32 %9, i64 0
%15 = insertelement <2 x i32> %14, i32 %13, i64 1
%16 = sitofp <2 x i32> %15 to <2 x double>
%17 = tail call i32 (double*, i32, ...) bitcast (i32 (...)* @stat_double_variance to i32 (double*, i32, ...)*)(double* %1, i32 %2)
%18 = sitofp i32 %17 to double
%19 = tail call double @sqrt(double %18)
br i1 %6, label %20, label %44
20: ; preds = %3
%21 = add nsw i32 %2, -1
%22 = sitofp i32 %21 to double
%23 = zext i32 %2 to i64
%24 = insertelement <2 x double> poison, double %12, i64 0
%25 = insertelement <2 x double> %24, double %19, i64 1
br label %26
26: ; preds = %20, %26
%27 = phi i64 [ 0, %20 ], [ %42, %26 ]
%28 = phi double [ 0.000000e+00, %20 ], [ %41, %26 ]
%29 = getelementptr inbounds double, double* %0, i64 %27
%30 = load double, double* %29
%31 = getelementptr inbounds double, double* %1, i64 %27
%32 = load double, double* %31
%33 = insertelement <2 x double> poison, double %30, i64 0
%34 = insertelement <2 x double> %33, double %32, i64 1
%35 = fsub <2 x double> %34, %16
%36 = fdiv <2 x double> %35, %25
%37 = shufflevector <2 x double> %36, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%38 = fmul <2 x double> %36, %37
%39 = extractelement <2 x double> %38, i64 0
%40 = fdiv double %39, %22
%41 = fadd double %28, %40
%42 = add nuw nsw i64 %27, 1
%43 = icmp eq i64 %42, %23
br i1 %43, label %44, label %26
44: ; preds = %26, %3
%45 = phi double [ 0.000000e+00, %3 ], [ %41, %26 ]
ret double %45
}