// File: 6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/test_ca_sst.cpp
// Function: test_get_update_4()
void test_get_update_4() {
    // -- This is a bit of stress test
    // Test update all elements.
    // make value = key^2. Do multiple passes with random tree sizes.
    for (int i = 0; i < 100; i++) {
        // limit size to the range [0...10000]
        // no point in doing more.
        int t_size = 1 + rand() % 10000;
        CA_static_search_tree tree(t_size);
        for (int j = 0; j < t_size; j++) {
            tree.update(j, j);
        }
        // now update them again but in BACKWARDS order.
        for (int j = t_size - 1; j >= 0; j--) {
            tree.update(j, j*j);
        }
        for (int j = 0; j < t_size; j++) {
            if (tree.get(j * j) != j) {
                cout << "test_get_update_4 failed: expected value " << j*j << " at index " << j << ", tree size: " << t_size << endl;
                return;
            }
        }
    }
    cout << "test_get_update_4: OK" << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
cmpl $0x64, -0x4(%rbp)
jge 0x5b67
callq 0x1050
movl $0x2710, %ecx           # imm = 0x2710
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, -0x8(%rbp)
movl -0x8(%rbp), %esi
leaq -0x20(%rbp), %rdi
callq 0x2310
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x5a31
movl -0x24(%rbp), %edx
leaq -0x20(%rbp), %rdi
movl %edx, %esi
callq 0x2aa0
jmp 0x5a0a
jmp 0x5a0c
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x59f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x2390
jmp 0x5b92
movl -0x8(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jl 0x5a60
movl -0x38(%rbp), %esi
movl %esi, %edx
imull %edx, %edx
leaq -0x20(%rbp), %rdi
callq 0x2aa0
jmp 0x5a53
jmp 0x5a55
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x5a3a
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x5b3c
movl -0x3c(%rbp), %esi
imull %esi, %esi
leaq -0x20(%rbp), %rdi
callq 0x2af0
movl %eax, -0x44(%rbp)
jmp 0x5a87
movl -0x44(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x5b2c
movq 0x453e(%rip), %rdi      # 0x9fd8
leaq 0x1859(%rip), %rsi      # 0x72fa
callq 0x10d0
movq %rax, -0x50(%rbp)
jmp 0x5aac
movq -0x50(%rbp), %rdi
movl -0x3c(%rbp), %esi
imull %esi, %esi
callq 0x1180
movq %rax, -0x58(%rbp)
jmp 0x5ac1
movq -0x58(%rbp), %rdi
leaq 0x17ff(%rip), %rsi      # 0x72cb
callq 0x10d0
movq %rax, -0x60(%rbp)
jmp 0x5ad7
movq -0x60(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x1180
movq %rax, -0x68(%rbp)
jmp 0x5ae9
movq -0x68(%rbp), %rdi
leaq 0x17e2(%rip), %rsi      # 0x72d6
callq 0x10d0
movq %rax, -0x70(%rbp)
jmp 0x5aff
movq -0x70(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x1180
movq %rax, -0x78(%rbp)
jmp 0x5b11
movq -0x78(%rbp), %rdi
movq 0x44ac(%rip), %rsi      # 0x9fc8
callq 0x1110
jmp 0x5b23
movl $0x1, -0x40(%rbp)
jmp 0x5b43
jmp 0x5b2e
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5a67
movl $0x0, -0x40(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x2390
movl -0x40(%rbp), %eax
testl %eax, %eax
je 0x5b57
jmp 0x5b55
jmp 0x5b89
jmp 0x5b59
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x59c2
movq 0x446a(%rip), %rdi      # 0x9fd8
leaq 0x17af(%rip), %rsi      # 0x7324
callq 0x10d0
movq %rax, %rdi
movq 0x4444(%rip), %rsi      # 0x9fc8
callq 0x1110
addq $0x80, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x1190
nopl (%rax,%rax)