// File: 6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/static_search_trees.cpp
// Function: CA_static_search_tree::update(int, int, int, int, int, int, int, int)
void CA_static_search_tree::update(int tree_l, int num_inner_nodes, int temp_root, int h, int arr_l, int arr_r, int index, int value) {
    if (arr_l == arr_r)
    {
        int last_subtree_size = min((1 << (this->height-((h>>2)<<2))) - 1, 15);
        int real_subtree_root = ((num_inner_nodes<<4)-num_inner_nodes) + (tree_l-num_inner_nodes)*last_subtree_size;
        // printf("update at index %d, real index %d, value %d\n", arr_l, tree_l + temp_root, value);
        this->tree[real_subtree_root + temp_root] = value;
        return;
    }
    int old_tree_l = tree_l, old_temp_root = temp_root;
    int mid = (arr_l + arr_r) >> 1;
    int new_tree_l = 0, new_tree_r = 0;
    if (h > 0 && (h+1) & 3 == 0) {
        h++;
        int old_num_inner_nodes = num_inner_nodes;
        num_inner_nodes += (1 << (h-4));
        // update tree_l
        int mid = (arr_l + arr_r) / 2;
        new_tree_l = (tree_l << 4) + ((temp_root-8) << 1) + 1;
        new_tree_r = (tree_l << 4) + ((temp_root-8) << 1) + 2;
        if (index <= mid) {
            arr_r = mid;
            tree_l = new_tree_l;
        } else {
            arr_l = mid + 1;
            tree_l = new_tree_r;
        }
        temp_root = 1;
        if (h == this->height - 1) {
            int last_subtree_size = min((1 << (this->height-((h>>2)<<2))) - 1, 15);
            int real_subtree_root = ((num_inner_nodes<<4)-num_inner_nodes) + (tree_l-num_inner_nodes)*last_subtree_size;
            this->tree[real_subtree_root + temp_root] = value;
            // printf("here....\n");
            int real_tree_l = ((num_inner_nodes<<4)-num_inner_nodes) + (new_tree_l-num_inner_nodes)*last_subtree_size;
            int real_tree_r = real_tree_l + last_subtree_size;
            int old_real_subtree_root = (old_tree_l<<4) - old_tree_l;
            this->tree[old_real_subtree_root + old_temp_root] = this->merge(this->tree[real_tree_l + 1], this->tree[real_tree_r + 1]);
            return;
        }
    }
    mid = (arr_l + arr_r) >> 1;
    int left_child = temp_root << 1;
    int right_child = (temp_root << 1) + 1;
    h++;
    if (index <= mid)
    {
        this->update(tree_l, num_inner_nodes, left_child, h, arr_l, mid, index, value);
    }
    else
    {
        this->update(tree_l, num_inner_nodes, right_child, h, mid + 1, arr_r, index, value);
    }
    int last_subtree_size = min((1 << (this->height-((h>>2)<<2))) - 1, 15);
    int real_subtree_root = ((num_inner_nodes<<4)-num_inner_nodes) + (tree_l-num_inner_nodes)*last_subtree_size;
    this->tree[real_subtree_root + temp_root] = this->merge(this->tree[real_subtree_root + left_child], this->tree[real_subtree_root + right_child]);
    if (old_tree_l != tree_l) {
        int last_subtree_size = min((1 << (this->height-((h>>2)<<2))) - 1, 15);
        int real_tree_l = ((num_inner_nodes<<4)-num_inner_nodes) + (new_tree_l-num_inner_nodes)*last_subtree_size;
        int real_tree_r = real_tree_l + last_subtree_size;
        int old_real_subtree_root = (old_tree_l << 4) - old_tree_l;
        this->tree[old_real_subtree_root + old_temp_root] = this->merge(this->tree[real_tree_l + 1], this->tree[real_tree_r + 1]);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
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, -0xa0(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jne 0x2460
movq -0xa0(%rbp), %rax
movl 0x14(%rax), %ecx
movl -0x18(%rbp), %eax
sarl $0x2, %eax
shll $0x2, %eax
subl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
movl $0xf, -0x28(%rbp)
leaq -0x24(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x3f00
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x20(%rbp)
movl -0x10(%rbp), %ecx
shll $0x4, %ecx
subl -0x10(%rbp), %ecx
movl -0xc(%rbp), %edx
subl -0x10(%rbp), %edx
imull -0x20(%rbp), %edx
addl %edx, %ecx
movl %ecx, -0x2c(%rbp)
movl 0x20(%rbp), %edx
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
addl -0x14(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x282a
movl -0xc(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x1c(%rbp), %eax
addl 0x10(%rbp), %eax
sarl %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0x0, -0x18(%rbp)
jle 0x261f
movl -0x18(%rbp), %eax
addl $0x1, %eax
andl $0x0, %eax
cmpl $0x0, %eax
je 0x261f
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x18(%rbp), %ecx
subl $0x4, %ecx
movl $0x1, %eax
shll %cl, %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x1c(%rbp), %eax
addl 0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x48(%rbp)
movl -0xc(%rbp), %eax
shll $0x4, %eax
movl -0x14(%rbp), %ecx
subl $0x8, %ecx
shll %ecx
addl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0xc(%rbp), %eax
shll $0x4, %eax
movl -0x14(%rbp), %ecx
subl $0x8, %ecx
shll %ecx
addl %ecx, %eax
addl $0x2, %eax
movl %eax, -0x40(%rbp)
movl 0x18(%rbp), %eax
cmpl -0x48(%rbp), %eax
jg 0x2516
movl -0x48(%rbp), %eax
movl %eax, 0x10(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x2525
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0xc(%rbp)
movq -0xa0(%rbp), %rcx
movl $0x1, -0x14(%rbp)
movl -0x18(%rbp), %eax
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x261d
movq -0xa0(%rbp), %rax
movl 0x14(%rax), %ecx
movl -0x18(%rbp), %eax
sarl $0x2, %eax
shll $0x2, %eax
subl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, -0x50(%rbp)
movl $0xf, -0x54(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x3f00
movq -0xa0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x10(%rbp), %eax
shll $0x4, %eax
subl -0x10(%rbp), %eax
movl -0xc(%rbp), %ecx
subl -0x10(%rbp), %ecx
imull -0x4c(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x58(%rbp)
movl 0x20(%rbp), %edx
movq (%rdi), %rax
movl -0x58(%rbp), %ecx
addl -0x14(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x10(%rbp), %eax
shll $0x4, %eax
subl -0x10(%rbp), %eax
movl -0x3c(%rbp), %ecx
subl -0x10(%rbp), %ecx
imull -0x4c(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x30(%rbp), %eax
shll $0x4, %eax
subl -0x30(%rbp), %eax
movl %eax, -0x64(%rbp)
movq (%rdi), %rax
movl -0x5c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %esi
movq (%rdi), %rax
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
callq 0x4080
movl %eax, %edx
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x282a
jmp 0x261f
movl -0x1c(%rbp), %eax
addl 0x10(%rbp), %eax
sarl %eax
movl %eax, -0x38(%rbp)
movl -0x14(%rbp), %eax
shll %eax
movl %eax, -0x68(%rbp)
movl -0x14(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl 0x18(%rbp), %eax
cmpl -0x38(%rbp), %eax
jg 0x2685
movq -0xa0(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x68(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x1c(%rbp), %r9d
movl -0x38(%rbp), %r11d
movl 0x18(%rbp), %r10d
movl 0x20(%rbp), %eax
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x23b0
jmp 0x26be
movq -0xa0(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x6c(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x38(%rbp), %r9d
addl $0x1, %r9d
movl 0x10(%rbp), %r11d
movl 0x18(%rbp), %r10d
movl 0x20(%rbp), %eax
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x23b0
movq -0xa0(%rbp), %rax
movl 0x14(%rax), %ecx
movl -0x18(%rbp), %eax
sarl $0x2, %eax
shll $0x2, %eax
subl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, -0x74(%rbp)
movl $0xf, -0x78(%rbp)
leaq -0x74(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3f00
movq -0xa0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x70(%rbp)
movl -0x10(%rbp), %eax
shll $0x4, %eax
subl -0x10(%rbp), %eax
movl -0xc(%rbp), %ecx
subl -0x10(%rbp), %ecx
imull -0x70(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x7c(%rbp)
movq (%rdi), %rax
movl -0x7c(%rbp), %ecx
addl -0x68(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %esi
movq (%rdi), %rax
movl -0x7c(%rbp), %ecx
addl -0x6c(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
callq 0x4080
movl %eax, %edx
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movl -0x7c(%rbp), %ecx
addl -0x14(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
cmpl -0xc(%rbp), %eax
je 0x282a
movq -0xa0(%rbp), %rax
movl 0x14(%rax), %ecx
movl -0x18(%rbp), %eax
sarl $0x2, %eax
shll $0x2, %eax
subl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, -0x84(%rbp)
movl $0xf, -0x88(%rbp)
leaq -0x84(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3f00
movq -0xa0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x80(%rbp)
movl -0x10(%rbp), %eax
shll $0x4, %eax
subl -0x10(%rbp), %eax
movl -0x3c(%rbp), %ecx
subl -0x10(%rbp), %ecx
imull -0x80(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
addl -0x80(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x30(%rbp), %eax
shll $0x4, %eax
subl -0x30(%rbp), %eax
movl %eax, -0x94(%rbp)
movq (%rdi), %rax
movl -0x8c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %esi
movq (%rdi), %rax
movl -0x90(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
callq 0x4080
movl %eax, %edx
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movl -0x94(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)