// File: /workspace/github_cpp_makefile_star2_O3/rocket323[P]fishdb/./btree.cpp
// Function: fishdb::BTree::Insert(std::shared_ptr<fishdb::MemPage>, std::shared_ptr<fishdb::MemPage>, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void BTree::Insert(std::shared_ptr<MemPage> now, std::shared_ptr<MemPage> parent,
        int upper_idx, const std::string &key, const std::string &data)
{
    auto iter = LowerBound(now, key);
    size_t p = iter - now->kvs.begin();
    if (iter != now->kvs.end() && Equal(iter->key, key))
        iter->value = data;
    else if (!now->is_leaf)
    {
        assert(now);
        assert(now->children.size() > p);
        Insert(ReadPage(now->children[p]), now, p, key, data);
    }
    else
        now->kvs.insert(iter, KV(key, data));
    if ((int)now->kvs.size() <= 2 * m_min_key_num) return;

    //split full
    size_t mid = now->kvs.size() / 2;
    auto left = m_pager.NewPage();
    auto right = m_pager.NewPage();

    left->is_leaf = right->is_leaf = now->is_leaf;
    left->kvs.assign(now->kvs.begin(), now->kvs.begin() + mid);
    right->kvs.assign(now->kvs.begin() + mid + 1, now->kvs.end());
    if (!now->is_leaf)
    {
        left->children.assign(now->children.begin(), now->children.begin() + mid + 1);
        right->children.assign(now->children.begin() + mid + 1, now->children.end());
    }

    if (!parent)
    {
        m_root = m_pager.NewPage();
        m_root->is_leaf = false;
        parent = m_root;
        m_pager.SetRoot(m_root->header.page_no);
        assert(upper_idx == 0);
        parent->children.resize(upper_idx + 1);
    }
    assert(upper_idx < (int)parent->children.size());
    parent->kvs.insert(parent->kvs.begin() + upper_idx, now->kvs[mid]);
    parent->children[upper_idx] = left->header.page_no;
    parent->children.insert(parent->children.begin() + upper_idx + 1, right->header.page_no);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, -0x48(%rbp)
movq %r8, %r15
movl %ecx, -0x34(%rbp)
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r13
movq (%rsi), %rax
movq %rax, -0x78(%rbp)
movq 0x8(%rsi), %rax
movq %rax, -0x70(%rbp)
testq %rax, %rax
je 0x3b5a
movq 0x8484(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x3b56
incl 0x8(%rax)
jmp 0x3b5a
lock
incl 0x8(%rax)
leaq -0x78(%rbp), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x35ee
movq %rax, %rbx
movq %r13, -0x30(%rbp)
movq %r12, -0x40(%rbp)
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x3b82
callq 0x277e
movq (%r14), %r12
movq %rbx, %r13
subq 0x60(%r12), %r13
cmpq 0x68(%r12), %rbx
je 0x3bc7
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x359e
testb %al, %al
je 0x3bc4
addq $0x20, %rbx
movq %rbx, %rdi
movq -0x48(%rbp), %rsi
callq 0x2110
movq -0x40(%rbp), %r12
movq -0x30(%rbp), %r15
jmp 0x3cd2
movq (%r14), %r12
cmpb $0x0, 0x79(%r12)
je 0x3c32
addq $0x60, %r12
leaq -0xe0(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq -0x48(%rbp), %rdx
callq 0x4d62
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x504a
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq -0x40(%rbp), %r12
movq -0x30(%rbp), %r15
je 0x3c14
callq 0x21b0
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3cd2
callq 0x21b0
jmp 0x3cd2
sarq $0x6, %r13
movq 0x48(%r12), %rax
movq 0x50(%r12), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
jbe 0x3f03
movq (%rax,%r13,8), %rdx
leaq -0xa0(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x353c
movq (%r14), %rax
movq %rax, -0x68(%rbp)
movq 0x8(%r14), %rax
movq %rax, -0x60(%rbp)
testq %rax, %rax
movq -0x40(%rbp), %r12
je 0x3c91
movq 0x834d(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x3c8d
incl 0x8(%rax)
jmp 0x3c91
lock
incl 0x8(%rax)
leaq -0xa0(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movq -0x30(%rbp), %rdi
movl %r13d, %ecx
movq %r15, %r8
movq -0x48(%rbp), %r9
callq 0x3b0a
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x3cbd
callq 0x277e
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
movq -0x30(%rbp), %r15
je 0x3cd2
callq 0x277e
movq (%r14), %rax
movq 0x68(%rax), %rbx
subq 0x60(%rax), %rbx
sarq $0x6, %rbx
movl 0x48(%r15), %eax
addl %eax, %eax
cmpl %ebx, %eax
jge 0x3ed2
leaq -0xe0(%rbp), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x640c
leaq -0x58(%rbp), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x640c
shrq %rbx
movq (%r14), %rax
movb 0x79(%rax), %cl
movq -0x58(%rbp), %rdx
movb %cl, 0x79(%rdx)
movq -0xe0(%rbp), %rdi
movb %cl, 0x79(%rdi)
addq $0x60, %rdi
movq 0x60(%rax), %rsi
movq %rbx, %r13
shlq $0x6, %r13
leaq (%rsi,%r13), %rdx
callq 0x53a4
movq -0x58(%rbp), %rdi
addq $0x60, %rdi
movq (%r14), %rax
movq 0x60(%rax), %rcx
movq 0x68(%rax), %rdx
leaq (%rcx,%r13), %rsi
addq $0x40, %rsi
callq 0x53a4
movq (%r14), %rax
cmpb $0x0, 0x79(%rax)
jne 0x3dab
movq -0xe0(%rbp), %rdi
addq $0x48, %rdi
movq 0x48(%rax), %rsi
leaq (%rsi,%rbx,8), %rdx
addq $0x8, %rdx
callq 0x567e
movq -0x58(%rbp), %rdi
addq $0x48, %rdi
movq (%r14), %rax
movq 0x48(%rax), %rcx
movq 0x50(%rax), %rdx
leaq (%rcx,%rbx,8), %rsi
addq $0x8, %rsi
callq 0x567e
movq (%r12), %rdi
testq %rdi, %rdi
jne 0x3e54
leaq -0x90(%rbp), %rdi
movq -0x30(%rbp), %rbx
movq %rbx, %rsi
movl $0x2, %edx
callq 0x640c
movaps -0x90(%rbp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, -0x90(%rbp)
movq 0x78(%rbx), %rdi
movups %xmm0, 0x70(%rbx)
addq $0x78, %rbx
testq %rdi, %rdi
je 0x3e08
callq 0x277e
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x3e08
callq 0x277e
movq -0x30(%rbp), %r15
movq 0x70(%r15), %rax
movb $0x0, 0x79(%rax)
movq %rax, (%r12)
leaq 0x8(%r12), %rdi
movq %rbx, %rsi
callq 0x4f9a
movq 0x70(%r15), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x65ba
cmpl $0x0, -0x34(%rbp)
jne 0x3f22
movq (%r12), %rdi
addq $0x48, %rdi
movl $0x1, %esi
callq 0x4e00
movq (%r12), %rdi
movq 0x50(%rdi), %rax
subq 0x48(%rdi), %rax
shrq $0x3, %rax
movl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jle 0x3ee4
movslq %ecx, %rbx
movq %rbx, %rsi
shlq $0x6, %rsi
addq 0x60(%rdi), %rsi
addq $0x60, %rdi
movq (%r14), %rax
addq 0x60(%rax), %r13
movq %r13, %rdx
callq 0x4e38
movq -0xe0(%rbp), %rax
movq (%rax), %rax
movq (%r12), %rdi
movq 0x48(%rdi), %rcx
addq $0x48, %rdi
leaq (%rcx,%rbx,8), %rsi
addq $0x8, %rsi
movq %rax, -0x8(%rsi)
movq -0x58(%rbp), %rdx
callq 0x4ee0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x3ec1
callq 0x277e
movq -0xd8(%rbp), %rdi
testq %rdi, %rdi
je 0x3ed2
callq 0x277e
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4333(%rip), %rdi      # 0x821e
leaq 0x4240(%rip), %rsi      # 0x8132
leaq 0x427f(%rip), %rcx      # 0x8178
movl $0x9a, %edx
callq 0x2140
leaq 0x42ec(%rip), %rdi      # 0x81f6
leaq 0x4221(%rip), %rsi      # 0x8132
leaq 0x4260(%rip), %rcx      # 0x8178
movl $0x7c, %edx
callq 0x2140
leaq 0x42e6(%rip), %rdi      # 0x820f
leaq 0x4202(%rip), %rsi      # 0x8132
leaq 0x4241(%rip), %rcx      # 0x8178
movl $0x97, %edx
callq 0x2140
jmp 0x3f7a
jmp 0x3f7a
jmp 0x3f7a
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x3f58
callq 0x277e
movq -0x98(%rbp), %rdi
jmp 0x3fa0
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x4dca
jmp 0x3faa
jmp 0x3f7a
jmp 0x3f7a
jmp 0x3f7a
jmp 0x3f7a
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x3f90
callq 0x277e
jmp 0x3f90
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
jmp 0x3fa0
movq %rax, %rbx
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x3faa
callq 0x277e
movq %rbx, %rdi
callq 0x2300