// File: /workspace/github_cpp_makefile_star2_O2/jaycelq[P]BPlusTree/BPlusTree.cpp
// Function: BPlusTree::insertNode(BPlusTree::Node*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, BPlusTree::Node*, std::stack<BPlusTree::Node*, std::deque<BPlusTree::Node*, std::allocator<BPlusTree::Node*>>>*)
void BPlusTree::insertNode(Node* node, int key, string v, Node *p, stack<Node*>* parent)
{
    Node* newNode;
    int newKey;
    if(node->keyNum < maxKeyNum) {
        if(node->isLeaf) ((leafNode*)node)->insert(key, v);
        else ((innerNode *)node)->insert(key, p);
    }
    else {
        if(node->isLeaf) {
            newNode = new leafNode();
            newKey = ((leafNode*)node)->split((leafNode *)newNode);

            if(key < newKey) {
                ((leafNode*)node)->insert(key, v);
            }
            else
                ((leafNode*)newNode)->insert(key, v);
        }
        else {
            newNode = new innerNode();
            newKey = ((innerNode*)node)->split(newNode, key);
            if(newKey == key) {
                ((innerNode *)newNode)->child[0] = p;
            }
            else if(newKey > key) {
                ((innerNode*)node)->insert(key, p);
            }
            else {
                ((innerNode*)newNode)->insert(key, p);
            }
        }

        if(node == root) {
            innerNode* newRoot = new innerNode();
            newRoot->keyNum = 1;
            newRoot->key[0] = newKey;
            newRoot->child[0] = node;
            newRoot->child[1] = newNode;
            root = newRoot;
        }
        else {
            Node* p = parent->top();
            parent->pop();
            insertNode(p, newKey, v, newNode, parent);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, %rbx
movl %edx, %ebp
movq %rsi, %r13
movq %rdi, 0x8(%rsp)
cmpl $0x2, 0xc(%rsi)
movb 0x8(%rsi), %al
jg 0x25e6
testb %al, %al
je 0x2646
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
movq %rcx, %rsi
callq 0x2170
movq %r13, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x2438
leaq 0x78(%rsp), %rdi
jmp 0x273d
movq %r9, %r14
movq %rcx, 0x10(%rsp)
testb %al, %al
je 0x2664
movl $0x90, %edi
callq 0x2130
movq %rax, %r12
movq %rax, %rdi
callq 0x2a3e
movq %r13, %rdi
movq %r12, %rsi
callq 0x24c2
movl %eax, %r15d
cmpl %ebp, %eax
jle 0x26a9
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x2170
movq %r13, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x2438
leaq 0x58(%rsp), %rdi
jmp 0x26cd
movq %r13, %rdi
movl %ebp, %esi
movq %rbx, %rdx
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2362
pushq $0x40
popq %rdi
callq 0x2130
movq %rax, %r12
andl $0x0, 0xc(%rax)
leaq 0x46de(%rip), %rax      # 0x6d58
movq %rax, (%r12)
movb $0x0, 0x8(%r12)
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x23a0
cmpl %ebp, %eax
jne 0x269f
movq %rbx, 0x10(%r12)
movl %ebp, %r15d
jmp 0x26e1
movl %eax, %r15d
jle 0x26d4
movq %r13, %rdi
jmp 0x26d7
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x2170
movq %r12, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x2438
leaq 0x38(%rsp), %rdi
callq 0x2080
jmp 0x26e1
movq %r12, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x2362
movq 0x8(%rsp), %rbp
cmpq %r13, (%rbp)
je 0x2744
movq 0x30(%r14), %rax
cmpq 0x38(%r14), %rax
jne 0x2703
movq 0x48(%r14), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rbx
movq %r14, %rdi
callq 0x2bb0
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0x2170
movq %rbp, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movq %r13, %rcx
movq %r12, %r8
movq %r14, %r9
callq 0x2590
leaq 0x18(%rsp), %rdi
callq 0x2080
jmp 0x2771
pushq $0x40
popq %rdi
callq 0x2130
leaq 0x4605(%rip), %rcx      # 0x6d58
movq %rcx, (%rax)
movb $0x0, 0x8(%rax)
movl $0x1, 0xc(%rax)
movl %r15d, 0x30(%rax)
movq %r13, 0x10(%rax)
movq %r12, 0x18(%rax)
movq %rax, (%rbp)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x27bb
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x27bb
movq %rax, %rbx
movl $0x90, %esi
movq %r12, %rdi
callq 0x2140
jmp 0x27c0
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x27bb
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x21d0