// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movl 0x10(%rbp), %eax
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, -0x48(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x18(%rbp), %ecx
subl $0x2, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x10(%rbp), %eax
je 0x1ccc
movq -0x48(%rbp), %rax
movl -0x20(%rbp), %edx
movslq -0x24(%rbp), %rcx
movl %edx, 0x20(%rax,%rcx,4)
movl -0x1c(%rbp), %eax
movl -0x14(%rbp), %ecx
addl -0x2c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1c90
movq -0x48(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
callq 0x3f40
movl %eax, -0x20(%rbp)
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
jmp 0x1cb9
movq -0x48(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
callq 0x3fe0
movl %eax, -0x20(%rbp)
movl -0x28(%rbp), %eax
shll %eax
orl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x2c(%rbp), %eax
sarl %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1c4d
movq -0x48(%rbp), %rax
movl 0x10(%rbp), %edx
movq (%rax), %rax
movl -0xc(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0x1, -0x30(%rbp)
jl 0x1d88
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %eax
sarl %eax
movl %eax, -0x28(%rbp)
movslq -0x30(%rbp), %rax
movl 0x20(%rdi,%rax,4), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %esi
movl -0x30(%rbp), %edx
movl -0x28(%rbp), %ecx
callq 0x3f40
movq -0x48(%rbp), %rdi
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %esi
movl -0x30(%rbp), %edx
movl -0x28(%rbp), %ecx
callq 0x3fe0
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, -0x3c(%rbp)
movq (%rax), %rdi
movl -0xc(%rbp), %ecx
addl -0x38(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %eax
addl -0x3c(%rbp), %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
callq 0x31c0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movl (%rcx), %edx
movq (%rax), %rax
movl -0xc(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1ceb
movq -0x48(%rbp), %rax
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)