// File: /workspace/github_cpp_makefile_star2_O3/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
vxorpd %xmm0, %xmm0, %xmm0
movq %rsi, %rbx
movq %rdi, %r14
movq $0x0, 0x30(%rsp)
vmovapd %xmm0, 0x20(%rsp)
testq %rsi, %rsi
jle 0x39d9
leaq 0x20(%rsp), %r15
movq %rsp, %r12
movq %rbx, %rbp
callq 0x2080
movq 0x8(%r14), %rcx
cltq
xorl %edx, %edx
subq (%r14), %rcx
sarq $0x3, %rcx
divq %rcx
movq %rdx, %r13
callq 0x2080
movq (%r14), %rcx
movq 0x8(%r14), %rsi
cltq
xorl %edx, %edx
subq %rcx, %rsi
sarq $0x3, %rsi
divq %rsi
movq 0x28(%rsp), %rsi
vmovsd (%rcx,%rdx,8), %xmm1
movq %rdx, %rax
subq %r13, %rax
vsubsd (%rcx,%r13,8), %xmm1, %xmm1
vcvtsi2sd %rax, %xmm2, %xmm0
vdivsd %xmm1, %xmm0, %xmm0
vmovsd %xmm0, (%rsp)
cmpq 0x30(%rsp), %rsi
je 0x39b9
vmovsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x39c4
movq %r15, %rdi
movq %r12, %rdx
callq 0x8380
decq %rbp
jne 0x394b
movq 0x28(%rsp), %rcx
subq 0x20(%rsp), %rcx
sarq $0x3, %rcx
jmp 0x39db
xorl %ecx, %ecx
movq %rcx, %rsi
shrq %rsi
decl %ecx
leaq 0x20(%rsp), %rdi
xorl %edx, %edx
callq 0x4c51
vmovapd %xmm0, 0x60(%rsp)
vxorpd %xmm0, %xmm0, %xmm0
movq $0x0, 0x10(%rsp)
vmovapd %xmm0, (%rsp)
testq %rbx, %rbx
jle 0x3a9b
vmovapd 0x60(%rsp), %xmm0
leaq 0x58(%rsp), %r12
movq %rsp, %r15
vxorpd 0x6638(%rip){1to2}, %xmm0, %xmm0 # 0xa060
vmovapd %xmm0, 0x40(%rsp)
callq 0x2080
movq (%r14), %rcx
movq 0x8(%r14), %rsi
cltq
xorl %edx, %edx
subq %rcx, %rsi
sarq $0x3, %rsi
divq %rsi
vmovapd 0x40(%rsp), %xmm1
movq 0x8(%rsp), %rsi
movslq %edx, %rax
vcvtsi2sd %edx, %xmm2, %xmm0
vfmadd231sd (%rcx,%rax,8), %xmm1, %xmm0 # xmm0 = (xmm1 * mem) + xmm0
vmovsd %xmm0, 0x58(%rsp)
cmpq 0x10(%rsp), %rsi
je 0x3a7c
vmovsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x3a87
movq %r15, %rdi
movq %r12, %rdx
callq 0x8380
decq %rbx
jne 0x3a2e
movq 0x8(%rsp), %rcx
subq (%rsp), %rcx
sarq $0x3, %rcx
jmp 0x3a9d
xorl %ecx, %ecx
movq %rcx, %rsi
shrq %rsi
decl %ecx
movq %rsp, %rdi
xorl %edx, %edx
callq 0x4c51
vmovsd %xmm0, 0x40(%rsp)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3acb
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3ae2
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 0x3b01
jmp 0x3b1c
movq (%rsp), %rdi
movq %rax, %rbx
testq %rdi, %rdi
je 0x3b1f
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
jmp 0x3b1f
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3b36
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq %rbx, %rdi
callq 0x2360