// File: /workspace/github_cpp_makefile_star2_O1/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 0x434c
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 0x2f50
movq %r12, %rdi
callq 0x304c
leaq 0x18(%rsp), %rdi
callq 0x2b38
movq 0x30(%rsp), %r15
movq 0x38(%rsp), %r14
cmpq %r14, %r15
je 0x42f8
cmpl %ebp, 0xc(%r15)
jne 0x42c8
movq %r12, %rdi
movq %r15, %rsi
callq 0x25dc
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x565c
movq %r12, %rdi
callq 0x264c
leaq 0x78(%rsp), %rdi
callq 0x2630
movb $0x1, %r13b
leaq 0x18(%rsp), %rdi
movl %ebp, %ebx
movq %r12, %rbp
leaq 0x78(%rsp), %r12
movq %r12, %rsi
callq 0x2e74
movq %r12, %rdi
movq %rbp, %r12
movl %ebx, %ebp
jmp 0x42ea
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0x25dc
leaq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
callq 0x2e74
movq %rbx, %rdi
callq 0x264c
addq $0x30, %r15
jmp 0x426b
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 0x304c
leaq 0x30(%rsp), %rdi
callq 0x304c
movl 0xc(%rsp), %edx
incl %edx
cmpl 0x20(%r14), %edx
jl 0x421f
testb $0x1, %r13b
jne 0x4390
movq (%rsp), %rax
movq 0x30(%rax), %rbx
movq 0x38(%rax), %rax
cmpq %rax, %rbx
je 0x4390
movq (%rsp), %rcx
leaq 0x30(%rcx), %r14
cmpl %ebp, 0xc(%rbx)
je 0x4375
addq $0x30, %rbx
cmpq %rax, %rbx
jne 0x4365
jmp 0x4390
movq (%rsp), %rdi
addq $0x48, %rdi
movq %rbx, %rsi
callq 0x3124
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3150
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x43f0
movq %rax, %rbx
jmp 0x43eb
jmp 0x43de
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x43d5
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x43d5
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x264c
jmp 0x43e1
jmp 0x43de
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x304c
leaq 0x30(%rsp), %rdi
callq 0x304c
movq %rbx, %rdi
callq 0x22a0
nop