// File: 6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/test_co_sst.cpp
// Function: test_range_update_uniform(int)
void test_range_update_uniform(const int n) {
    co_static_search_tree tree(n);
    int arr[n];
    for (int i = 0; i < n; ++i) {
        arr[i] = i * 5;
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j){
            arr[j] = j * 5;
        }
        int len = rand() % (n / 2) + 1;
        int R = min(i + len - 1, n - 1);
        tree.range_update(i, R, arr);

        i += (len - 1);
    }
    for (int i = 0; i < (n - 1) * 5; ++i) {
        int result = tree.get(i);
        int expected = ceil(i / 5.0);
        if (result != expected)
        {
            printf("Incorrect index for query value %d, got %d, expected %d\n", i, result, expected);
            exit(-1);
        }
    }
    cout << "Success range update uniform: " << n << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movl %edi, -0x4(%rbp)
movl -0x4(%rbp), %esi
leaq -0xc8(%rbp), %rdi
callq 0x1360
movl -0x4(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0xd0(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x118(%rbp)
movq %rcx, %rsp
movq %rax, -0xd8(%rbp)
movl $0x0, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x676b
movq -0x118(%rbp), %rax
imull $0x5, -0xdc(%rbp), %edx
movslq -0xdc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x6737
movl $0x0, -0xe0(%rbp)
movl -0xe0(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x689b
movl $0x0, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x67c2
movq -0x118(%rbp), %rax
imull $0x5, -0xe4(%rbp), %edx
movslq -0xe4(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x678e
callq 0x1060
movl -0x4(%rbp), %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %edx, %ecx
sarl %ecx
cltd
idivl %ecx
incl %edx
movl %edx, -0xe8(%rbp)
movl -0xe0(%rbp), %edx
movl -0xe8(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal -0x1(%rax,%rcx), %eax
movl %eax, -0xf0(%rbp)
movl -0x4(%rbp), %eax
decl %eax
movl %eax, -0xf4(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0xf4(%rbp), %rsi
callq 0x3f20
movq %rax, -0x120(%rbp)
jmp 0x681f
movq -0x118(%rbp), %rcx
movq -0x120(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xec(%rbp)
movl -0xe0(%rbp), %esi
movl -0xec(%rbp), %edx
leaq -0xc8(%rbp), %rdi
callq 0x1ba0
jmp 0x684f
movl -0xe8(%rbp), %eax
subl $0x1, %eax
addl -0xe0(%rbp), %eax
movl %eax, -0xe0(%rbp)
movl -0xe0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe0(%rbp)
jmp 0x6775
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x1420
jmp 0x69b9
movl $0x0, -0x108(%rbp)
movl -0x108(%rbp), %eax
movl -0x4(%rbp), %ecx
subl $0x1, %ecx
imull $0x5, %ecx, %ecx
cmpl %ecx, %eax
jge 0x6955
movl -0x108(%rbp), %esi
leaq -0xc8(%rbp), %rdi
callq 0x18e0
movl %eax, -0x124(%rbp)
jmp 0x68d6
movl -0x124(%rbp), %eax
movl %eax, -0x10c(%rbp)
cvtsi2sdl -0x108(%rbp), %xmm0
movsd 0x82e(%rip), %xmm1      # 0x7120
divsd %xmm1, %xmm0
callq 0x1050
cvttsd2si %xmm0, %eax
movl %eax, -0x110(%rbp)
movl -0x10c(%rbp), %eax
cmpl -0x110(%rbp), %eax
je 0x693f
movl -0x108(%rbp), %esi
movl -0x10c(%rbp), %edx
movl -0x110(%rbp), %ecx
leaq 0xa72(%rip), %rdi       # 0x739e
xorl %eax, %eax
callq 0x1030
jmp 0x6935
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1140
jmp 0x6941
movl -0x108(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x108(%rbp)
jmp 0x68a5
movq 0x367c(%rip), %rdi      # 0x9fd8
leaq 0xa91(%rip), %rsi       # 0x73f4
callq 0x10e0
movq %rax, -0x130(%rbp)
jmp 0x6971
movq -0x130(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0x11a0
movq %rax, -0x138(%rbp)
jmp 0x6989
movq -0x138(%rbp), %rdi
movq 0x3631(%rip), %rsi      # 0x9fc8
callq 0x1120
jmp 0x699e
movq -0xd0(%rbp), %rax
movq %rax, %rsp
leaq -0xc8(%rbp), %rdi
callq 0x1420
movq %rbp, %rsp
popq %rbp
retq
movq -0x100(%rbp), %rdi
callq 0x11b0
nopw %cs:(%rax,%rax)