// File: /workspace/github_cpp_makefile_star2_O3/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, %ebp
movl %esi, 0x8(%rsp)
movq %rdi, (%rsp)
cmpl $0x0, 0x20(%rdi)
jle 0x46b4
movq (%rsp), %r14
leaq 0x48(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
leaq 0xa8(%rsp), %r12
xorl %edx, %edx
movq (%r14), %rax
movq 0x8(%r14), %r15
movq %r14, %rdi
movl 0x8(%rsp), %esi
movl %edx, 0xc(%rsp)
callq *0x10(%rax)
movq (%r15), %rcx
movq %r12, %rdi
movq %r15, %rsi
movl %eax, %edx
callq *0x8(%rcx)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x2ef4
movq %r12, %rdi
callq 0x2ff0
leaq 0x18(%rsp), %rdi
callq 0x2b28
movq 0x30(%rsp), %r15
movq 0x38(%rsp), %r14
cmpq %r14, %r15
je 0x4660
cmpl %ebp, 0xc(%r15)
jne 0x4630
movq %r12, %rdi
movq %r15, %rsi
callq 0x25dc
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x591a
movq %r12, %rdi
callq 0x2638
leaq 0x78(%rsp), %rdi
callq 0x261c
movb $0x1, %r13b
leaq 0x18(%rsp), %rdi
movl %ebp, %ebx
movq %r12, %rbp
leaq 0x78(%rsp), %r12
movq %r12, %rsi
callq 0x2e12
movq %r12, %rdi
movq %rbp, %r12
movl %ebx, %ebp
jmp 0x4652
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0x25dc
leaq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
callq 0x2e12
movq %rbx, %rdi
callq 0x2638
addq $0x30, %r15
jmp 0x45d3
movq (%rsp), %r14
movq (%r14), %rax
movq 0x8(%r14), %r15
movq %r14, %rdi
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
callq *0x10(%rax)
leaq 0x18(%rsp), %rbx
movq (%r15), %rcx
movq %r15, %rdi
movl %eax, %esi
movq %rbx, %rdx
callq *0x10(%rcx)
movq %rbx, %rdi
callq 0x2ff0
leaq 0x30(%rsp), %rdi
callq 0x2ff0
movl 0xc(%rsp), %edx
incl %edx
cmpl 0x20(%r14), %edx
jl 0x4587
testb $0x1, %r13b
jne 0x46f8
movq (%rsp), %rax
movq 0x30(%rax), %rbx
movq 0x38(%rax), %rax
cmpq %rax, %rbx
je 0x46f8
movq (%rsp), %rcx
leaq 0x30(%rcx), %r14
cmpl %ebp, 0xc(%rbx)
je 0x46dd
addq $0x30, %rbx
cmpq %rax, %rbx
jne 0x46cd
jmp 0x46f8
movq (%rsp), %rdi
addq $0x48, %rdi
movq %rbx, %rsi
callq 0x30ce
movq %r14, %rdi
movq %rbx, %rsi
callq 0x30fa
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x4758
movq %rax, %rbx
jmp 0x4753
jmp 0x4746
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x473d
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x473d
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x2638
jmp 0x4749
jmp 0x4746
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2ff0
leaq 0x30(%rsp), %rdi
callq 0x2ff0
movq %rbx, %rdi
callq 0x22a0
nop