// File: umatin[P]LogarithmicErrorRegression/./src/helpers/../exponential_search.h
// Function: exponential_search_lower_bound_steps(int, double, std::vector<double, std::allocator<double>>&, int&)
int exponential_search_lower_bound_steps(int m, double key, std::vector<double> & data, int & steps) {
    // Continue doubling the bound until it contains the lower bound. Then use
    // binary search.
    steps = 1;
    int bound = 1;
    int l, r;  // will do binary search in range [l, r)
    if (data[m] >= key) {
        int size = m;
        while (bound < size && data[m - bound] >= key) {
            bound *= 2;
            steps++;
        }
        l = m - std::min<int>(bound, size);
        r = m - bound / 2;
    } else {
        int size = data.size() - m;
        while (bound < size && data[m + bound] < key) {
            bound *= 2;
            steps++;
        }
        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, 0x54(%rsp)
vmovsd %xmm0, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq 0x38(%rsp), %rax
movl $0x1, (%rax)
movl $0x1, 0x34(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x6390
vmovsd (%rax), %xmm0
vucomisd 0x48(%rsp), %xmm0
jb 0x3913
movl 0x54(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
xorl %eax, %eax
cmpl 0x28(%rsp), %ecx
movb %al, 0x23(%rsp)
jge 0x38a8
movq 0x40(%rsp), %rdi
movl 0x54(%rsp), %eax
subl 0x34(%rsp), %eax
movslq %eax, %rsi
callq 0x6390
vmovsd (%rax), %xmm0
vucomisd 0x48(%rsp), %xmm0
setae %al
movb %al, 0x23(%rsp)
movb 0x23(%rsp), %al
testb $0x1, %al
jne 0x38b2
jmp 0x38ca
movl 0x34(%rsp), %eax
shll %eax
movl %eax, 0x34(%rsp)
movq 0x38(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x3872
movl 0x54(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x34(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x65c0
movq %rax, %rcx
movl 0x18(%rsp), %eax
subl (%rcx), %eax
movl %eax, 0x30(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x34(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x1c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x2c(%rsp)
jmp 0x39c9
movq 0x40(%rsp), %rdi
callq 0x6400
movslq 0x54(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x24(%rsp)
movl 0x34(%rsp), %ecx
xorl %eax, %eax
cmpl 0x24(%rsp), %ecx
movb %al, 0x17(%rsp)
jge 0x3963
movq 0x40(%rsp), %rdi
movl 0x54(%rsp), %eax
addl 0x34(%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 0x396d
jmp 0x3985
movl 0x34(%rsp), %eax
shll %eax
movl %eax, 0x34(%rsp)
movq 0x38(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x3929
movl 0x54(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x34(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0xc(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x30(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0x10(%rsp)
leaq 0x34(%rsp), %rdi
leaq 0x24(%rsp), %rsi
callq 0x65c0
movq %rax, %rcx
movl 0x10(%rsp), %eax
addl (%rcx), %eax
movl %eax, 0x2c(%rsp)
movl 0x30(%rsp), %edi
movl 0x2c(%rsp), %esi
vmovsd 0x48(%rsp), %xmm0
movq 0x40(%rsp), %rdx
callq 0x6600
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)