// File: 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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
movb $0x0, -0x11(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x150(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl 0x20(%rcx), %eax
jge 0x8ee1
movq -0x150(%rbp), %rdi
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq %rcx, -0x160(%rbp)
movl -0xc(%rbp), %esi
movl -0x18(%rbp), %edx
movq 0x10(%rax), %rax
callq *%rax
movq -0x160(%rbp), %rsi
movl %eax, %edx
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0x48(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq *%rax
movq -0x158(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x4700
jmp 0x8c9e
leaq -0x48(%rbp), %rdi
callq 0xcfd0
leaq -0x70(%rbp), %rdi
callq 0x41c0
jmp 0x8cb2
leaq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x4a70
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
callq 0x4aa0
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x4ad0
testb $0x1, %al
jne 0x8cf0
jmp 0x8e65
leaq -0x80(%rbp), %rdi
callq 0x4b10
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x10(%rbp), %eax
jne 0x8e06
movq -0x150(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x168(%rbp)
movq -0x90(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x3720
jmp 0x8d3a
movq -0x168(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xcff0
jmp 0x8d4f
leaq -0xc0(%rbp), %rdi
callq 0x3830
movb $0x1, -0x11(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x37e0
jmp 0x8d6d
leaq -0x70(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x45c0
jmp 0x8d7f
leaq -0xf0(%rbp), %rdi
callq 0x3830
jmp 0x8e55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xcfd0
jmp 0x8fe5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x8ed3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x8eca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x3830
jmp 0x8eca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x3830
jmp 0x8eca
movq -0x90(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x3720
jmp 0x8e1b
leaq -0x70(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x45c0
jmp 0x8e2d
leaq -0x120(%rbp), %rdi
callq 0x3830
jmp 0x8e55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x3830
jmp 0x8eca
jmp 0x8e57
leaq -0x80(%rbp), %rdi
callq 0x4b30
jmp 0x8cd7
movq -0x150(%rbp), %rdi
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq %rcx, -0x178(%rbp)
movl -0xc(%rbp), %esi
movl -0x18(%rbp), %edx
movq 0x10(%rax), %rax
callq *%rax
movl %eax, -0x16c(%rbp)
jmp 0x8e8e
movl -0x16c(%rbp), %esi
movq -0x178(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq -0x70(%rbp), %rdx
callq *%rax
jmp 0x8eaa
leaq -0x70(%rbp), %rdi
callq 0xcfd0
leaq -0x30(%rbp), %rdi
callq 0x4900
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x8c3b
leaq -0x70(%rbp), %rdi
callq 0xcfd0
leaq -0x30(%rbp), %rdi
callq 0x4900
jmp 0x8fe5
movb -0x11(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x8fdc
movq -0x150(%rbp), %rdi
addq $0x30, %rdi
callq 0x4a70
movq %rax, -0x128(%rbp)
movq -0x150(%rbp), %rdi
addq $0x30, %rdi
callq 0x4aa0
movq %rax, -0x130(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x4ad0
testb $0x1, %al
jne 0x8f3c
jmp 0x8fda
leaq -0x128(%rbp), %rdi
callq 0xd020
movl 0xc(%rax), %eax
cmpl -0x10(%rbp), %eax
jne 0x8fbe
movq -0x150(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x188(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x4b10
movq -0x188(%rbp), %rdi
movq %rax, %rsi
callq 0x4b80
movq -0x150(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x180(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x4ca0
movq -0x180(%rbp), %rdi
movq -0x138(%rbp), %rsi
callq 0x4bf0
movq %rax, -0x140(%rbp)
jmp 0x8fda
jmp 0x8fc0
leaq -0x128(%rbp), %rdi
xorl %esi, %esi
callq 0xd040
movq %rax, -0x148(%rbp)
jmp 0x8f09
jmp 0x8fdc
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x33a0
nop