#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 CSPL_Stats_mean(double *, long);
double CSPL_Regression_LinearRsq(double *x, double *y, long n, double slope,
                                 double intercept) {
  double ymean;
  long i;
  double SStot = 0, SSres = 0;
  ymean = CSPL_Stats_mean(y, n);
  for (i = 0; i < n; i++) {
    SStot += ((y[i] - ymean) * (y[i] - ymean));
    SSres +=
        ((y[i] - slope * x[i] + intercept) * (y[i] - slope * x[i] + intercept));
  }
  return (1 - SSres / SStot);
}


x86 assembly (clang, -O0):
<CSPL_Regression_LinearRsq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <CSPL_Stats_mean@plt>
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1245 <CSPL_Regression_LinearRsq+0x135>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
subsd  -0x30(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm2
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
addsd  -0x28(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1158 <CSPL_Regression_LinearRsq+0x48>
movsd  -0x48(%rbp),%xmm1
divsd  -0x40(%rbp),%xmm1
movsd  0xda9(%rip),%xmm0
subsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CSPL_Regression_LinearRsq>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <CSPL_Stats_mean@plt>
test   %r15,%r15
jle    1167 <CSPL_Regression_LinearRsq+0x57>
movapd 0x10(%rsp),%xmm5
xorpd  0xec4(%rip),%xmm5
cmp    $0x1,%r15
movsd  0x8(%rsp),%xmm6
jne    1174 <CSPL_Regression_LinearRsq+0x64>
xorpd  %xmm1,%xmm1
xor    %eax,%eax
xorpd  %xmm2,%xmm2
jmp    11f1 <CSPL_Regression_LinearRsq+0xe1>
movsd  0xe91(%rip),%xmm1
jmp    1222 <CSPL_Regression_LinearRsq+0x112>
mov    %r15,%rcx
and    $0xfffffffffffffffe,%rcx
xorpd  %xmm1,%xmm1
xor    %eax,%eax
xorpd  %xmm2,%xmm2
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rbx,%rax,8),%xmm3
movsd  (%r14,%rax,8),%xmm4
mulsd  %xmm5,%xmm4
addsd  %xmm3,%xmm4
subsd  %xmm0,%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
movsd  0x8(%rbx,%rax,8),%xmm2
addsd  %xmm6,%xmm4
mulsd  %xmm4,%xmm4
addsd  %xmm1,%xmm4
movsd  0x8(%r14,%rax,8),%xmm1
mulsd  %xmm5,%xmm1
addsd  %xmm2,%xmm1
subsd  %xmm0,%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm3,%xmm2
addsd  %xmm6,%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm4,%xmm1
add    $0x2,%rax
cmp    %rax,%rcx
jne    1190 <CSPL_Regression_LinearRsq+0x80>
test   $0x1,%r15b
je     121e <CSPL_Regression_LinearRsq+0x10e>
mulsd  (%r14,%rax,8),%xmm5
movsd  (%rbx,%rax,8),%xmm3
addsd  %xmm3,%xmm5
subsd  %xmm0,%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm3,%xmm2
addsd  %xmm6,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm5,%xmm1
divsd  %xmm2,%xmm1
movsd  0xdde(%rip),%xmm0
subsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define double @CSPL_Regression_LinearRsq(double* nocapture %0, double* %1, i64 %2, double %3, double %4) {
%6 = tail call double @CSPL_Stats_mean(double* %1, i64 %2)
%7 = icmp sgt i64 %2, 0
br i1 %7, label %8, label %62
8: ; preds = %5
%9 = fneg double %3
%10 = and i64 %2, 1
%11 = icmp eq i64 %2, 1
br i1 %11, label %41, label %12
12: ; preds = %8
%13 = and i64 %2, -2
br label %14
14: ; preds = %14, %12
%15 = phi double [ 0.000000e+00, %12 ], [ %37, %14 ]
%16 = phi double [ 0.000000e+00, %12 ], [ %32, %14 ]
%17 = phi i64 [ 0, %12 ], [ %38, %14 ]
%18 = phi i64 [ 0, %12 ], [ %39, %14 ]
%19 = getelementptr inbounds double, double* %1, i64 %17
%20 = load double, double* %19
%21 = fsub double %20, %6
%22 = tail call double @llvm.fmuladd.f64(double %21, double %21, double %16)
%23 = getelementptr inbounds double, double* %0, i64 %17
%24 = load double, double* %23
%25 = tail call double @llvm.fmuladd.f64(double %9, double %24, double %20)
%26 = fadd double %25, %4
%27 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %15)
%28 = or i64 %17, 1
%29 = getelementptr inbounds double, double* %1, i64 %28
%30 = load double, double* %29
%31 = fsub double %30, %6
%32 = tail call double @llvm.fmuladd.f64(double %31, double %31, double %22)
%33 = getelementptr inbounds double, double* %0, i64 %28
%34 = load double, double* %33
%35 = tail call double @llvm.fmuladd.f64(double %9, double %34, double %30)
%36 = fadd double %35, %4
%37 = tail call double @llvm.fmuladd.f64(double %36, double %36, double %27)
%38 = add nuw nsw i64 %17, 2
%39 = add i64 %18, 2
%40 = icmp eq i64 %39, %13
br i1 %40, label %41, label %14
41: ; preds = %14, %8
%42 = phi double [ undef, %8 ], [ %32, %14 ]
%43 = phi double [ undef, %8 ], [ %37, %14 ]
%44 = phi double [ 0.000000e+00, %8 ], [ %37, %14 ]
%45 = phi double [ 0.000000e+00, %8 ], [ %32, %14 ]
%46 = phi i64 [ 0, %8 ], [ %38, %14 ]
%47 = icmp eq i64 %10, 0
br i1 %47, label %58, label %48
48: ; preds = %41
%49 = getelementptr inbounds double, double* %1, i64 %46
%50 = load double, double* %49
%51 = fsub double %50, %6
%52 = tail call double @llvm.fmuladd.f64(double %51, double %51, double %45)
%53 = getelementptr inbounds double, double* %0, i64 %46
%54 = load double, double* %53
%55 = tail call double @llvm.fmuladd.f64(double %9, double %54, double %50)
%56 = fadd double %55, %4
%57 = tail call double @llvm.fmuladd.f64(double %56, double %56, double %44)
br label %58
58: ; preds = %41, %48
%59 = phi double [ %42, %41 ], [ %52, %48 ]
%60 = phi double [ %43, %41 ], [ %57, %48 ]
%61 = fdiv double %60, %59
br label %62
62: ; preds = %58, %5
%63 = phi double [ %61, %58 ], [ 0x7FF8000000000000, %5 ]
%64 = fsub double 1.000000e+00, %63
ret double %64
}