// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rdi, -0x30(%rbp)
xorl %r13d, %r13d
cmpl $0x6, 0x68(%r15)
jl 0x1c2c
movq 0x18(%r15), %rbx
movl $0x80, %edi
callq 0x1140
movq %rax, %r14
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x68(%r14)
movq %r13, 0x70(%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movups %xmm0, 0x10(%r14)
movups %xmm0, 0x20(%r14)
movups %xmm0, 0x30(%r14)
movups %xmm0, 0x40(%r14)
movups %xmm0, 0x50(%r14)
movq %r13, 0x60(%r14)
movb $0x1, 0x78(%r14)
cmpb $0x0, 0x78(%r15)
je 0x1a6e
xorl %r12d, %r12d
movq %r15, %rdi
movl $0x3, %esi
callq 0x22e6
movslq 0x68(%r14), %rcx
cmpq %rcx, %r12
jge 0x19df
movq %rcx, %rdx
movq -0x8(%r14,%rdx,8), %rsi
movq %rsi, (%r14,%rdx,8)
leaq -0x1(%rdx), %rsi
movq %rsi, %rdx
cmpq %r12, %rsi
jg 0x19ca
cltq
movq %rax, (%r14,%r12,8)
incl %ecx
movl %ecx, 0x68(%r14)
movq %r15, %rdi
movl $0x3, %esi
callq 0x2338
movslq 0x6c(%r14), %rcx
cmpq %rcx, %r12
jge 0x1a1a
movq %rcx, %rdx
movq 0x28(%r14,%rdx,8), %rsi
movq %rsi, 0x30(%r14,%rdx,8)
leaq -0x1(%rdx), %rsi
movq %rsi, %rdx
cmpq %r12, %rsi
jg 0x1a04
movq %rax, 0x30(%r14,%r12,8)
incl %ecx
movl %ecx, 0x6c(%r14)
incq %r12
cmpq $0x3, %r12
jne 0x19b1
movq %r15, %rdi
movl $0x3, %esi
callq 0x2338
movq %rax, 0x48(%r14)
movslq 0x6c(%r15), %r12
cmpq $0x4, %r12
jl 0x1a5e
leaq 0x50(%r15), %rdi
leaq 0x48(%r15), %rsi
leaq -0x18(,%r12,8), %rdx
callq 0x1190
movq %r14, 0x48(%r15)
incl %r12d
movl %r12d, 0x6c(%r15)
jmp 0x1b14
xorl %r12d, %r12d
movq %r15, %rdi
movl $0x4, %esi
callq 0x22e6
movslq 0x68(%r14), %rcx
cmpq %rcx, %r12
jge 0x1a9f
movq %rcx, %rdx
movq -0x8(%r14,%rdx,8), %rsi
movq %rsi, (%r14,%rdx,8)
leaq -0x1(%rdx), %rsi
movq %rsi, %rdx
cmpq %r12, %rsi
jg 0x1a8a
cltq
movq %rax, (%r14,%r12,8)
incl %ecx
movl %ecx, 0x68(%r14)
movq %r15, %rdi
movl $0x4, %esi
callq 0x2338
movslq 0x6c(%r14), %rcx
cmpq %rcx, %r12
jge 0x1ada
movq %rcx, %rdx
movq 0x28(%r14,%rdx,8), %rsi
movq %rsi, 0x30(%r14,%rdx,8)
leaq -0x1(%rdx), %rsi
movq %rsi, %rdx
cmpq %r12, %rsi
jg 0x1ac4
movq %rax, 0x30(%r14,%r12,8)
incl %ecx
movl %ecx, 0x6c(%r14)
leaq 0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
je 0x1a71
movq %r15, %rdi
movl $0x4, %esi
callq 0x2338
movq %rax, 0x40(%r14)
movq %r15, %rdi
movl $0x3, %esi
callq 0x22e6
movb 0x78(%r15), %al
movb %al, 0x78(%r14)
movq 0x70(%r15), %rcx
movq %rcx, 0x70(%r14)
testb %al, %al
jne 0x1b44
movslq 0x6c(%r14), %rax
testq %rax, %rax
jle 0x1b44
xorl %ecx, %ecx
movq 0x30(%r14,%rcx,8), %rdx
movq %r14, 0x70(%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x1b33
movq 0x70(%r15), %rax
testq %rax, %rax
je 0x1bcb
movslq 0x68(%rax), %rdx
movl %edx, %ecx
testq %rdx, %rdx
jle 0x1b68
xorl %edi, %edi
cmpq %rbx, (%rax,%rdi,8)
jg 0x1b6a
incq %rdi
cmpq %rdi, %rcx
jne 0x1b5a
movl %ecx, %edi
movslq %edi, %rsi
cmpl %edi, %ecx
jle 0x1b86
movq -0x8(%rax,%rdx,8), %rdi
movq %rdi, (%rax,%rdx,8)
leaq -0x1(%rdx), %rdi
movq %rdi, %rdx
cmpq %rsi, %rdi
jg 0x1b71
movq %rbx, (%rax,%rsi,8)
incl %ecx
movl %ecx, 0x68(%rax)
incl %esi
movslq 0x6c(%rax), %rcx
movslq %esi, %rdx
cmpl %esi, %ecx
jle 0x1bb5
movq %rcx, %rsi
movq 0x28(%rax,%rsi,8), %rdi
movq %rdi, 0x30(%rax,%rsi,8)
leaq -0x1(%rsi), %rdi
movq %rdi, %rsi
cmpq %rdx, %rdi
jg 0x1b9f
movq %r14, 0x30(%rax,%rdx,8)
incl %ecx
movl %ecx, 0x6c(%rax)
movq %rax, 0x70(%r14)
movq %rax, %r15
jmp 0x194c
movl $0x80, %edi
callq 0x1140
xorl %ecx, %ecx
movq %rcx, 0x70(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x50(%rax)
movq %rcx, 0x60(%rax)
movq %r15, 0x30(%rax)
movq %r14, 0x38(%rax)
movq %rbx, (%rax)
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x68(%rax)
movl $0x2, 0x6c(%rax)
movb $0x0, 0x78(%rax)
movq %rax, 0x70(%r15)
movq %rax, 0x70(%r14)
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop