// File: /workspace/github_cpp_makefile_star2_O2/6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/static_search_trees.cpp
// Function: co_static_search_tree::range_update(int, int, int, int, int, int, int*)
void co_static_search_tree::range_update(int block_index, int height, int range_left,  int og_height, int query_range_left, int query_range_right, int* items) {
    if (height == 1)
    {

        this->tree[block_index] = items[range_left];
        return;
    }

    //update bottom tree
    int bottom_tree_height = bottom_tree_height_memo[height];

    int top_tree_height = height - bottom_tree_height;
    
    int top_tree_size = (1 << top_tree_height) - 1;

    int bottom_tree_og_height = og_height - top_tree_height;
    int bottom_tree_size = (1 << bottom_tree_height) - 1;

    int bottom_tree_index_range_left = (query_range_left - range_left) >> (bottom_tree_og_height - 1);
    int bottom_tree_index_range_right = (query_range_right - range_left) >> (bottom_tree_og_height - 1);

    for (int bottom_tree_index = bottom_tree_index_range_left; bottom_tree_index <= bottom_tree_index_range_right; ++bottom_tree_index) {
        int bottom_tree_block_index = block_index + top_tree_size + (bottom_tree_index << bottom_tree_height) - bottom_tree_index;
        int bottom_tree_range_left = range_left + (bottom_tree_index << (bottom_tree_og_height - 1));
        this->range_update(bottom_tree_block_index, bottom_tree_height, bottom_tree_range_left, bottom_tree_og_height, max(query_range_left, bottom_tree_range_left), min(query_range_right, bottom_tree_range_left + (1 << (bottom_tree_og_height - 1)) - 1), items);
    }

    bottom_tree_index_range_left = bottom_tree_index_range_left & (~1);
    int range_lenght = (1 << (bottom_tree_og_height - 1));
    for (int bottom_tree_index = bottom_tree_index_range_left; bottom_tree_index <= bottom_tree_index_range_right; bottom_tree_index += 2)
    {
        int bottom_tree_block_index = block_index + top_tree_size + (bottom_tree_index << bottom_tree_height) - bottom_tree_index;
        int bottom_tree_range_left = range_left + (bottom_tree_index << (bottom_tree_og_height - 1));
        items[bottom_tree_range_left] = max(this->tree[bottom_tree_block_index], this->tree[bottom_tree_block_index + bottom_tree_size]);
    }

    //update upper tree
    this->range_update(block_index, top_tree_height, range_left, og_height, query_range_left, query_range_right, items);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, 0x20(%rsp)
movl %ecx, %ebp
movq %rdi, 0x8(%rsp)
movq 0x88(%rsp), %rbx
movl 0x80(%rsp), %eax
movl %r9d, 0x34(%rsp)
subl %ecx, %r9d
movl %r9d, 0x1c(%rsp)
subl %ecx, %eax
movl %eax, 0x18(%rsp)
leal -0x1(%rbp), %eax
movl %eax, 0x30(%rsp)
leal -0x1(%rsi), %r14d
movq %rsi, 0x38(%rsp)
leal -0x2(%rsi), %eax
movl %eax, 0x10(%rsp)
movl %r14d, 0x14(%rsp)
cmpl $0x1, %edx
je 0x1849
movslq %edx, %rax
leaq 0x190d(%rip), %rcx      # 0x3030
movl (%rcx,%rax,4), %edi
subl %edi, %edx
pushq $-0x1
popq %rsi
movl %esi, %r8d
movl %edx, %ecx
shll %cl, %r8d
movl 0x20(%rsp), %eax
movl %edi, 0x4(%rsp)
movl %edi, %ecx
shll %cl, %esi
movl %esi, 0x24(%rsp)
movl %edx, 0x2c(%rsp)
subl %edx, %eax
movq %rax, 0x40(%rsp)
leal -0x1(%rax), %ecx
movl 0x1c(%rsp), %r13d
sarl %cl, %r13d
movl 0x18(%rsp), %r15d
movl %ecx, (%rsp)
sarl %cl, %r15d
subl %r13d, %r14d
movl %r8d, 0x28(%rsp)
subl %r8d, %r14d
movl %r13d, %r12d
cmpl %r15d, %r12d
jg 0x17d4
movl %r12d, %esi
movl 0x4(%rsp), %edx
movl %edx, %ecx
shll %cl, %esi
movl %r12d, %eax
movl (%rsp), %ecx
shll %cl, %eax
addl %r14d, %esi
addl %ebp, %eax
movl 0x34(%rsp), %r9d
cmpl %r9d, %eax
cmovgl %eax, %r9d
incl %r12d
movl %r12d, %r10d
shll %cl, %r10d
addl 0x30(%rsp), %r10d
movl 0x80(%rsp), %ecx
cmpl %ecx, %r10d
cmovgel %ecx, %r10d
movq 0x8(%rsp), %rdi
movl %eax, %ecx
movq 0x40(%rsp), %r8
pushq %rbx
pushq %r10
callq 0x16b8
addq $0x10, %rsp
decl %r14d
jmp 0x1772
andl $-0x2, %r13d
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x10(%rsp), %edx
movl 0x28(%rsp), %ecx
subl %ecx, %edx
subl 0x24(%rsp), %edx
subl %r13d, %edx
movl 0x14(%rsp), %r14d
movl %r14d, %esi
subl %ecx, %esi
subl %r13d, %esi
cmpl %r15d, %r13d
jg 0x1840
movl %r13d, %edi
movl 0x4(%rsp), %ecx
shll %cl, %edi
movl %r13d, %r8d
movl (%rsp), %ecx
shll %cl, %r8d
leal (%rsi,%rdi), %ecx
addl %ebp, %r8d
movslq %ecx, %rcx
addl %edx, %edi
movslq %edi, %rdi
movl (%rax,%rcx,4), %ecx
movl (%rax,%rdi,4), %edi
cmpl %edi, %ecx
cmovgl %ecx, %edi
movslq %r8d, %rcx
movl %edi, (%rbx,%rcx,4)
addl $0x2, %r13d
addl $-0x2, %edx
addl $-0x2, %esi
jmp 0x17fe
movl 0x2c(%rsp), %edx
jmp 0x1710
movslq %ebp, %rax
movl (%rbx,%rax,4), %eax
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x38(%rsp), %rdx
movl %eax, (%rcx,%rdx,4)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq