// File: 6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/test_simple_sst.cpp
// Function: test_get_update_4(bool)
void test_get_update_4(bool recursive) {
    // -- 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;
        simple_static_search_tree tree(t_size, recursive);
        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 $0x90, %rsp
movb %dil, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x0, -0x8(%rbp)
cmpl $0x64, -0x8(%rbp)
jge 0x5c7d
callq 0x1050
movl $0x2710, %ecx           # imm = 0x2710
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, -0xc(%rbp)
movl -0xc(%rbp), %esi
movb -0x1(%rbp), %al
leaq -0x30(%rbp), %rdi
andb $0x1, %al
movzbl %al, %edx
callq 0x2bb0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x5b41
movl -0x34(%rbp), %edx
leaq -0x30(%rbp), %rdi
movl %edx, %esi
callq 0x2fc0
jmp 0x5b1a
jmp 0x5b1c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5b02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2c40
jmp 0x5ca8
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jl 0x5b70
movl -0x48(%rbp), %esi
movl %esi, %edx
imull %edx, %edx
leaq -0x30(%rbp), %rdi
callq 0x2fc0
jmp 0x5b63
jmp 0x5b65
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x5b4a
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x5c52
movl -0x4c(%rbp), %esi
imull %esi, %esi
leaq -0x30(%rbp), %rdi
callq 0x3030
movl %eax, -0x54(%rbp)
jmp 0x5b97
movl -0x54(%rbp), %eax
cmpl -0x4c(%rbp), %eax
je 0x5c42
movq 0x442e(%rip), %rdi      # 0x9fd8
leaq 0x1749(%rip), %rsi      # 0x72fa
callq 0x10d0
movq %rax, -0x60(%rbp)
jmp 0x5bbc
movq -0x60(%rbp), %rdi
movl -0x4c(%rbp), %esi
imull %esi, %esi
callq 0x1180
movq %rax, -0x68(%rbp)
jmp 0x5bd1
movq -0x68(%rbp), %rdi
leaq 0x16ef(%rip), %rsi      # 0x72cb
callq 0x10d0
movq %rax, -0x70(%rbp)
jmp 0x5be7
movq -0x70(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x1180
movq %rax, -0x78(%rbp)
jmp 0x5bf9
movq -0x78(%rbp), %rdi
leaq 0x16d2(%rip), %rsi      # 0x72d6
callq 0x10d0
movq %rax, -0x80(%rbp)
jmp 0x5c0f
movq -0x80(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x1180
movq %rax, -0x88(%rbp)
jmp 0x5c24
movq -0x88(%rbp), %rdi
movq 0x4396(%rip), %rsi      # 0x9fc8
callq 0x1110
jmp 0x5c39
movl $0x1, -0x50(%rbp)
jmp 0x5c59
jmp 0x5c44
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x5b77
movl $0x0, -0x50(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2c40
movl -0x50(%rbp), %eax
testl %eax, %eax
je 0x5c6d
jmp 0x5c6b
jmp 0x5c9f
jmp 0x5c6f
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x5aca
movq 0x4354(%rip), %rdi      # 0x9fd8
leaq 0x1699(%rip), %rsi      # 0x7324
callq 0x10d0
movq %rax, %rdi
movq 0x432e(%rip), %rsi      # 0x9fc8
callq 0x1110
addq $0x90, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x1190
nopw %cs:(%rax,%rax)