// File: umatin[P]LogarithmicErrorRegression/./src/helpers/../exponential_search.h
// Function: exponential_search_lower_bound_linear_head(int, double, std::vector<double, std::allocator<double>>&)
int exponential_search_lower_bound_linear_head(int m, double key, std::vector<double> & data) {
    if(data[m] == key){
        return m;
    }
    int bound = 4;
    int l, r;  // will do binary search in range [l, r)
    if (data[m] >= key) {
        for(int i = 1; i < 4; i++){
            if(data[m-i] < key){
                return m-i;
            }
        }
        int size = m;
        while (bound < size && data[m - bound] > key) {
            bound *= 2;
        }
        l = m - std::min<int>(bound, size);
        r = m - bound / 2;
    } else {
        for(int i = 1; i < 4; i++){
            if(data[m+1] > key){
                return m+i;
            }
        }
        int size = data.size() - m;
        while (bound < size && data[m + bound] < key) {
            bound *= 2;
        }
        l = m + bound / 2;
        r = m + std::min<int>(bound, size);
    }
    return binary_search_lower_bound(l, r, key, data);
}

// Assembly:
subq $0x58, %rsp
movl %edi, 0x50(%rsp)
vmovsd %xmm0, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x50(%rsp), %rsi
callq 0x6390
vmovsd (%rax), %xmm0
vucomisd 0x48(%rsp), %xmm0
jne 0x35dd
jp 0x35dd
movl 0x50(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0x380a
movl $0x4, 0x3c(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x50(%rsp), %rsi
callq 0x6390
vmovsd (%rax), %xmm0
vucomisd 0x48(%rsp), %xmm0
jb 0x36f5
movl $0x1, 0x30(%rsp)
cmpl $0x4, 0x30(%rsp)
jge 0x3658
movq 0x40(%rsp), %rdi
movl 0x50(%rsp), %eax
subl 0x30(%rsp), %eax
movslq %eax, %rsi
callq 0x6390
vmovsd (%rax), %xmm1
vmovsd 0x48(%rsp), %xmm0
vucomisd %xmm1, %xmm0
jbe 0x3649
movl 0x50(%rsp), %eax
subl 0x30(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0x380a
jmp 0x364b
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x360c
movl 0x50(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x3c(%rsp), %ecx
xorl %eax, %eax
cmpl 0x2c(%rsp), %ecx
movb %al, 0x23(%rsp)
jge 0x3696
movq 0x40(%rsp), %rdi
movl 0x50(%rsp), %eax
subl 0x3c(%rsp), %eax
movslq %eax, %rsi
callq 0x6390
vmovsd (%rax), %xmm0
vucomisd 0x48(%rsp), %xmm0
seta %al
movb %al, 0x23(%rsp)
movb 0x23(%rsp), %al
testb $0x1, %al
jne 0x36a0
jmp 0x36ac
movl 0x3c(%rsp), %eax
shll %eax
movl %eax, 0x3c(%rsp)
jmp 0x3660
movl 0x50(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x3c(%rsp), %rdi
leaq 0x2c(%rsp), %rsi
callq 0x65c0
movq %rax, %rcx
movl 0x18(%rsp), %eax
subl (%rcx), %eax
movl %eax, 0x38(%rsp)
movl 0x50(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x3c(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x1c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x34(%rsp)
jmp 0x37ee
movl $0x1, 0x28(%rsp)
cmpl $0x4, 0x28(%rsp)
jge 0x3744
movq 0x40(%rsp), %rdi
movl 0x50(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x6390
vmovsd (%rax), %xmm0
vucomisd 0x48(%rsp), %xmm0
jbe 0x3735
movl 0x50(%rsp), %eax
addl 0x28(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0x380a
jmp 0x3737
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x36fd
movq 0x40(%rsp), %rdi
callq 0x6400
movslq 0x50(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x24(%rsp)
movl 0x3c(%rsp), %ecx
xorl %eax, %eax
cmpl 0x24(%rsp), %ecx
movb %al, 0x17(%rsp)
jge 0x3794
movq 0x40(%rsp), %rdi
movl 0x50(%rsp), %eax
addl 0x3c(%rsp), %eax
movslq %eax, %rsi
callq 0x6390
vmovsd (%rax), %xmm1
vmovsd 0x48(%rsp), %xmm0
vucomisd %xmm1, %xmm0
seta %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x379e
jmp 0x37aa
movl 0x3c(%rsp), %eax
shll %eax
movl %eax, 0x3c(%rsp)
jmp 0x375a
movl 0x50(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x3c(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0xc(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x38(%rsp)
movl 0x50(%rsp), %eax
movl %eax, 0x10(%rsp)
leaq 0x3c(%rsp), %rdi
leaq 0x24(%rsp), %rsi
callq 0x65c0
movq %rax, %rcx
movl 0x10(%rsp), %eax
addl (%rcx), %eax
movl %eax, 0x34(%rsp)
movl 0x38(%rsp), %edi
movl 0x34(%rsp), %esi
vmovsd 0x48(%rsp), %xmm0
movq 0x40(%rsp), %rdx
callq 0x6600
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)