// File: 6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/static_search_trees.cpp
// Function: co_static_search_tree::get_4_base_case(int, int, int, int)
inline int co_static_search_tree::get_4_base_case(int block_index, int range_left, int og_height, int value) {
    /*
                                    0
                    1                                   2
            3               6                   9                 12
        4       5       7       8           10       11      13          14                    
    */
    int leafs_og_height = og_height - 3;
    int leafs_range_length = (1 << (leafs_og_height - 1));
    if(value <= this->tree[block_index + 1]) {
        if(value <= this->tree[block_index + 3]) {
            if(value <= this->tree[block_index + 4])
                return range_left;
            return range_left + leafs_range_length;
        }
        else
        { //6
            if(value <= this->tree[block_index + 7])
                return range_left + (leafs_range_length << 1);
            return range_left + (leafs_range_length << 1) + leafs_range_length;
        }
    } else //2
    {
        if(value <= this->tree[block_index + 9]) {
            if(value <= this->tree[block_index + 10]) return  range_left + (leafs_range_length << 2);
            return range_left + (leafs_range_length << 2) + leafs_range_length;
        }
        else //12 
        {
            if(value <= this->tree[block_index + 13])
                return range_left + (leafs_range_length << 2) + (leafs_range_length << 1);
            return range_left + (leafs_range_length << 2) + (leafs_range_length << 1) + leafs_range_length;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
subl $0x3, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movl $0x1, %eax
shll %cl, %eax
movq -0x30(%rbp), %rcx
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
movq (%rcx), %rcx
movl -0x14(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x3e5a
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %eax
movq (%rcx), %rcx
movl -0x14(%rbp), %edx
addl $0x3, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x3e1b
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %eax
movq (%rcx), %rcx
movl -0x14(%rbp), %edx
addl $0x4, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x3e0d
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ef4
movl -0x18(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ef4
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %eax
movq (%rcx), %rcx
movl -0x14(%rbp), %edx
addl $0x7, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x3e45
movl -0x18(%rbp), %eax
movl -0x28(%rbp), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x3ef4
movl -0x18(%rbp), %eax
movl -0x28(%rbp), %ecx
shll %ecx
addl %ecx, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ef4
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %eax
movq (%rcx), %rcx
movl -0x14(%rbp), %edx
addl $0x9, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x3ead
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %eax
movq (%rcx), %rcx
movl -0x14(%rbp), %edx
addl $0xa, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x3e9a
movl -0x18(%rbp), %eax
movl -0x28(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x3ef4
movl -0x18(%rbp), %eax
movl -0x28(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ef4
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %eax
movq (%rcx), %rcx
movl -0x14(%rbp), %edx
addl $0xd, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x3edc
movl -0x18(%rbp), %eax
movl -0x28(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl -0x28(%rbp), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x3ef4
movl -0x18(%rbp), %eax
movl -0x28(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl -0x28(%rbp), %ecx
shll %ecx
addl %ecx, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)