// 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::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, %r10d
movl %edx, %ebx
movq 0x88(%rsp), %r15
movl 0x80(%rsp), %ebp
leal -0x1(%rsi), %eax
movl %eax, (%rsp)
movq %rsi, 0x38(%rsp)
leal -0x2(%rsi), %eax
movl %eax, 0x14(%rsp)
movl %r9d, %eax
subl %ecx, %eax
movl %eax, 0x1c(%rsp)
movl %ebp, %eax
subl %ecx, %eax
movl %eax, 0x18(%rsp)
movq %r10, 0x40(%rsp)
movl %r9d, 0xc(%rsp)
cmpl $0x1, %ebx
je 0x19d9
movslq %ebx, %rax
leaq 0x27f7(%rip), %rcx      # 0x4040
movl (%rcx,%rax,4), %r12d
subl %r12d, %ebx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebx, %ecx
shll %cl, %eax
movl %eax, 0x4(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %r12d, %ecx
shll %cl, %eax
movl %eax, 0x24(%rsp)
movl 0x20(%rsp), %eax
movl %eax, %r8d
movl %ebx, 0x28(%rsp)
subl %ebx, %r8d
leal -0x1(%r8), %r11d
movl 0x1c(%rsp), %eax
movl %r11d, %ecx
sarl %cl, %eax
movl 0x18(%rsp), %edx
sarl %cl, %edx
movl %eax, 0x8(%rsp)
cmpl %edx, %eax
movl %edx, 0x10(%rsp)
jg 0x1952
leal -0x1(%r10), %eax
movl %eax, 0x2c(%rsp)
movl (%rsp), %r14d
movl 0x8(%rsp), %eax
subl %eax, %r14d
subl 0x4(%rsp), %r14d
movl %eax, %r13d
movl %r12d, 0x30(%rsp)
movl %r13d, %esi
movl %r12d, %ecx
shll %cl, %esi
movl %r13d, %eax
movl %r11d, %ecx
shll %cl, %eax
addl %r14d, %esi
addl %r10d, %eax
cmpl %r9d, %eax
movl 0xc(%rsp), %r9d
cmovgl %eax, %r9d
leal 0x1(%r13), %ecx
movl %ecx, 0x34(%rsp)
movl %ecx, %r10d
movl %r11d, %ecx
shll %cl, %r10d
addl 0x2c(%rsp), %r10d
cmpl %ebp, %r10d
cmovgel %ebp, %r10d
movl %r12d, %edx
movl %eax, %ecx
movq %r8, %rbx
pushq %r15
pushq %r10
movq %r15, %rbp
movq %rdi, %r15
movl %r11d, %r12d
callq 0x17e2
movl %r12d, %r11d
movq %rbx, %r8
movl 0x20(%rsp), %edx
movq %r15, %rdi
movq %rbp, %r15
movl 0x90(%rsp), %ebp
movl 0x40(%rsp), %r12d
movq 0x50(%rsp), %r10
movl 0x1c(%rsp), %r9d
addq $0x10, %rsp
decl %r14d
cmpl %edx, %r13d
movl 0x34(%rsp), %eax
movl %eax, %r13d
jne 0x18bc
movl 0x8(%rsp), %r13d
andl $-0x2, %r13d
cmpl %edx, %r13d
movl 0x28(%rsp), %ebx
jg 0x1836
movq (%rdi), %rax
movl 0x14(%rsp), %edx
movl 0x4(%rsp), %r8d
subl %r8d, %edx
subl 0x24(%rsp), %edx
subl %r13d, %edx
movl (%rsp), %ecx
movl %ecx, %esi
subl %r8d, %esi
subl %r13d, %esi
movl %r11d, %r14d
movl %r13d, %r11d
movl %r12d, %ecx
shll %cl, %r11d
movl %r13d, %r8d
movl %r14d, %ecx
shll %cl, %r8d
leal (%rsi,%r11), %ecx
addl %r10d, %r8d
movslq %ecx, %rcx
addl %edx, %r11d
movslq %r11d, %r11
movl (%rax,%rcx,4), %ecx
movl (%rax,%r11,4), %r11d
cmpl %r11d, %ecx
cmovgl %ecx, %r11d
movslq %r8d, %rcx
movl %r11d, (%r15,%rcx,4)
addl $0x2, %r13d
addl $-0x2, %edx
addl $-0x2, %esi
cmpl 0x10(%rsp), %r13d
jle 0x198c
jmp 0x1836
movslq %r10d, %rax
movl (%r15,%rax,4), %eax
movq (%rdi), %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