// File: /workspace/github_cpp_makefile_star2_O1/6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/static_search_trees.cpp
// Function: co_static_search_tree::get(int, int, int, int, int)
int co_static_search_tree::get(int block_index, int height, int range_left, int og_height, int value) {
    if (height == 1)
    {
        return range_left;
    }
    if(height == 2) {
        if(value <= this->tree[block_index + 1])
            return range_left;
        return range_left + (1 << (og_height - 2));
    }
    if(height == 3){
        return this->get_3_base_case(block_index, range_left, og_height, value);
    }
    if(height == 4) {
        return this->get_4_base_case(block_index, range_left, og_height, value);
    }

    
    int bottom_tree_height = bottom_tree_height_memo[height];
    int top_tree_height = height - bottom_tree_height;

    int index = this->get(block_index, top_tree_height, range_left, og_height, value);
    
    int top_tree_size = (1 << top_tree_height) - 1;

    int bottom_tree_og_height = og_height - top_tree_height;
    int bottom_tree_index = (index - range_left) >> (bottom_tree_og_height - 1);
    int bottom_tree_size = (1 << bottom_tree_height) - 1;

    int bottom_tree_block_index = block_index + top_tree_size + (bottom_tree_index << bottom_tree_height) - bottom_tree_index;
    int bottom_tree_range_left = range_left + (bottom_tree_index << (bottom_tree_og_height - 1));

    if (value <= tree[bottom_tree_block_index]){
        return this->get(bottom_tree_block_index, bottom_tree_height, bottom_tree_range_left, bottom_tree_og_height, value);
    }
    else{
        bottom_tree_index += 1;
        bottom_tree_block_index += bottom_tree_size;
        bottom_tree_range_left += (1 << (bottom_tree_og_height - 1));
        return this->get(bottom_tree_block_index, bottom_tree_height, bottom_tree_range_left, bottom_tree_og_height, value);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %r12d
movl %r8d, %r13d
movl %ecx, %r14d
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, (%rsp)
leal -0x1(%rbp), %eax
cmpl $0x3, %eax
jbe 0x1695
movslq %ebp, %rax
leaq 0x2a25(%rip), %rcx      # 0x4040
movl (%rcx,%rax,4), %ebx
subl %ebx, %ebp
movq (%rsp), %rdi
movl %r15d, %esi
movl %ebp, %edx
movl %r14d, %ecx
movl %r13d, %r8d
movl %r12d, %r9d
callq 0x15e8
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %esi
notl %esi
subl %ebp, %r13d
subl %r14d, %eax
leal -0x1(%r13), %edx
movl %edx, %ecx
sarl %cl, %eax
movl %eax, %edi
movl %ebx, %ecx
shll %cl, %edi
addl %r15d, %esi
subl %eax, %esi
movl %esi, %r15d
addl %edi, %r15d
movq (%rsp), %rcx
movq (%rcx), %rcx
movslq %r15d, %rsi
cmpl %r12d, (%rcx,%rsi,4)
jge 0x1687
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %ebx, %ecx
shll %cl, %esi
incl %eax
movl %edx, %ecx
shll %cl, %eax
notl %esi
addl %esi, %r15d
jmp 0x168b
movl %edx, %ecx
shll %cl, %eax
addl %eax, %r14d
movl %ebx, %ebp
jmp 0x1605
leaq 0x2994(%rip), %rcx      # 0x4030
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
movq (%rax), %rax
movslq %r15d, %rcx
cmpl %r12d, 0x4(%rax,%rcx,4)
jge 0x17b0
addb $-0x2, %r13b
movl $0x1, %eax
movl %r13d, %ecx
shll %cl, %eax
addl %eax, %r14d
jmp 0x17b0
addl $-0x3, %r13d
movl $0x1, %eax
movl %r13d, %ecx
shll %cl, %eax
movq (%rsp), %rcx
movq (%rcx), %rcx
movslq %r15d, %rdx
cmpl %r12d, 0x4(%rcx,%rdx,4)
jge 0x174e
cmpl %r12d, 0x14(%rcx,%rdx,4)
jge 0x177b
movl $0x2, %edx
movl %r13d, %ecx
shll %cl, %edx
addl %r14d, %edx
addl %eax, %edx
movl %edx, %r14d
jmp 0x17b0
addl $-0x4, %r13d
movl $0x1, %eax
movl %r13d, %ecx
shll %cl, %eax
movq (%rsp), %rcx
movq (%rcx), %rdx
movslq %r15d, %rsi
cmpl %r12d, 0x4(%rdx,%rsi,4)
jge 0x175d
cmpl %r12d, 0x24(%rdx,%rsi,4)
jge 0x1785
movl $0x6, %edi
movl %r13d, %ecx
shll %cl, %edi
addl %r14d, %edi
xorl %r14d, %r14d
cmpl %r12d, 0x34(%rdx,%rsi,4)
jmp 0x179a
xorl %esi, %esi
cmpl %r12d, 0x8(%rcx,%rdx,4)
cmovll %eax, %esi
addl %esi, %r14d
jmp 0x17b0
cmpl %r12d, 0xc(%rdx,%rsi,4)
jge 0x17a3
movl $0x2, %edi
movl %r13d, %ecx
shll %cl, %edi
addl %r14d, %edi
xorl %r14d, %r14d
cmpl %r12d, 0x1c(%rdx,%rsi,4)
jmp 0x179a
addl %r14d, %eax
addl %eax, %eax
movl %eax, %r14d
jmp 0x17b0
movl $0x4, %edi
movl %r13d, %ecx
shll %cl, %edi
addl %r14d, %edi
xorl %r14d, %r14d
cmpl %r12d, 0x28(%rdx,%rsi,4)
cmovll %eax, %r14d
addl %edi, %r14d
jmp 0x17b0
xorl %ecx, %ecx
cmpl %r12d, 0x10(%rdx,%rsi,4)
cmovll %eax, %ecx
addl %ecx, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq