// File: /workspace/github_cpp_makefile_star2_O1/umatin[P]LogarithmicErrorRegression/./src/theil_sen.h
// Function: theil_sen(std::vector<double, std::allocator<double>>&, long)
linear_regression theil_sen(std::vector<double>& data, long max_trails){
    std::vector<double> slopes;
    double a,b;
    long num = (data.size() * (data.size()-1)) / 2;

    for (int i = 0; i < max_trails; i++){
        double a_tmp, b_tmp;
        fit_line(data, rand()%data.size(), rand()%data.size(), a_tmp, b_tmp);
        slopes.push_back(a_tmp);
    }
    a = quickselect(slopes,slopes.size()/2,0,slopes.size()-1);

    std::vector<double> intercepts;
    for (int i = 0; i < max_trails; i++){
        int element = rand()%data.size();
        double intercept = (double)element - (a * data[element]);
        intercepts.push_back(intercept);
    }
    b = quickselect(intercepts,intercepts.size()/2,0,intercepts.size()-1);
    return linear_regression(a,b);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
movq %rdi, %r14
vxorpd %xmm0, %xmm0, %xmm0
vmovapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %rsi, %rsi
jle 0x3a2d
leaq 0x20(%rsp), %r15
movq %rsp, %r12
movq %rbx, %rbp
callq 0x2080
cltq
movq 0x8(%r14), %rcx
subq (%r14), %rcx
sarq $0x3, %rcx
xorl %edx, %edx
divq %rcx
movq %rdx, %r13
callq 0x2080
cltq
movq (%r14), %rcx
movq 0x8(%r14), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %rax
subq %r13, %rax
vcvtsi2sd %rax, %xmm2, %xmm0
vmovsd (%rcx,%rdx,8), %xmm1
vsubsd (%rcx,%r13,8), %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
vmovsd %xmm0, (%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x3a1d
vmovsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x3a28
movq %r15, %rdi
movq %r12, %rdx
callq 0x83f2
decq %rbp
jne 0x39af
leaq 0x20(%rsp), %rdi
movq 0x8(%rdi), %rcx
subq (%rdi), %rcx
sarq $0x3, %rcx
movq %rcx, %rsi
shrq %rsi
decl %ecx
xorl %edx, %edx
callq 0x4cad
vmovapd %xmm0, 0x60(%rsp)
vxorpd %xmm0, %xmm0, %xmm0
vmovapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rbx, %rbx
jle 0x3ae5
vmovapd 0x60(%rsp), %xmm0
vxorpd 0x65e7(%rip){1to2}, %xmm0, %xmm0 # 0xa060
vmovapd %xmm0, 0x40(%rsp)
movq %rsp, %r15
leaq 0x58(%rsp), %r12
callq 0x2080
cltq
movq (%r14), %rcx
movq 0x8(%r14), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
xorl %edx, %edx
divq %rsi
vcvtsi2sd %edx, %xmm2, %xmm0
movslq %edx, %rax
vmovapd 0x40(%rsp), %xmm1
vfmadd231sd (%rcx,%rax,8), %xmm1, %xmm0 # xmm0 = (xmm1 * mem) + xmm0
vmovsd %xmm0, 0x58(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x3ad5
vmovsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x3ae0
movq %r15, %rdi
movq %r12, %rdx
callq 0x83f2
decq %rbx
jne 0x3a87
movq %rsp, %rdi
movq 0x8(%rdi), %rcx
subq (%rdi), %rcx
sarq $0x3, %rcx
movq %rcx, %rsi
shrq %rsi
decl %ecx
xorl %edx, %edx
callq 0x4cad
vmovsd %xmm0, 0x40(%rsp)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3b1e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3b35
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
vmovaps 0x60(%rsp), %xmm0
vmovsd 0x40(%rsp), %xmm1
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3b54
jmp 0x3b6f
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3b72
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
jmp 0x3b72
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3b89
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq %rbx, %rdi
callq 0x2360