// File: /workspace/github_cpp_makefile_star2_O3/rocket323[P]fishdb/./btree.cpp
// Function: fishdb::BTree::Delete(std::shared_ptr<fishdb::MemPage>, std::shared_ptr<fishdb::MemPage>, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
int BTree::Delete(std::shared_ptr<MemPage> now, std::shared_ptr<MemPage> parent,
        int child_idx, const std::string &key)
{
    auto iter = LowerBound(now, key);
    size_t p = iter - now->kvs.begin();

    int del_ret = BT_NOT_FOUND;
    if (iter != now->kvs.end() && Equal(iter->key, key))
    {
        if (!now->is_leaf)
        {
            auto left = ReadPage(now->children[p]);
            auto nd = left;
            while (!nd->is_leaf)
                nd = ReadPage(nd->children.back());

            now->kvs[p] = nd->kvs.back();
            Delete(left, now, p, nd->kvs.back().key);
        }
        else
            now->kvs.erase(iter);
        del_ret = BT_OK;
    }
    else if (!now->is_leaf)
        del_ret = Delete(ReadPage(now->children[p]), now, p, key);

    // maintain now
    if (now == m_root)
    {
        if (now->is_leaf || now->kvs.size() > 0) return del_ret;
        assert(now->children.size() == 1);
        m_root = ReadPage(now->children[0]);
    }
    else if ((int)now->kvs.size() < m_min_key_num)
        Maintain(now, parent, child_idx);

    return del_ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r8, %r14
movl %ecx, %r12d
movq %rdx, %r13
movq %rdi, %rbx
movq (%rsi), %rax
movq %rax, -0xd0(%rbp)
movq %rsi, -0x30(%rbp)
movq 0x8(%rsi), %rax
movq %rax, -0xc8(%rbp)
testq %rax, %rax
je 0x4005
movq 0x7fd9(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x4001
incl 0x8(%rax)
jmp 0x4005
lock
incl 0x8(%rax)
leaq -0xd0(%rbp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x35ee
movq %rax, %r15
movq %r13, -0xd8(%rbp)
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0x4032
callq 0x277e
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq %r15, %r13
subq 0x60(%rdi), %r13
movq %r13, %rax
sarq $0x6, %rax
movq %rax, -0x38(%rbp)
cmpq 0x68(%rdi), %r15
je 0x4084
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x359e
movq -0x30(%rbp), %rcx
movq (%rcx), %rdi
testb %al, %al
je 0x4084
cmpb $0x0, 0x79(%rdi)
je 0x40de
addq $0x60, %rdi
movq %r15, %rsi
callq 0x5b4a
xorl %r13d, %r13d
jmp 0x42c0
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
cmpb $0x0, 0x79(%rdi)
jne 0x42c0
movq 0x48(%rdi), %rax
movq -0x38(%rbp), %r15
movq (%rax,%r15,8), %rdx
leaq -0xe8(%rbp), %rdi
movq %rbx, %rsi
callq 0x353c
movq -0x30(%rbp), %rcx
movq (%rcx), %rax
movq %rax, -0xa0(%rbp)
movq 0x8(%rcx), %rax
movq %rax, -0x98(%rbp)
testq %rax, %rax
je 0x4124
movq 0x7efc(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x4120
incl 0x8(%rax)
jmp 0x4124
movl %r12d, -0x3c(%rbp)
movq 0x48(%rdi), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq -0x50(%rbp), %r14
movq %r14, %rdi
movq %rbx, -0x58(%rbp)
movq %rbx, %rsi
callq 0x353c
movq (%r14), %rbx
movq 0x8(%r14), %r12
testq %r12, %r12
je 0x4174
movq 0x7ebc(%rip), %rax      # 0xbfd0
cmpb $0x0, (%rax)
je 0x416e
incl 0x8(%r12)
jmp 0x4174
lock
incl 0x8(%rax)
leaq -0xe8(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
movq %rbx, %rdi
movl %r15d, %ecx
movq %r14, %r8
callq 0x3fb2
movl %eax, %r13d
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x4154
callq 0x277e
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x42c0
callq 0x277e
jmp 0x42c0
lock
incl 0x8(%r12)
cmpb $0x0, 0x79(%rbx)
jne 0x41c5
leaq -0x70(%rbp), %r15
movq %r12, %r14
movq 0x50(%rbx), %rax
movq -0x8(%rax), %rdx
movq %r15, %rdi
movq -0x58(%rbp), %rsi
callq 0x353c
movq -0x70(%rbp), %rbx
movq -0x68(%rbp), %r12
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
testq %r14, %r14
je 0x41bf
movq %r14, %rdi
callq 0x277e
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x41bf
callq 0x277e
cmpb $0x0, 0x79(%rbx)
je 0x417e
movq 0x68(%rbx), %r14
leaq -0x40(%r14), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rax
addq 0x60(%rax), %r13
movq %r13, %rdi
callq 0x2110
addq $0x20, %r13
addq $-0x20, %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x2110
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, -0xc0(%rbp)
movq %rax, -0xb8(%rbp)
testq %rax, %rax
movq -0x38(%rbp), %rcx
je 0x4227
movq 0x7db7(%rip), %rdx      # 0xbfd0
cmpb $0x0, (%rdx)
je 0x4223
incl 0x8(%rax)
jmp 0x4227
lock
incl 0x8(%rax)
movq -0x30(%rbp), %rdx
movq (%rdx), %rax
movq %rax, -0xb0(%rbp)
movq 0x8(%rdx), %rax
movq %rax, -0xa8(%rbp)
testq %rax, %rax
je 0x425a
movq 0x7d84(%rip), %rdx      # 0xbfd0
cmpb $0x0, (%rdx)
je 0x4256
incl 0x8(%rax)
jmp 0x425a
lock
incl 0x8(%rax)
movq 0x68(%rbx), %r8
addq $-0x40, %r8
leaq -0xc0(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x3fb2
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x428d
callq 0x277e
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x429e
callq 0x277e
testq %r12, %r12
je 0x42ab
movq %r12, %rdi
callq 0x277e
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x42b9
callq 0x277e
xorl %r13d, %r13d
movl -0x3c(%rbp), %r12d
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpq 0x70(%rbx), %rax
je 0x430e
movq 0x68(%rax), %rcx
subq 0x60(%rax), %rcx
shrq $0x6, %rcx
cmpl %ecx, 0x48(%rbx)
jle 0x43d9
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
testq %rax, %rax
je 0x4374
movq 0x7ccc(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x4370
incl 0x8(%rax)
jmp 0x4374
cmpb $0x0, 0x79(%rax)
jne 0x43d9
movq 0x68(%rax), %rcx
cmpq 0x60(%rax), %rcx
jne 0x43d9
movq 0x48(%rax), %rcx
movq 0x50(%rax), %rax
subq %rcx, %rax
cmpq $0x8, %rax
jne 0x43ee
movq (%rcx), %rdx
leaq -0x50(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x353c
movaps (%r14), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, (%r14)
movq 0x78(%rbx), %rdi
movups %xmm0, 0x70(%rbx)
testq %rdi, %rdi
je 0x43d9
callq 0x277e
movq -0x48(%rbp), %rdi
jmp 0x43cf
lock
incl 0x8(%rax)
movq -0xd8(%rbp), %rcx
movq (%rcx), %rax
movq %rax, -0x80(%rbp)
movq 0x8(%rcx), %rax
movq %rax, -0x78(%rbp)
testq %rax, %rax
je 0x43a4
movq 0x7c3a(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x43a0
incl 0x8(%rax)
jmp 0x43a4
lock
incl 0x8(%rax)
leaq -0x90(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movq %rbx, %rdi
movl %r12d, %ecx
callq 0x44a6
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x43c8
callq 0x277e
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x43d9
callq 0x277e
movl %r13d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e52(%rip), %rdi      # 0x8247
leaq 0x3d36(%rip), %rsi      # 0x8132
leaq 0x3e5e(%rip), %rcx      # 0x8261
movl $0xc3, %edx
callq 0x2140
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x4421
callq 0x277e
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x4482
callq 0x277e
jmp 0x4482
movq %rax, %rbx
jmp 0x4482
movq %rax, %rbx
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x444a
callq 0x277e
movq -0x88(%rbp), %rdi
jmp 0x4493
movq %rax, %rbx
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x4467
callq 0x277e
movq -0xe0(%rbp), %rdi
jmp 0x4493
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
jmp 0x4493
movq %rax, %rbx
movq %r14, %r12
testq %r12, %r12
je 0x448f
movq %r12, %rdi
callq 0x277e
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x449d
callq 0x277e
movq %rbx, %rdi
callq 0x2300
nop