// File: umatin[P]LogarithmicErrorRegression/./src/competitor_regression.h
// Function: simple_linear_regression_stable(std::vector<double, std::allocator<double>>&)
linear_regression simple_linear_regression_stable(std::vector<double>& data){
    long double count = data.size();
    long double x_mean = 0;
    long double y_mean = 0;
    long double xx_sum = 0;
    long double xy_sum = 0;

    for(int i = 0; i < data.size(); i++){
        x_mean += data[i];
        y_mean += (long double)i;
    }
    x_mean /= count;
    y_mean /= count;

    for(int i = 0; i < data.size(); i++){
        xx_sum += std::pow<long double>((long double)data[i] - x_mean, 2);
        xy_sum += (long double)(i - y_mean) * (long double)(data[i] - x_mean);
    }

    double a = xy_sum / xx_sum;
    double b = y_mean - (a * x_mean);

    assert(a >= 0);
    return linear_regression(a,b);
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xb0(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x6400
movq %rax, 0x40(%rsp)
testq %rax, %rax
sets %al
movzbl %al, %eax
movl %eax, %ecx
fildll 0x40(%rsp)
leaq 0x12399(%rip), %rax     # 0x15010
flds (%rax,%rcx,4)
faddp %st, %st(1)
fstpt 0xa0(%rsp)
fldz
fld %st(0)
fstpt 0x90(%rsp)
fld %st(0)
fstpt 0x80(%rsp)
fld %st(0)
fstpt 0x70(%rsp)
fstpt 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movslq 0x5c(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x6400
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
jae 0x2d1a
movq 0xb0(%rsp), %rdi
movslq 0x5c(%rsp), %rsi
callq 0x6390
fldl (%rax)
fldt 0x90(%rsp)
faddp %st, %st(1)
fstpt 0x90(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x30(%rsp)
fildl 0x30(%rsp)
fldt 0x80(%rsp)
faddp %st, %st(1)
fstpt 0x80(%rsp)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x2ca9
fldt 0xa0(%rsp)
fldt 0x90(%rsp)
fdivp %st, %st(1)
fstpt 0x90(%rsp)
fldt 0xa0(%rsp)
fldt 0x80(%rsp)
fdivp %st, %st(1)
fstpt 0x80(%rsp)
movl $0x0, 0x58(%rsp)
movslq 0x58(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x6400
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x2e04
movq 0xb0(%rsp), %rdi
movslq 0x58(%rsp), %rsi
callq 0x6390
fldl (%rax)
fldt 0x90(%rsp)
fsubrp %st, %st(1)
movq %rsp, %rax
fstpt (%rax)
movl $0x2, %edi
callq 0x6420
fldt 0x70(%rsp)
faddp %st, %st(1)
fstpt 0x70(%rsp)
movslq 0x58(%rsp), %rsi
movl %esi, %eax
movl %eax, 0x34(%rsp)
fildl 0x34(%rsp)
fldt 0x80(%rsp)
fsubrp %st, %st(1)
fstpt 0x14(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x6390
fldt 0x14(%rsp)
fldl (%rax)
fldt 0x90(%rsp)
fsubrp %st, %st(1)
fldt 0x60(%rsp)
fxch %st(2)
fmulp %st, %st(1)
faddp %st, %st(1)
fstpt 0x60(%rsp)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x2d50
fldt 0x60(%rsp)
fldt 0x70(%rsp)
fdivrp %st, %st(1)
fstpl 0x50(%rsp)
fldt 0x80(%rsp)
fldl 0x50(%rsp)
fldt 0x90(%rsp)
fmulp %st, %st(1)
fsubrp %st, %st(1)
fstpl 0x38(%rsp)
vmovsd 0x38(%rsp), %xmm0
vmovsd %xmm0, 0x48(%rsp)
vmovsd 0x50(%rsp), %xmm0
vpxor %xmm1, %xmm1, %xmm1
vucomisd %xmm1, %xmm0
jb 0x2e4a
jmp 0x2e69
leaq 0x12227(%rip), %rdi     # 0x15078
leaq 0x12227(%rip), %rsi     # 0x1507f
movl $0x33, %edx
leaq 0x1227b(%rip), %rcx     # 0x150df
callq 0x2130
vmovsd 0x50(%rsp), %xmm0
vmovsd 0x48(%rsp), %xmm1
leaq 0xb8(%rsp), %rdi
callq 0x63b0
vmovsd 0xb8(%rsp), %xmm0
vmovsd 0xc0(%rsp), %xmm1
addq $0xc8, %rsp
retq
nopl (%rax)