// File: /workspace/github_cpp_makefile_star2_O1/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, -0x40(%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 0x3b48
movq 0x8496(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x3b44
incl 0x8(%rax)
jmp 0x3b48
lock
incl 0x8(%rax)
leaq -0x78(%rbp), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x35cc
movq %rax, %rbx
movq %r13, -0x30(%rbp)
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x3b6c
callq 0x277e
movq (%r14), %rax
movq %rbx, %r13
subq 0x60(%rax), %r13
cmpq 0x68(%rax), %rbx
je 0x3ba8
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x357c
testb %al, %al
je 0x3ba8
addq $0x20, %rbx
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
callq 0x2110
movq -0x30(%rbp), %r15
jmp 0x3cc3
movq %r12, -0x58(%rbp)
movq (%r14), %r12
cmpb $0x0, 0x79(%r12)
je 0x3c1a
addq $0x60, %r12
leaq -0xe0(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq -0x40(%rbp), %rdx
callq 0x4d18
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x4ffc
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq -0x58(%rbp), %r12
movq -0x30(%rbp), %r15
je 0x3bfc
callq 0x21b0
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3cc3
callq 0x21b0
jmp 0x3cc3
testq %r12, %r12
je 0x3ef6
sarq $0x6, %r13
movq 0x48(%r12), %rax
movq 0x50(%r12), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
jbe 0x3f15
movq (%rax,%r13,8), %rdx
leaq -0xa0(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x351a
movq (%r14), %rax
movq %rax, -0x68(%rbp)
movq 0x8(%r14), %rax
movq %rax, -0x60(%rbp)
testq %rax, %rax
movq -0x58(%rbp), %r12
je 0x3c82
movq 0x835c(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x3c7e
incl 0x8(%rax)
jmp 0x3c82
lock
incl 0x8(%rax)
leaq -0xa0(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movq -0x30(%rbp), %rdi
movl %r13d, %ecx
movq %r15, %r8
movq -0x40(%rbp), %r9
callq 0x3af8
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x3cae
callq 0x277e
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
movq -0x30(%rbp), %r15
je 0x3cc3
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 0x3ec5
leaq -0xe0(%rbp), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x63b2
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x63b2
shrq %rbx
movq (%r14), %rax
movb 0x79(%rax), %cl
movq -0x50(%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 0x5356
movq -0x50(%rbp), %rdi
addq $0x60, %rdi
movq (%r14), %rax
movq 0x60(%rax), %rcx
movq 0x68(%rax), %rdx
leaq (%rcx,%r13), %rsi
addq $0x40, %rsi
callq 0x5356
movq (%r14), %rax
cmpb $0x0, 0x79(%rax)
jne 0x3d9c
movq -0xe0(%rbp), %rdi
addq $0x48, %rdi
movq 0x48(%rax), %rsi
leaq (%rsi,%rbx,8), %rdx
addq $0x8, %rdx
callq 0x5630
movq -0x50(%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 0x5630
cmpq $0x0, (%r12)
jne 0x3e43
leaq -0x90(%rbp), %rdi
movq -0x30(%rbp), %rbx
movq %rbx, %rsi
movl $0x2, %edx
callq 0x63b2
movaps -0x90(%rbp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, -0x90(%rbp)
movq 0x78(%rbx), %rdi
movups %xmm0, 0x70(%rbx)
testq %rdi, %rdi
je 0x3de2
callq 0x277e
movq -0x30(%rbp), %rax
leaq 0x78(%rax), %rbx
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x3dfb
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 0x4f50
movq 0x70(%r15), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x65b8
cmpl $0x0, -0x34(%rbp)
jne 0x3f34
movq (%r12), %rdi
addq $0x48, %rdi
movl $0x1, %esi
callq 0x4db6
movq (%r12), %rdi
movq 0x50(%rdi), %rax
subq 0x48(%rdi), %rax
shrq $0x3, %rax
movl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jle 0x3ed7
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 0x4dee
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 -0x50(%rbp), %rdx
callq 0x4e96
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x3eb4
callq 0x277e
movq -0xd8(%rbp), %rdi
testq %rdi, %rdi
je 0x3ec5
callq 0x277e
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4344(%rip), %rdi      # 0x8222
leaq 0x424d(%rip), %rsi      # 0x8132
leaq 0x4290(%rip), %rcx      # 0x817c
movl $0x9a, %edx
callq 0x2140
leaq 0x427b(%rip), %rdi      # 0x8178
leaq 0x422e(%rip), %rsi      # 0x8132
leaq 0x4271(%rip), %rcx      # 0x817c
movl $0x7b, %edx
callq 0x2140
leaq 0x42de(%rip), %rdi      # 0x81fa
leaq 0x420f(%rip), %rsi      # 0x8132
leaq 0x4252(%rip), %rcx      # 0x817c
movl $0x7c, %edx
callq 0x2140
leaq 0x42d8(%rip), %rdi      # 0x8213
leaq 0x41f0(%rip), %rsi      # 0x8132
leaq 0x4233(%rip), %rcx      # 0x817c
movl $0x97, %edx
callq 0x2140
jmp 0x3f8c
jmp 0x3f8c
jmp 0x3f8c
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x3f6a
callq 0x277e
movq -0x98(%rbp), %rdi
jmp 0x3fb2
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x4d80
jmp 0x3fbc
jmp 0x3f8c
jmp 0x3f8c
jmp 0x3f8c
jmp 0x3f8c
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x3fa2
callq 0x277e
jmp 0x3fa2
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
jmp 0x3fb2
movq %rax, %rbx
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x3fbc
callq 0x277e
movq %rbx, %rdi
callq 0x2300