// File: rocket323[P]fishdb/./iter.cpp
// Function: fishdb::Iterator::Seek(char const*)
void Iterator::Seek(const char *k)
{
    std::string key = k;
    auto now = m_btree->m_root;

    bool found_upper = false;
    while (now != NULL)
    {
        m_stack.push_back(now);
        auto iter = m_btree->LowerBound(now, key);
        size_t p = iter - now->kvs.begin();
        if (iter != now->kvs.end())
        {
            found_upper = true;
            m_kv_idx = p;
            now = m_btree->ReadPage(now->children[p]);
        }
        else if (!now->is_leaf)
        {
            now = m_btree->ReadPage(now->children[p]);
        }
        else
        {
            break;
        }
    }

    m_valid = found_upper;
    if (!m_valid)
        m_stack.clear();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x2380
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x22d0
jmp 0x38b2
leaq -0x31(%rbp), %rdi
callq 0x2240
movq -0xc8(%rbp), %rax
movq (%rax), %rsi
addq $0x70, %rsi
leaq -0x58(%rbp), %rdi
callq 0x40f0
movb $0x0, -0x59(%rbp)
leaq -0x58(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x42a0
testb $0x1, %al
jne 0x38ec
jmp 0x3aea
movq -0xc8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x58(%rbp), %rsi
callq 0x4120
jmp 0x3902
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
leaq -0x78(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x40f0
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x54c0
movq %rax, -0xd0(%rbp)
jmp 0x3947
movq -0xd0(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x27e0
leaq -0x58(%rbp), %rdi
callq 0x4190
movq %rax, %rdi
addq $0x60, %rdi
callq 0x4310
movq %rax, -0x88(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x42d0
movq %rax, -0x80(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4190
movq %rax, %rdi
addq $0x60, %rdi
callq 0x4380
movq %rax, -0x90(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x4340
testb $0x1, %al
jne 0x39c0
jmp 0x3a72
movq -0xc8(%rbp), %rax
movb $0x1, -0x59(%rbp)
movl -0x80(%rbp), %ecx
movl %ecx, 0x20(%rax)
movq (%rax), %rax
movq %rax, -0xe8(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4190
movq %rax, %rdi
addq $0x48, %rdi
movq -0x80(%rbp), %rsi
callq 0x41b0
movq -0xe8(%rbp), %rsi
movq (%rax), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x5390
jmp 0x3a0c
leaq -0x58(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x41d0
leaq -0xa0(%rbp), %rdi
callq 0x27e0
jmp 0x3ae5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x2240
jmp 0x3b3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3b2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x27e0
jmp 0x3b2b
leaq -0x58(%rbp), %rdi
callq 0x4190
testb $0x1, 0x79(%rax)
jne 0x3ae1
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4190
movq %rax, %rdi
addq $0x48, %rdi
movq -0x80(%rbp), %rsi
callq 0x41b0
movq -0xf0(%rbp), %rsi
movq (%rax), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x5390
jmp 0x3ac3
leaq -0x58(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x41d0
leaq -0xb0(%rbp), %rdi
callq 0x27e0
jmp 0x3ae3
jmp 0x3aea
jmp 0x3ae5
jmp 0x38d6
movq -0xc8(%rbp), %rax
movb -0x59(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x24(%rax)
testb $0x1, 0x24(%rax)
jne 0x3b10
movq -0xc8(%rbp), %rdi
addq $0x8, %rdi
callq 0x4220
leaq -0x58(%rbp), %rdi
callq 0x27e0
leaq -0x30(%rbp), %rdi
callq 0x2140
addq $0xf0, %rsp
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x27e0
leaq -0x30(%rbp), %rdi
callq 0x2140
movq -0x40(%rbp), %rdi
callq 0x2370
nopw %cs:(%rax,%rax)