// File: /workspace/github_cpp_makefile_star2_O2/CoderUper[P]BTree/BTree.cpp
// Function: BTree::SolveOverflow(Node*)
void BTree::SolveOverflow(Node* node)
{
    //判断是否需要上溢操作
    if(node->key_num<2*M) return;
    //存储要分裂的关键之
    keyType e=node->key[M];
    //生成新节点，并赋值
    Node* new_node=create_node();
    //判断用B+树还是B树分裂法
    if(node->is_leaf)
    {
        for(int i=0;i<M;i++)
        {
            new_node->key_insert(i,node->key_remove(M));
            new_node->child_insert(i,node->child_remove(M));
        }
        new_node->child[M]=node->child_remove(M);
        node->child_insert(M,new_node);
    }
    else
    {
        for(int i=0;i<M-1;i++)
        {
            new_node->key_insert(i,node->key_remove(M+1));
            new_node->child_insert(i,node->child_remove(M+1));
        }
        new_node->child[M-1]=node->child_remove(M+1);
        node->key_remove(M);
    }
    new_node->is_leaf=node->is_leaf;
    new_node->parent=node->parent;
    if(!new_node->is_leaf)
        for(int i=0;i<new_node->child_num;i++)
            new_node->child[i]->parent=new_node;
    //分裂的点是根节点
    if(node->parent==NULL)
    {
        //初始化新根节点
        Node* new_root=create_node();
        new_root->child[0]=node;
        new_root->child[1]=new_node;
        new_root->key[0]=e;
        new_root->key_num=1;
        new_root->child_num=2;
        new_root->is_leaf=false;
        node->parent=new_root;
        new_node->parent=new_root;
        root=new_root;

    }
    //分裂点不是根节点
    else
    {
        Node* p=node->parent;
        int pos=p->search(e);
        p->key_insert(pos+1,e);
        p->child_insert(pos+2,new_node);
        new_node->parent=p;
        SolveOverflow(p);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r13
movq %rdi, -0x30(%rbp)
cmpl $0x6, 0x68(%r13)
jl 0x1a0c
movq 0x18(%r13), %r15
callq 0x16d0
movq %rax, %r12
cmpb $0x0, 0x78(%r13)
je 0x18e6
xorl %ebx, %ebx
movq %r13, %rdi
cmpl $0x3, %ebx
je 0x1925
pushq $0x3
popq %r14
movl %r14d, %esi
callq 0x1f24
movslq %eax, %rdx
movq %r12, %rdi
movl %ebx, %esi
callq 0x1eca
movq %r13, %rdi
movl %r14d, %esi
callq 0x1f72
movq %r12, %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0x1ef6
incl %ebx
jmp 0x18a9
xorl %ebx, %ebx
movq %r13, %rdi
cmpl $0x2, %ebx
je 0x1943
pushq $0x4
popq %r14
movl %r14d, %esi
callq 0x1f24
movslq %eax, %rdx
movq %r12, %rdi
movl %ebx, %esi
callq 0x1eca
movq %r13, %rdi
movl %r14d, %esi
callq 0x1f72
movq %r12, %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0x1ef6
incl %ebx
jmp 0x18e8
pushq $0x3
popq %rbx
movl %ebx, %esi
callq 0x1f72
movq %rax, 0x48(%r12)
movq %r13, %rdi
movl %ebx, %esi
movq %r12, %rdx
callq 0x1ef6
jmp 0x195b
pushq $0x4
popq %rsi
callq 0x1f72
movq %rax, 0x40(%r12)
movq %r13, %rdi
pushq $0x3
popq %rsi
callq 0x1f24
movb 0x78(%r13), %al
movb %al, 0x78(%r12)
movq 0x70(%r13), %rbx
movq %rbx, 0x70(%r12)
testb %al, %al
jne 0x1999
movl 0x6c(%r12), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x1995
movq 0x30(%r12,%rcx,8), %rdx
movq %r12, 0x70(%rdx)
incq %rcx
jmp 0x1982
movq 0x70(%r13), %rbx
testq %rbx, %rbx
je 0x19da
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1ea8
movl %eax, %r13d
leal 0x1(%r13), %esi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x1eca
addl $0x2, %r13d
movq %rbx, %rdi
movl %r13d, %esi
movq %r12, %rdx
callq 0x1ef6
movq %rbx, 0x70(%r12)
movq %rbx, %r13
jmp 0x1889
callq 0x16d0
movq %r13, 0x30(%rax)
movq %r12, 0x38(%rax)
movq %r15, (%rax)
movabsq $0x200000001, %rcx      # imm = 0x200000001
movq %rcx, 0x68(%rax)
movb $0x0, 0x78(%rax)
movq %rax, 0x70(%r13)
movq %rax, 0x70(%r12)
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop