// File: 6851-2021[P]Cache-Oblivious-Data-Structures/static_search_trees/test_ca_sst.cpp
// Function: test_get_update_1()
void test_get_update_1() {
    // Test with a tree of size 15.
    int n = 15;
    CA_static_search_tree tree(n);
    int a[15];
    a[0] = rand() % 10;
    // for (int i = 1; i < n; ++i) {
    //     a[i] = a[i - 1] + rand() % 10;
    //     tree.update(i, a[i]);
    // }

    for (int i = 0; i < n; ++i) {
        a[i] = i;
        tree.update(i, i);
    }

    int index;

    index = tree.get(a[13]);
    if (index != 13)
    {
        print_array(a, n);
        printf("test_get_update_1 failed: expected %d at index 13, got: %d\n", a[13], index);
        tree.print_tree();
        return;
    }

    index = tree.get(a[5]);
    if (index != 5)
    {
        print_array(a, n);
        printf("test_get_update_1 failed: expected %d at index 5, got: %d\n", a[5], index);
        return;
    }

    index = tree.get(a[0]);
    if (index != 0)
    {
        print_array(a, n);
        printf("test_get_update_1 failed: expected %d at index 0, got: %d\n", a[0], index);
        return;
    }

    index = tree.get(a[13]);
    if (index != 13)
    {
        print_array(a, n);
        printf("test_get_update_1 failed: expected %d at index 13, got: %d\n", a[13], index);
        return;
    }
    cout << "test_get_update_1: OK" << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl $0xf, -0x4(%rbp)
movl -0x4(%rbp), %esi
leaq -0x20(%rbp), %rdi
callq 0x2310
callq 0x1050
movl $0xa, %ecx
cltd
idivl %ecx
movl %edx, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x54ae
movslq -0x64(%rbp), %rax
movl %eax, %ecx
movl %ecx, -0x60(%rbp,%rax,4)
movl -0x64(%rbp), %edx
leaq -0x20(%rbp), %rdi
movl %edx, %esi
callq 0x2aa0
jmp 0x5487
jmp 0x5489
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x5465
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x2390
jmp 0x5646
movl -0x2c(%rbp), %esi
leaq -0x20(%rbp), %rdi
callq 0x2af0
movl %eax, -0x80(%rbp)
jmp 0x54bf
movl -0x80(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $0xd, -0x78(%rbp)
je 0x5506
movl -0x4(%rbp), %esi
leaq -0x60(%rbp), %rdi
callq 0x53c0
jmp 0x54d9
movl -0x2c(%rbp), %esi
movl -0x78(%rbp), %edx
leaq 0x1c48(%rip), %rdi      # 0x712e
xorl %eax, %eax
callq 0x1030
jmp 0x54ef
leaq -0x20(%rbp), %rdi
callq 0x2b40
jmp 0x54fa
movl $0x1, -0x7c(%rbp)
jmp 0x5634
movl -0x4c(%rbp), %esi
leaq -0x20(%rbp), %rdi
callq 0x2af0
movl %eax, -0x84(%rbp)
jmp 0x551a
movl -0x84(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $0x5, -0x78(%rbp)
je 0x5559
movl -0x4(%rbp), %esi
leaq -0x60(%rbp), %rdi
callq 0x53c0
jmp 0x5537
movl -0x4c(%rbp), %esi
movl -0x78(%rbp), %edx
leaq 0x1c26(%rip), %rdi      # 0x716a
xorl %eax, %eax
callq 0x1030
jmp 0x554d
movl $0x1, -0x7c(%rbp)
jmp 0x5634
movl -0x60(%rbp), %esi
leaq -0x20(%rbp), %rdi
callq 0x2af0
movl %eax, -0x88(%rbp)
jmp 0x556d
movl -0x88(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x78(%rbp)
je 0x55ac
movl -0x4(%rbp), %esi
leaq -0x60(%rbp), %rdi
callq 0x53c0
jmp 0x558a
movl -0x60(%rbp), %esi
movl -0x78(%rbp), %edx
leaq 0x1c0e(%rip), %rdi      # 0x71a5
xorl %eax, %eax
callq 0x1030
jmp 0x55a0
movl $0x1, -0x7c(%rbp)
jmp 0x5634
movl -0x2c(%rbp), %esi
leaq -0x20(%rbp), %rdi
callq 0x2af0
movl %eax, -0x8c(%rbp)
jmp 0x55c0
movl -0x8c(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $0xd, -0x78(%rbp)
je 0x55fc
movl -0x4(%rbp), %esi
leaq -0x60(%rbp), %rdi
callq 0x53c0
jmp 0x55dd
movl -0x2c(%rbp), %esi
movl -0x78(%rbp), %edx
leaq 0x1b44(%rip), %rdi      # 0x712e
xorl %eax, %eax
callq 0x1030
jmp 0x55f3
movl $0x1, -0x7c(%rbp)
jmp 0x5634
movq 0x49d5(%rip), %rdi      # 0x9fd8
leaq 0x1bd6(%rip), %rsi      # 0x71e0
callq 0x10d0
movq %rax, -0x98(%rbp)
jmp 0x5618
movq -0x98(%rbp), %rdi
movq 0x49a2(%rip), %rsi      # 0x9fc8
callq 0x1110
jmp 0x562d
movl $0x0, -0x7c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x2390
addq $0xa0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x1190
nop