// File: /workspace/github_cpp_makefile_star2_O2/obliviousram[P]oblivious-avl-tree/src/OAVLTreeDeterministicEviction.cpp
// Function: OAVLTreeDeterministicEviction::moveToLocal(int, int)
void OAVLTreeDeterministicEviction::moveToLocal(int leaf, int blockid) {
    bool inOram = false;
    for (int i = 0; i < num_levels; i++) {
        vector<Block> blocks = storage->readBucket(P(leaf, i)).getBlocks();
        Bucket writeBack;
        for (Block &b: blocks) {
            if (b.id == blockid) {
                local.push_back(Block(b));
                inOram = true;
                writeBack.addBlock(Block());
            } else writeBack.addBlock(b);
        }
        storage->writeBucket(P(leaf, i), writeBack);
    }
    if (inOram == false) {
        for (auto it = stash.begin(); it != stash.end(); it++) {
            if (it->id == blockid) {
                local.push_back(*it);
                stash.erase(it);
                break;
            } 
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %edx, %ebx
movl %esi, (%rsp)
movq %rdi, %r12
leaq 0x48(%rdi), %rax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
leaq 0xa8(%rsp), %r13
xorl %ebp, %ebp
movq %rdi, 0x10(%rsp)
cmpl 0x20(%r12), %edx
jge 0x3e8d
movq (%r12), %rax
movq 0x8(%r12), %r14
movq %r12, %rdi
movl (%rsp), %esi
movl %edx, 0x4(%rsp)
callq *0x10(%rax)
movq (%r14), %rcx
movq %r13, %rdi
movq %r14, %rsi
movl %eax, %edx
callq *0x8(%rcx)
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x2c1a
movq %r13, %rdi
callq 0x2d0c
leaq 0x18(%rsp), %rdi
callq 0x28e4
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %r12
cmpq %r12, %r14
je 0x3e42
cmpl %ebx, 0xc(%r14)
jne 0x3e12
movq %r13, %rdi
movq %r14, %rsi
callq 0x253c
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x4f4a
movq %r13, %rdi
callq 0x2594
leaq 0x78(%rsp), %rdi
callq 0x257a
movb $0x1, %bpl
leaq 0x18(%rsp), %rdi
movl %ebx, %r15d
movq %r13, %rbx
leaq 0x78(%rsp), %r13
movq %r13, %rsi
callq 0x2b68
movq %r13, %rdi
movq %rbx, %r13
movl %r15d, %ebx
jmp 0x3e34
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x253c
leaq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %r15
movq %r15, %rsi
callq 0x2b68
movq %r15, %rdi
callq 0x2594
addq $0x30, %r14
jmp 0x3db3
movq 0x10(%rsp), %r12
movq (%r12), %rax
movq 0x8(%r12), %r14
movq %r12, %rdi
movl (%rsp), %esi
movl 0x4(%rsp), %edx
callq *0x10(%rax)
leaq 0x18(%rsp), %r15
movq (%r14), %rcx
movq %r14, %rdi
movl %eax, %esi
movq %r15, %rdx
callq *0x10(%rcx)
movq %r15, %rdi
callq 0x2d0c
leaq 0x30(%rsp), %rdi
callq 0x2d0c
movl 0x4(%rsp), %edx
incl %edx
jmp 0x3d5b
testb $0x1, %bpl
jne 0x3ecb
leaq 0x30(%r12), %r14
movq 0x30(%r12), %r15
movq 0x38(%r12), %rax
cmpq %rax, %r15
je 0x3ecb
cmpl %ebx, 0xc(%r15)
je 0x3eb3
addq $0x30, %r15
jmp 0x3ea2
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x2d80
movq %r14, %rdi
movq %r15, %rsi
callq 0x2dac
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x3f26
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x3f2b
jmp 0x3f19
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x3f12
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x3f12
jmp 0x3f19
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2594
jmp 0x3f1c
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2d0c
leaq 0x30(%rsp), %rdi
callq 0x2d0c
movq %rbx, %rdi
callq 0x22b0