// File: umatin[P]LogarithmicErrorRegression/./src/log_regression.h
// Function: linear_regression create_regression_tournament_selection_recursive<(ERROR_TYPE)1, true, true>(std::vector<double, std::allocator<double>>&, std::vector<int, std::allocator<int>>&, int, int, double&)
linear_regression create_regression_tournament_selection_recursive(std::vector<double>& data, std::vector<int>& tournament, int fr, int to, double & error){
    assert(to - fr >= 2);

    if (to - fr == 2){
        error = 0;
        return fit_line(data, tournament[fr], tournament[to-1]);;
    }
    double errorl = 0;
    linear_regression lr_l = create_regression_tournament_selection_recursive<E,ROUND,BOUNDED>(data, tournament, fr, (fr+to)/2, errorl);

    double errorr = 0;
    linear_regression lr_r = create_regression_tournament_selection_recursive<E,ROUND,BOUNDED>(data, tournament, (fr+to)/2, to, errorr);

    for (int i = (fr+to)/2; i < to; i++){
        errorl += calculate_error_single_element<E,ROUND,BOUNDED> (data, lr_l, tournament[i]);
    }
    for (int i = fr; i < (fr+to)/2; i++){
        errorr += calculate_error_single_element<E,ROUND,BOUNDED> (data, lr_r, tournament[i]);
    }
    if (errorl < errorr){
        error = errorl;
        return lr_l;
    }
    else{
        error = errorr;
        return lr_r;
    }
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movl %edx, 0xa4(%rsp)
movl %ecx, 0xa0(%rsp)
movq %r8, 0x98(%rsp)
movl 0xa0(%rsp), %eax
subl 0xa4(%rsp), %eax
cmpl $0x2, %eax
jl 0x12e42
jmp 0x12e61
leaq 0x248c(%rip), %rdi      # 0x152d5
leaq 0x2492(%rip), %rsi      # 0x152e2
movl $0x2e, %edx
leaq 0x249d(%rip), %rcx      # 0x152f9
callq 0x2130
movl 0xa0(%rsp), %eax
subl 0xa4(%rsp), %eax
cmpl $0x2, %eax
jne 0x12ef1
movq 0x98(%rsp), %rax
vpxor %xmm0, %xmm0, %xmm0
vmovsd %xmm0, (%rax)
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xa8(%rsp), %rdi
movslq 0xa4(%rsp), %rsi
callq 0x12de0
movslq (%rax), %rax
movq %rax, 0x30(%rsp)
movq 0xa8(%rsp), %rdi
movl 0xa0(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x12de0
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movslq (%rax), %rdx
callq 0x13cc0
vmovsd %xmm0, 0xb8(%rsp)
vmovsd %xmm1, 0xc0(%rsp)
jmp 0x1314c
vpxor %xmm0, %xmm0, %xmm0
vmovsd %xmm0, 0x90(%rsp)
movq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movl 0xa4(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0xa4(%rsp), %eax
addl 0xa0(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl 0x24(%rsp), %edx
movl %eax, %ecx
leaq 0x90(%rsp), %r8
callq 0x12e00
vmovsd %xmm0, 0x80(%rsp)
vmovsd %xmm1, 0x88(%rsp)
vpxor %xmm0, %xmm0, %xmm0
vmovsd %xmm0, 0x78(%rsp)
movq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movl 0xa4(%rsp), %eax
addl 0xa0(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %edx
movl 0xa0(%rsp), %ecx
leaq 0x78(%rsp), %r8
callq 0x12e00
vmovsd %xmm0, 0x68(%rsp)
vmovsd %xmm1, 0x70(%rsp)
movl 0xa4(%rsp), %eax
addl 0xa0(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jge 0x1303a
movq 0xb0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0xa8(%rsp), %rdi
movslq 0x64(%rsp), %rsi
callq 0x12de0
movq 0x18(%rsp), %rdi
movl (%rax), %esi
vmovsd 0x50(%rsp), %xmm0
vmovsd 0x58(%rsp), %xmm1
callq 0x13d90
vaddsd 0x90(%rsp), %xmm0, %xmm0
vmovsd %xmm0, 0x90(%rsp)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x12fbd
movl 0xa4(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0xa4(%rsp), %eax
addl 0xa0(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x130d4
movq 0xb0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xa8(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0x12de0
movq 0x8(%rsp), %rdi
movl (%rax), %esi
vmovsd 0x38(%rsp), %xmm0
vmovsd 0x40(%rsp), %xmm1
callq 0x13d90
vaddsd 0x78(%rsp), %xmm0, %xmm0
vmovsd %xmm0, 0x78(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x13045
vmovsd 0x90(%rsp), %xmm1
vmovsd 0x78(%rsp), %xmm0
vucomisd %xmm1, %xmm0
jbe 0x13120
vmovsd 0x90(%rsp), %xmm0
movq 0x98(%rsp), %rax
vmovsd %xmm0, (%rax)
movq 0x80(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0xc0(%rsp)
jmp 0x1314c
vmovsd 0x78(%rsp), %xmm0
movq 0x98(%rsp), %rax
vmovsd %xmm0, (%rax)
movq 0x68(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0xc0(%rsp)
vmovsd 0xb8(%rsp), %xmm0
vmovsd 0xc0(%rsp), %xmm1
addq $0xc8, %rsp
retq
nopw %cs:(%rax,%rax)