// File: /workspace/github_cpp_makefile_star2_O3/6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/static_search_trees.cpp
// Function: co_static_search_tree::update_tree_height_pwr_2(int, int, int, int, int, int)
int co_static_search_tree::update_tree_height_pwr_2(int block_index, int height, int range_left, int og_height, int index, int value) {
    int inner_block_index = 0;
    int depth = 1;
    int path = 0;
    int length = (1 << (og_height - 2));
    while (depth != height)
    {
        this->block_index_memo[depth] = inner_block_index;
        if (index < range_left + length)
        {
            inner_block_index = this->left_child(inner_block_index, depth, path);
            path <<= 1;
        }
        else {
            inner_block_index = this->right_child(inner_block_index, depth, path);
            path = (path << 1) | 1;
            range_left += length;
        }
        length >>= 1;
        depth += 1;
    }
    this->tree[block_index + inner_block_index] = value;
    for (int i = height - 1; i >= 1; --i) {
        path >>= 1;
        int inner_block_index = this->block_index_memo[i];
        int left_child_inner_block_index = this->left_child(inner_block_index, i, path);
        int right_child_inner_block_index = this->right_child(inner_block_index, i, path);
        this->tree[block_index + inner_block_index] = max(this->tree[block_index + left_child_inner_block_index], this->tree[block_index + right_child_inner_block_index]);
    }
    return this->tree[block_index];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %ecx, %eax
movl 0x38(%rsp), %r10d
movslq %esi, %rcx
cmpl $0x1, %edx
jne 0x1a53
movq (%rdi), %rax
movl %r10d, (%rax,%rcx,4)
jmp 0x1bf7
movq %rcx, -0x8(%rsp)
movl %edx, %r11d
addb $-0x2, %r8b
movl $0x1, %r14d
movl %r8d, %ecx
shll %cl, %r14d
leaq -0x1(%r11), %r15
xorl %ebx, %ebx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
xorl %r8d, %r8d
movq %rbx, %r12
incq %rbx
movl %r13d, 0x24(%rdi,%r12,4)
leal (%rax,%r14), %r10d
cmpl %r9d, %r10d
jle 0x1acb
testb $0x1, %bl
jne 0x1b0c
movl %ebx, %ecx
andl %ebp, %ecx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
shll %cl, %r10d
addl %r8d, %r8d
notl %r10d
andl %r8d, %r10d
incl %r12d
orl $0x1, %r12d
subl %ecx, %r12d
incl %r10d
movl %r10d, %r13d
shll %cl, %r13d
movslq %r12d, %rcx
subl %r10d, %r13d
addl 0x20(%rdi,%rcx,4), %r13d
jmp 0x1b23
testb $0x1, %bl
jne 0x1b14
movl %ebx, %ecx
andl %ebp, %ecx
leal 0x1(,%r8,2), %r8d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
shll %cl, %r13d
notl %r13d
andl %r8d, %r13d
incl %r12d
orl $0x1, %r12d
subl %ecx, %r12d
movslq %r12d, %rax
leal 0x1(%r13), %r12d
shll %cl, %r12d
notl %r13d
addl %r12d, %r13d
addl 0x20(%rdi,%rax,4), %r13d
jmp 0x1b20
incl %r13d
addl %r8d, %r8d
jmp 0x1b23
addl $0x2, %r13d
leal 0x1(,%r8,2), %r8d
movl %r10d, %eax
sarl %r14d
decl %ebp
cmpq %rbx, %r15
jne 0x1a7c
movq (%rdi), %rax
addl %esi, %r13d
movslq %r13d, %rcx
movl 0x38(%rsp), %r9d
movl %r9d, (%rax,%rcx,4)
cmpl $0x2, %r11d
jl 0x1bf2
movl $0x1, %r9d
subl %edx, %r9d
leaq -0x1(%r11), %rdx
movl 0x1c(%rdi,%r11,4), %ebx
testb $0x1, %dl
jne 0x1bae
movl %r9d, %ecx
andl %edx, %ecx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
shll %cl, %ebp
notl %ebp
movl %r8d, %r14d
andl %ebp, %r14d
subl %ecx, %r11d
movslq %r11d, %r10
movl 0x20(%rdi,%r10,4), %r15d
orl $0x1, %r14d
movl %r14d, %r10d
shll %cl, %r10d
subl %r14d, %r10d
movl %r8d, %r11d
orl $0x1, %r11d
andl %ebp, %r11d
leal 0x1(%r11), %ebp
shll %cl, %ebp
addl %r15d, %r10d
notl %r11d
addl %r15d, %r11d
addl %ebp, %r11d
jmp 0x1bb6
leal 0x1(%rbx), %r10d
leal 0x2(%rbx), %r11d
sarl %r8d
addl %esi, %r10d
movslq %r10d, %rcx
addl %esi, %r11d
movslq %r11d, %r10
movl (%rax,%rcx,4), %ecx
movl (%rax,%r10,4), %r10d
cmpl %r10d, %ecx
cmovgl %ecx, %r10d
addl %esi, %ebx
movslq %ebx, %rcx
movl %r10d, (%rax,%rcx,4)
incl %r9d
movq %rdx, %rcx
incq %rcx
movq %rdx, %r11
cmpq $0x2, %rcx
ja 0x1b56
movq -0x8(%rsp), %rcx
movl (%rax,%rcx,4), %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop