// File: obliviousram[P]oblivious-avl-tree/src/CorrectnessTester.cpp
// Function: CorrectnessTester::runTester2()
void CorrectnessTester::runTester2() {

    vector<int> stat;
    stat.resize(10,0);
    int bucketSize = 4;
    int numBlocks = pow(2, 10);
    Bucket::setMaxSize(bucketSize);    

    UntrustedStorageInterface* storage = new ServerStorage();
    RandForOramInterface* random = new RandomForOram();
    OAVLTreeInterface* oavl = new OAVLTreeDeterministicEviction(storage, random, bucketSize, numBlocks);

    cout << "Test begins..." << endl;
    vector<int> ele;
    for (int i = 0; i < 1024; ++i) {
        ele.push_back(i);
    }
    random_shuffle(ele.begin(), ele.end());

    int dy = 1;

    for (auto e: ele) {
        oavl->insert(e,e);
        if (oavl->getStashSize() > 0) {
            cout << dy++ << " : insert " << e << endl;
            cout << "stash size: "<< oavl->getStashSize() << endl;
        }
    }
    // storage->dumpAllValidBlocks();
    for (int i = 0; i < 3000; ++i) {
        int res = oavl->search(i % 1024);
        int s = oavl->getStashSize();
        stat[s] += 1;
    }
    for (auto r : stat) cout << r << " ";
    // storage->dumpAllValidBlocks();
    // oavl->dumpStash();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
leaq -0x20(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x6c30
movq -0xe0(%rbp), %rdi
movl $0x0, -0x24(%rbp)
movl $0xa, %esi
leaq -0x24(%rbp), %rdx
callq 0x6c50
jmp 0x66fd
movl $0x4, -0x38(%rbp)
movl $0x2, %edi
movl $0xa, %esi
callq 0x6c00
movsd %xmm0, -0xe8(%rbp)
jmp 0x671d
movsd -0xe8(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %edi
callq 0x4730
jmp 0x6736
movl $0x28, %edi
callq 0x3210
movq %rax, -0xf0(%rbp)
jmp 0x6749
movq -0xf0(%rbp), %rdi
callq 0x13600
jmp 0x6757
movq -0xf0(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x13d0, %edi           # imm = 0x13D0
callq 0x3210
movq %rax, -0xf8(%rbp)
jmp 0x6775
movq -0xf8(%rbp), %rdi
callq 0x11de0
jmp 0x6783
movq -0xf8(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x70, %edi
callq 0x3210
movq %rax, -0x100(%rbp)
jmp 0x67a1
movq -0x100(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movl -0x38(%rbp), %ecx
movl -0x3c(%rbp), %r8d
callq 0x87c0
jmp 0x67be
movq -0x100(%rbp), %rax
movq %rax, -0x58(%rbp)
movq 0x17808(%rip), %rdi     # 0x1dfd8
leaq 0xfa12(%rip), %rsi      # 0x161e9
callq 0x31f0
movq %rax, -0x108(%rbp)
jmp 0x67e5
movq -0x108(%rbp), %rdi
movq 0x177d5(%rip), %rsi     # 0x1dfc8
callq 0x3230
jmp 0x67fa
leaq -0x70(%rbp), %rdi
callq 0x6c30
movl $0x0, -0x74(%rbp)
cmpl $0x400, -0x74(%rbp)     # imm = 0x400
jge 0x68c4
leaq -0x70(%rbp), %rdi
leaq -0x74(%rbp), %rsi
callq 0x6d00
jmp 0x6826
jmp 0x6828
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x680a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x6be5
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x28, %esi
callq 0x3220
jmp 0x6be5
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x13d0, %esi           # imm = 0x13D0
callq 0x3220
jmp 0x6be5
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x70, %esi
callq 0x3220
jmp 0x6be5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x6f40
jmp 0x6be5
leaq -0x70(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x6e40
movq -0x110(%rbp), %rdi
movq %rax, -0x80(%rbp)
callq 0x6e70
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x6d70
jmp 0x68fd
movl $0x1, -0x8c(%rbp)
leaq -0x70(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x6e40
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x6e70
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x6ea0
testb $0x1, %al
jne 0x6954
jmp 0x6a89
leaq -0xa0(%rbp), %rdi
callq 0x6ee0
movl (%rax), %eax
movl %eax, -0xac(%rbp)
movq -0x58(%rbp), %rdi
movl -0xac(%rbp), %edx
movq (%rdi), %rax
movq (%rax), %rax
movl %edx, %esi
callq *%rax
jmp 0x697e
movq -0x58(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movl %eax, -0x114(%rbp)
jmp 0x6993
movl -0x114(%rbp), %eax
cmpl $0x0, %eax
jle 0x6a76
movl -0x8c(%rbp), %esi
movl %esi, %eax
incl %eax
movl %eax, -0x8c(%rbp)
movq 0x1761f(%rip), %rdi     # 0x1dfd8
callq 0x3380
movq %rax, -0x120(%rbp)
jmp 0x69c7
movq -0x120(%rbp), %rdi
leaq 0xf823(%rip), %rsi      # 0x161f8
callq 0x31f0
movq %rax, -0x128(%rbp)
jmp 0x69e3
movq -0x128(%rbp), %rdi
movl -0xac(%rbp), %esi
callq 0x3380
movq %rax, -0x130(%rbp)
jmp 0x69fe
movq -0x130(%rbp), %rdi
movq 0x175bc(%rip), %rsi     # 0x1dfc8
callq 0x3230
jmp 0x6a13
movq 0x175be(%rip), %rdi     # 0x1dfd8
leaq 0xf7e2(%rip), %rsi      # 0x16203
callq 0x31f0
movq %rax, -0x138(%rbp)
jmp 0x6a2f
movq -0x58(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movl %eax, -0x13c(%rbp)
jmp 0x6a44
movl -0x13c(%rbp), %esi
movq -0x138(%rbp), %rdi
callq 0x3380
movq %rax, -0x148(%rbp)
jmp 0x6a5f
movq -0x148(%rbp), %rdi
movq 0x1755b(%rip), %rsi     # 0x1dfc8
callq 0x3230
jmp 0x6a74
jmp 0x6a76
jmp 0x6a78
leaq -0xa0(%rbp), %rdi
callq 0x6f00
jmp 0x6938
movl $0x0, -0xb0(%rbp)
cmpl $0xbb8, -0xb0(%rbp)     # imm = 0xBB8
jge 0x6b2c
movq -0x58(%rbp), %rdi
movl -0xb0(%rbp), %esi
movl %esi, %ecx
addl $0x3ff, %ecx            # imm = 0x3FF
testl %esi, %esi
movl %esi, %eax
cmovsl %ecx, %eax
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
subl %eax, %esi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
movl %eax, -0x14c(%rbp)
jmp 0x6ad4
movl -0x14c(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0x58(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movl %eax, -0x150(%rbp)
jmp 0x6af5
movl -0x150(%rbp), %eax
movl %eax, -0xb8(%rbp)
movslq -0xb8(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x6f20
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0xb0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb0(%rbp)
jmp 0x6a93
leaq -0x20(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x6e40
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x6e70
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x6ea0
testb $0x1, %al
jne 0x6b76
jmp 0x6bca
leaq -0xc8(%rbp), %rdi
callq 0x6ee0
movl (%rax), %eax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %esi
movq 0x17441(%rip), %rdi     # 0x1dfd8
callq 0x3380
movq %rax, -0x158(%rbp)
jmp 0x6ba5
movq -0x158(%rbp), %rdi
leaq 0xf462(%rip), %rsi      # 0x16015
callq 0x31f0
jmp 0x6bba
jmp 0x6bbc
leaq -0xc8(%rbp), %rdi
callq 0x6f00
jmp 0x6b5d
leaq -0x70(%rbp), %rdi
callq 0x6f40
leaq -0x20(%rbp), %rdi
callq 0x6f40
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x20(%rbp), %rdi
callq 0x6f40
movq -0x30(%rbp), %rdi
callq 0x33a0
nopw (%rax,%rax)