#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 sqrt(double);
double owl_stats_corrcoef(double *x, double *y, int n) {
  double sum_xsq = 0;
  double sum_ysq = 0;
  double sum_cross = 0;
  double mean_x = *x;
  double mean_y = *y;
  double delta_x, delta_y, ratio;
  for (int i = 1; i < n; ++i) {
    ratio = i / (i + 1.);
    delta_x = *(x + i) - mean_x;
    delta_y = *(y + i) - mean_y;
    sum_xsq += delta_x * delta_x * ratio;
    sum_ysq += delta_y * delta_y * ratio;
    sum_cross += delta_x * delta_y * ratio;
    mean_x += delta_x / (i + 1.);
    mean_y += delta_y / (i + 1.);
  }
  double r = sum_cross / (sqrt(sum_xsq) * sqrt(sum_ysq));
  return r;
}


x86 assembly (clang, -O0):
<owl_stats_corrcoef>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1271 <owl_stats_corrcoef+0x161>
cvtsi2sdl -0x5c(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
movsd  0xe83(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x50(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
movsd  0xdd3(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
movsd  0xdaf(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    115f <owl_stats_corrcoef+0x4f>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  -0x78(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<owl_stats_corrcoef>:
sub    $0x28,%rsp
xorpd  %xmm6,%xmm6
xorpd  %xmm8,%xmm8
xorpd  %xmm0,%xmm0
cmp    $0x2,%edx
jl     11ba <owl_stats_corrcoef+0xaa>
mov    %edx,%eax
movsd  (%rdi),%xmm2
movhpd (%rsi),%xmm2
xorpd  %xmm5,%xmm5
xorpd  %xmm0,%xmm0
mov    $0x1,%ecx
movsd  0xeb7(%rip),%xmm3
nopl   0x0(%rax)
xorps  %xmm6,%xmm6
cvtsi2sd %ecx,%xmm6
movapd %xmm5,%xmm4
movapd %xmm6,%xmm1
addsd  %xmm3,%xmm1
divsd  %xmm1,%xmm6
movsd  (%rdi,%rcx,8),%xmm7
movhpd (%rsi,%rcx,8),%xmm7
subpd  %xmm2,%xmm7
movapd %xmm7,%xmm5
mulsd  %xmm7,%xmm5
mulsd  %xmm6,%xmm5
addsd  %xmm5,%xmm0
movapd %xmm7,%xmm5
unpckhpd %xmm7,%xmm5
mulpd  %xmm7,%xmm5
unpcklpd %xmm6,%xmm6
mulpd  %xmm5,%xmm6
movapd %xmm6,%xmm5
addpd  %xmm4,%xmm5
unpcklpd %xmm1,%xmm1
divpd  %xmm1,%xmm7
addpd  %xmm7,%xmm2
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1150 <owl_stats_corrcoef+0x40>
addpd  %xmm4,%xmm6
ucomisd %xmm8,%xmm0
movapd %xmm6,0x10(%rsp)
jb     11d0 <owl_stats_corrcoef+0xc0>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
jmp    11df <owl_stats_corrcoef+0xcf>
call   1030 <sqrt@plt>
movapd 0x10(%rsp),%xmm6
movapd %xmm0,%xmm2
movapd %xmm6,%xmm0
unpckhpd %xmm6,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11f7 <owl_stats_corrcoef+0xe7>
sqrtsd %xmm0,%xmm0
jmp    120e <owl_stats_corrcoef+0xfe>
movsd  %xmm2,0x8(%rsp)
call   1030 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movapd 0x10(%rsp),%xmm6
mulsd  %xmm0,%xmm2
divsd  %xmm2,%xmm6
movapd %xmm6,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @owl_stats_corrcoef(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 double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
%17 = load double*, double** %4
%18 = load double, double* %17
store double %18, double* %10
%19 = load double*, double** %5
%20 = load double, double* %19
store double %20, double* %11
store i32 1, i32* %15
br label %21
21: ; preds = %78, %3
%22 = load i32, i32* %15
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %81
25: ; preds = %21
%26 = load i32, i32* %15
%27 = sitofp i32 %26 to double
%28 = load i32, i32* %15
%29 = sitofp i32 %28 to double
%30 = fadd double %29, 1.000000e+00
%31 = fdiv double %27, %30
store double %31, double* %14
%32 = load double*, double** %4
%33 = load i32, i32* %15
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = load double, double* %10
%38 = fsub double %36, %37
store double %38, double* %12
%39 = load double*, double** %5
%40 = load i32, i32* %15
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = load double, double* %11
%45 = fsub double %43, %44
store double %45, double* %13
%46 = load double, double* %12
%47 = load double, double* %12
%48 = fmul double %46, %47
%49 = load double, double* %14
%50 = load double, double* %7
%51 = call double @llvm.fmuladd.f64(double %48, double %49, double %50)
store double %51, double* %7
%52 = load double, double* %13
%53 = load double, double* %13
%54 = fmul double %52, %53
%55 = load double, double* %14
%56 = load double, double* %8
%57 = call double @llvm.fmuladd.f64(double %54, double %55, double %56)
store double %57, double* %8
%58 = load double, double* %12
%59 = load double, double* %13
%60 = fmul double %58, %59
%61 = load double, double* %14
%62 = load double, double* %9
%63 = call double @llvm.fmuladd.f64(double %60, double %61, double %62)
store double %63, double* %9
%64 = load double, double* %12
%65 = load i32, i32* %15
%66 = sitofp i32 %65 to double
%67 = fadd double %66, 1.000000e+00
%68 = fdiv double %64, %67
%69 = load double, double* %10
%70 = fadd double %69, %68
store double %70, double* %10
%71 = load double, double* %13
%72 = load i32, i32* %15
%73 = sitofp i32 %72 to double
%74 = fadd double %73, 1.000000e+00
%75 = fdiv double %71, %74
%76 = load double, double* %11
%77 = fadd double %76, %75
store double %77, double* %11
br label %78
78: ; preds = %25
%79 = load i32, i32* %15
%80 = add nsw i32 %79, 1
store i32 %80, i32* %15
br label %21
81: ; preds = %21
%82 = load double, double* %9
%83 = load double, double* %7
%84 = call double @sqrt(double %83)
%85 = load double, double* %8
%86 = call double @sqrt(double %85)
%87 = fmul double %84, %86
%88 = fdiv double %82, %87
store double %88, double* %16
%89 = load double, double* %16
ret double %89
}

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