// File: 6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/static_search_trees.cpp
// Function: co_static_search_tree::update_3_base_case(int, int, int, int, int)
inline int co_static_search_tree::update_3_base_case(int block_index, int range_left, int og_height, int index, int value) {
    /*
                            0
                    1               4
                2       3       5       6
    */
    int leafs_og_height = og_height - 2;
    int leaf_index = (index - range_left) >> (leafs_og_height - 1);
    if(leaf_index == 0) {
        this->tree[block_index + 2] = value;
        this->tree[block_index + 1] = max(this->tree[block_index + 2], this->tree[block_index + 3]);
        this->tree[block_index + 0] = max(this->tree[block_index + 1], this->tree[block_index + 4]);
    }
    else if(leaf_index == 1) {
        this->tree[block_index + 3] = value;
        this->tree[block_index + 1] = max(this->tree[block_index + 2], this->tree[block_index + 3]);
        this->tree[block_index + 0] = max(this->tree[block_index + 1], this->tree[block_index + 4]);
    }
    else if(leaf_index == 2) {
        this->tree[block_index + 5] = value;
        this->tree[block_index + 4] = max(this->tree[block_index + 5], this->tree[block_index + 6]);
        this->tree[block_index + 0] = max(this->tree[block_index + 1], this->tree[block_index + 4]);
    }
    else if(leaf_index == 3) {
        this->tree[block_index + 6] = value;
        this->tree[block_index + 4] = max(this->tree[block_index + 5], this->tree[block_index + 6]);
        this->tree[block_index + 0] = max(this->tree[block_index + 1], this->tree[block_index + 4]);
    }
    return this->tree[block_index];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
subl -0x10(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
sarl %cl, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x32e8
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %esi
movq (%rax), %rcx
movl -0xc(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movl %esi, (%rcx,%rdx,4)
movq (%rax), %rdi
movl -0xc(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %eax
addl $0x3, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
callq 0x31c0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl (%rcx), %esi
movq (%rax), %rcx
movl -0xc(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movl %esi, (%rcx,%rdx,4)
movq (%rax), %rdi
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %eax
addl $0x4, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
callq 0x31c0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl (%rcx), %edx
movq (%rax), %rax
movl -0xc(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x34e4
cmpl $0x1, -0x24(%rbp)
jne 0x3391
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %esi
movq (%rax), %rcx
movl -0xc(%rbp), %edx
addl $0x3, %edx
movslq %edx, %rdx
movl %esi, (%rcx,%rdx,4)
movq (%rax), %rdi
movl -0xc(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %eax
addl $0x3, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
callq 0x31c0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl (%rcx), %esi
movq (%rax), %rcx
movl -0xc(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movl %esi, (%rcx,%rdx,4)
movq (%rax), %rdi
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %eax
addl $0x4, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
callq 0x31c0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl (%rcx), %edx
movq (%rax), %rax
movl -0xc(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x34e2
cmpl $0x2, -0x24(%rbp)
jne 0x343a
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %esi
movq (%rax), %rcx
movl -0xc(%rbp), %edx
addl $0x5, %edx
movslq %edx, %rdx
movl %esi, (%rcx,%rdx,4)
movq (%rax), %rdi
movl -0xc(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %eax
addl $0x6, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
callq 0x31c0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl (%rcx), %esi
movq (%rax), %rcx
movl -0xc(%rbp), %edx
addl $0x4, %edx
movslq %edx, %rdx
movl %esi, (%rcx,%rdx,4)
movq (%rax), %rdi
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %eax
addl $0x4, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
callq 0x31c0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl (%rcx), %edx
movq (%rax), %rax
movl -0xc(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x34e0
cmpl $0x3, -0x24(%rbp)
jne 0x34de
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %esi
movq (%rax), %rcx
movl -0xc(%rbp), %edx
addl $0x6, %edx
movslq %edx, %rdx
movl %esi, (%rcx,%rdx,4)
movq (%rax), %rdi
movl -0xc(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %eax
addl $0x6, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
callq 0x31c0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl (%rcx), %esi
movq (%rax), %rcx
movl -0xc(%rbp), %edx
addl $0x4, %edx
movslq %edx, %rdx
movl %esi, (%rcx,%rdx,4)
movq (%rax), %rdi
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %eax
addl $0x4, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
callq 0x31c0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl (%rcx), %edx
movq (%rax), %rax
movl -0xc(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x34e0
jmp 0x34e2
jmp 0x34e4
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)