// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movl %r9d, 0xc(%rsp)
movl %r8d, %r15d
movl %ecx, %r14d
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rbx
leal -0x1(%rbp), %eax
cmpl $0x3, %eax
jbe 0x1608
movslq %ebp, %rax
leaq 0x1aaa(%rip), %rcx      # 0x3030
movl (%rcx,%rax,4), %r13d
subl %r13d, %ebp
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %r14d, %ecx
movl %r15d, %r8d
movl 0xc(%rsp), %r9d
callq 0x1548
pushq $-0x1
popq %r9
movl %r9d, %esi
movl %ebp, %ecx
shll %cl, %esi
subl %ebp, %r15d
subl %r14d, %eax
leal -0x1(%r15), %edx
movl %edx, %ecx
sarl %cl, %eax
notl %esi
addl %r12d, %esi
movl %eax, %edi
movl %r13d, %ecx
shll %cl, %edi
subl %eax, %esi
addl %edi, %esi
movq (%rbx), %rdi
movslq %esi, %r12
movl %r9d, %esi
shll %cl, %esi
xorl %r9d, %r9d
movl 0xc(%rsp), %ecx
cmpl %ecx, (%rdi,%r12,4)
setl %r9b
notl %esi
movl $0x0, %ecx
cmovgel %ecx, %esi
addl %eax, %r9d
movl %edx, %ecx
shll %cl, %r9d
addl %esi, %r12d
addl %r9d, %r14d
movl %r13d, %ebp
jmp 0x1570
leaq 0x1a11(%rip), %rcx      # 0x3020
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%rsp), %rax
movq (%rax), %rax
movslq %r12d, %rcx
movl 0xc(%rsp), %edx
cmpl %edx, 0x4(%rax,%rcx,4)
jge 0x163c
addb $-0x2, %r15b
pushq $0x1
popq %rax
movl %r15d, %ecx
shll %cl, %eax
addl %eax, %r14d
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
movl %r12d, %esi
movl %r14d, %edx
movl %r15d, %ecx
movl 0xc(%rsp), %r8d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2348
movq 0x10(%rsp), %rdi
movl %r12d, %esi
movl %r14d, %edx
movl %r15d, %ecx
movl 0xc(%rsp), %r8d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x238a