// File: /workspace/github_cpp_makefile_star2_O1/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 $0xb8, %rsp
movq %r8, %r14
movl %ecx, %r13d
movq %rdx, -0xc8(%rbp)
movq %rsi, %r12
movq %rdi, %r15
movq (%rsi), %rax
movq %rax, -0xc0(%rbp)
movq 0x8(%rsi), %rax
movq %rax, -0xb8(%rbp)
testq %rax, %rax
je 0x401a
movq 0x7fc4(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x4016
incl 0x8(%rax)
jmp 0x401a
lock
incl 0x8(%rax)
leaq -0xc0(%rbp), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x35cc
movq %rax, %rbx
movl %r13d, -0x3c(%rbp)
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x4044
callq 0x277e
movq (%r12), %rax
movq %rbx, %r13
subq 0x60(%rax), %r13
movq %r13, %rcx
sarq $0x6, %rcx
movq %rcx, -0x30(%rbp)
cmpq 0x68(%rax), %rbx
je 0x4090
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x357c
testb %al, %al
je 0x4090
movq (%r12), %rdi
cmpb $0x0, 0x79(%rdi)
je 0x40ec
addq $0x60, %rdi
movq %rbx, %rsi
callq 0x5ae8
xorl %r13d, %r13d
jmp 0x42c1
movq (%r12), %rax
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
cmpb $0x0, 0x79(%rax)
jne 0x42c1
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rbx
movq (%rax,%rbx,8), %rdx
leaq -0xd8(%rbp), %rdi
movq %r15, %rsi
callq 0x351a
movq (%r12), %rax
movq %rax, -0x90(%rbp)
movq 0x8(%r12), %rax
movq %rax, -0x88(%rbp)
testq %rax, %rax
je 0x4129
movq 0x7eee(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x4125
incl 0x8(%rax)
jmp 0x4129
movq 0x48(%rdi), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq -0x50(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x351a
movq (%r14), %rbx
movq 0x8(%r14), %r14
testq %r14, %r14
je 0x4177
movq 0x7eb6(%rip), %rax      # 0xbfd0
cmpb $0x0, (%rax)
je 0x4172
incl 0x8(%r14)
jmp 0x4177
lock
incl 0x8(%rax)
leaq -0xd8(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movq %r15, %rdi
movl %ebx, %ecx
movq %r14, %r8
callq 0x3fc4
movl %eax, %r13d
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x4158
callq 0x277e
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x42c1
callq 0x277e
jmp 0x42c1
lock
incl 0x8(%r14)
movq %r15, -0x38(%rbp)
cmpb $0x0, 0x79(%rbx)
je 0x4186
movq %r14, %r15
jmp 0x41ce
movq 0x50(%rbx), %rax
movq -0x8(%rax), %rdx
leaq -0x60(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x351a
movq -0x60(%rbp), %rbx
movq -0x58(%rbp), %r15
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
testq %r14, %r14
je 0x41b7
movq %r14, %rdi
callq 0x277e
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x41c5
callq 0x277e
cmpb $0x0, 0x79(%rbx)
movq %r15, %r14
je 0x4186
movq 0x68(%rbx), %r14
leaq -0x40(%r14), %rsi
movq (%r12), %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, -0xb0(%rbp)
movq %rax, -0xa8(%rbp)
testq %rax, %rax
movq -0x30(%rbp), %rcx
je 0x422d
movq 0x7db1(%rip), %rdx      # 0xbfd0
cmpb $0x0, (%rdx)
je 0x4229
incl 0x8(%rax)
jmp 0x422d
lock
incl 0x8(%rax)
movq (%r12), %rax
movq %rax, -0xa0(%rbp)
movq 0x8(%r12), %rax
movq %rax, -0x98(%rbp)
testq %rax, %rax
je 0x425e
movq 0x7d80(%rip), %rdx      # 0xbfd0
cmpb $0x0, (%rdx)
je 0x425a
incl 0x8(%rax)
jmp 0x425e
lock
incl 0x8(%rax)
movq 0x68(%rbx), %r8
addq $-0x40, %r8
leaq -0xb0(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
movq -0x38(%rbp), %rdi
callq 0x3fc4
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x428e
callq 0x277e
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x429f
callq 0x277e
testq %r15, %r15
je 0x42ac
movq %r15, %rdi
callq 0x277e
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x42ba
callq 0x277e
xorl %r13d, %r13d
movq -0x38(%rbp), %r15
movq (%r12), %rax
cmpq 0x70(%r15), %rax
je 0x4304
movq 0x68(%rax), %rcx
subq 0x60(%rax), %rcx
shrq $0x6, %rcx
cmpl %ecx, 0x48(%r15)
jle 0x43c8
movq %rax, -0x80(%rbp)
movq 0x8(%r12), %rax
movq %rax, -0x78(%rbp)
testq %rax, %rax
je 0x4369
movq 0x7cd6(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x4365
incl 0x8(%rax)
jmp 0x4369
cmpb $0x0, 0x79(%rax)
jne 0x43c8
movq 0x68(%rax), %rcx
cmpq 0x60(%rax), %rcx
jne 0x43c8
movq 0x48(%rax), %rcx
movq 0x50(%rax), %rax
subq %rcx, %rax
cmpq $0x8, %rax
jne 0x43dd
movq (%rcx), %rdx
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x351a
movaps (%rbx), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, (%rbx)
movq 0x78(%r15), %rdi
movups %xmm0, 0x70(%r15)
testq %rdi, %rdi
je 0x435f
callq 0x277e
movq -0x48(%rbp), %rdi
jmp 0x43be
lock
incl 0x8(%rax)
movq -0xc8(%rbp), %rcx
movq (%rcx), %rax
movq %rax, -0x70(%rbp)
movq 0x8(%rcx), %rax
movq %rax, -0x68(%rbp)
testq %rax, %rax
je 0x4399
movq 0x7c45(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x4395
incl 0x8(%rax)
jmp 0x4399
lock
incl 0x8(%rax)
leaq -0x80(%rbp), %rsi
leaq -0x70(%rbp), %rdx
movq %r15, %rdi
movl -0x3c(%rbp), %ecx
callq 0x4492
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x43ba
callq 0x277e
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x43c8
callq 0x277e
movl %r13d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e67(%rip), %rdi      # 0x824b
leaq 0x3d47(%rip), %rsi      # 0x8132
leaq 0x3e73(%rip), %rcx      # 0x8265
movl $0xc3, %edx
callq 0x2140
movq %rax, %rbx
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x4410
callq 0x277e
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x446e
callq 0x277e
jmp 0x446e
movq %rax, %rbx
jmp 0x446e
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x4439
callq 0x277e
movq -0x78(%rbp), %rdi
jmp 0x447f
movq %rax, %rbx
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x4453
callq 0x277e
movq -0xd0(%rbp), %rdi
jmp 0x447f
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
jmp 0x447f
movq %rax, %rbx
movq %r14, %r15
testq %r15, %r15
je 0x447b
movq %r15, %rdi
callq 0x277e
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x4489
callq 0x277e
movq %rbx, %rdi
callq 0x2300
nop