// File: /workspace/github_cpp_makefile_star2_O2/rocket323[P]fishdb/./iter.cpp
// Function: fishdb::Iterator::Next()
void Iterator::Next()
{
    assert(Valid());

    auto now = m_stack.back();
    std::string cur_key = now->kvs[m_kv_idx].key;

    // 1. we are leaf
    if (now->is_leaf)
    {
        // 1.a leaf have more kv
        if (m_kv_idx + 1 < (int)now->kvs.size())
        {
            m_kv_idx++;
            return;
        }

        // 1.b no more kv, find first parent which has more kv
        while (m_stack.size() > 0)
        {
            auto nd = m_stack.back();
            auto iter = m_btree->UpperBound(nd, cur_key);
            if (iter != nd->kvs.end())
            {
                m_kv_idx = iter - nd->kvs.begin();
                return;
            }
            else
                m_stack.pop_back();
        }
    }
    // 2. we are inner node
    else
    {
        int p = m_kv_idx + 1;
        now = m_btree->ReadPage(now->children[p]);
        m_stack.push_back(now);
        while (!now->is_leaf)
        {
            now = m_btree->ReadPage(now->children[0]);
            m_stack.push_back(now);
        }
        m_kv_idx = 0;
        return;
    }

    // invalid if came here
    m_valid = false;
    m_kv_idx = -1;
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
cmpb $0x0, 0x24(%rdi)
je 0x2d6c
movq %rdi, %rbx
movq 0x10(%rdi), %rsi
addq $-0x10, %rsi
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0x2ee6
movq (%r14), %rax
movslq 0x20(%rbx), %rsi
shlq $0x6, %rsi
addq 0x60(%rax), %rsi
leaq -0x78(%rbp), %rdi
callq 0x2280
leaq 0x8(%rbx), %r14
movq -0x48(%rbp), %rcx
movslq 0x20(%rbx), %rax
cmpb $0x1, 0x79(%rcx)
jne 0x2cbc
incl %eax
movq 0x68(%rcx), %rdx
subq 0x60(%rcx), %rdx
shrq $0x6, %rdx
cmpl %edx, %eax
jl 0x2d48
leaq -0x58(%rbp), %r15
movq 0x10(%rbx), %rsi
cmpq 0x8(%rbx), %rsi
je 0x2d41
addq $-0x10, %rsi
leaq -0x38(%rbp), %r13
movq %r13, %rdi
callq 0x2ee6
movq (%rbx), %r12
movq %r15, %rdi
movq %r13, %rsi
callq 0x2ee6
movq %r12, %rdi
movq %r15, %rsi
leaq -0x78(%rbp), %rdx
callq 0x3358
movq %rax, %r12
leaq -0x50(%rbp), %rdi
callq 0x2688
movq -0x38(%rbp), %rax
movq 0x68(%rax), %r13
cmpq %r13, %r12
je 0x2ca1
movq 0x60(%rax), %rax
movq %r12, %rcx
subq %rax, %rcx
shrq $0x6, %rcx
movl %ecx, 0x20(%rbx)
jmp 0x2ca9
movq %r14, %rdi
callq 0x2ec8
leaq -0x30(%rbp), %rdi
callq 0x2688
cmpq %r13, %r12
je 0x2c3a
jmp 0x2d4b
movq (%rbx), %rsi
movq 0x48(%rcx), %rcx
movq 0x8(%rcx,%rax,8), %rdx
leaq -0x38(%rbp), %rdi
callq 0x3274
leaq -0x48(%rbp), %r15
leaq -0x38(%rbp), %rsi
movq %r15, %rdi
callq 0x30d2
leaq -0x30(%rbp), %rdi
callq 0x2688
movq %r14, %rdi
movq %r15, %rsi
callq 0x2e7e
leaq -0x30(%rbp), %r15
leaq -0x38(%rbp), %r12
leaq -0x48(%rbp), %r13
movq -0x48(%rbp), %rax
cmpb $0x0, 0x79(%rax)
jne 0x2d3d
movq (%rbx), %rsi
movq 0x48(%rax), %rax
movq (%rax), %rdx
movq %r12, %rdi
callq 0x3274
movq %r13, %rdi
movq %r12, %rsi
callq 0x30d2
movq %r15, %rdi
callq 0x2688
movq %r14, %rdi
movq %r13, %rsi
callq 0x2e7e
jmp 0x2d01
xorl %eax, %eax
jmp 0x2d48
movb $0x0, 0x24(%rbx)
pushq $-0x1
popq %rax
movl %eax, 0x20(%rbx)
leaq -0x78(%rbp), %rdi
callq 0x20e0
leaq -0x40(%rbp), %rdi
callq 0x2688
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x42d0(%rip), %rdi      # 0x7043
leaq 0x42d1(%rip), %rsi      # 0x704b
leaq 0x42d5(%rip), %rcx      # 0x7056
pushq $0x5d
popq %rdx
callq 0x2140
jmp 0x2dab
jmp 0x2dab
movq %rax, %rbx
jmp 0x2db7
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x2688
leaq -0x30(%rbp), %rdi
callq 0x2688
jmp 0x2dae
jmp 0x2dab
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x20e0
leaq -0x40(%rbp), %rdi
callq 0x2688
movq %rbx, %rdi
callq 0x2310