// 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::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
xorl %r10d, %r10d
movl %edx, %r11d
movl $0x0, %r13d
movl %edx, -0x4(%rsp)
cmpl $0x1, %edx
je 0x1b50
movl %ecx, %eax
addb $-0x2, %r8b
movl $0x1, %r14d
movl %r8d, %ecx
shll %cl, %r14d
leaq 0x24(%rdi), %r8
xorl %r13d, %r13d
movl $0x1, %r15d
movl $0x2, %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r10d, %r10d
movl %r9d, %edx
movl %r13d, (%r8)
leal (%rax,%r14), %ebx
cmpl %r9d, %ebx
jle 0x1ae2
testb $0x1, %r15b
jne 0x1b22
movl %r15d, %ecx
andl %r12d, %ecx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
shll %cl, %ebx
leal (%r10,%r10), %r13d
notl %ebx
andl %r13d, %ebx
movq %rax, %r9
movl %ebp, %eax
subl %ecx, %eax
incl %ebx
movl %ebx, %r13d
shll %cl, %r13d
cltq
subl %ebx, %r13d
addl 0x20(%rdi,%rax,4), %r13d
movq %r9, %rax
movl %edx, %r9d
jmp 0x1b25
testb $0x1, %r15b
jne 0x1b2a
movl %r15d, %ecx
andl %r12d, %ecx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
shll %cl, %r13d
leal 0x1(,%r10,2), %eax
notl %r13d
andl %eax, %r13d
movl %ebp, %eax
subl %ecx, %eax
cltq
leal 0x1(%r13), %r9d
shll %cl, %r9d
notl %r13d
addl %r9d, %r13d
addl 0x20(%rdi,%rax,4), %r13d
movl %edx, %r9d
jmp 0x1b2e
incl %r13d
addl %r10d, %r10d
jmp 0x1b38
addl $0x2, %r13d
leal 0x1(,%r10,2), %r10d
movl %ebx, %eax
sarl %r14d
incq %r15
incl %ebp
decl %r12d
addq $0x4, %r8
cmpq %r15, %r11
jne 0x1a99
movq (%rdi), %rax
addl %esi, %r13d
movslq %r13d, %rcx
movl 0x38(%rsp), %r8d
movl %r8d, (%rax,%rcx,4)
movl -0x4(%rsp), %ecx
cmpl $0x2, %ecx
jl 0x1c2b
movl $0x1, %r8d
subl %ecx, %r8d
leaq -0x1(%r11), %rdx
movl 0x1c(%rdi,%r11,4), %r9d
testb $0x1, %dl
jne 0x1baf
movl %r8d, %ecx
andl %edx, %ecx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
shll %cl, %ebp
notl %ebp
andl %r10d, %ebp
movl %r11d, %r14d
subl %ecx, %r14d
orl $0x1, %ebp
movl %ebp, %ebx
shll %cl, %ebx
movslq %r14d, %rcx
subl %ebp, %ebx
addl 0x20(%rdi,%rcx,4), %ebx
jmp 0x1bb3
leal 0x1(%r9), %ebx
testb $0x1, %dl
jne 0x1beb
movl %r8d, %ecx
andl %edx, %ecx
movl %r10d, %ebp
orl $0x1, %ebp
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
shll %cl, %r14d
notl %r14d
andl %ebp, %r14d
subl %ecx, %r11d
movslq %r11d, %r11
leal 0x1(%r14), %ebp
shll %cl, %ebp
notl %r14d
addl %ebp, %r14d
addl 0x20(%rdi,%r11,4), %r14d
jmp 0x1bef
leal 0x2(%r9), %r14d
sarl %r10d
addl %esi, %ebx
movslq %ebx, %rcx
addl %esi, %r14d
movslq %r14d, %r11
movl (%rax,%rcx,4), %ecx
movl (%rax,%r11,4), %r11d
cmpl %r11d, %ecx
cmovgl %ecx, %r11d
addl %esi, %r9d
movslq %r9d, %rcx
movl %r11d, (%rax,%rcx,4)
incl %r8d
movq %rdx, %rcx
incq %rcx
movq %rdx, %r11
cmpq $0x2, %rcx
jg 0x1b78
movslq %esi, %rcx
movl (%rax,%rcx,4), %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq