// File: 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
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rcx, -0xf0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x3, 0xc(%rax)
jge 0x2b8c
movq -0x10(%rbp), %rax
testb $0x1, 0x8(%rax)
je 0x2b77
movq -0xf0(%rbp), %rsi
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0xfc(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x2090
movq -0x108(%rbp), %rdi
movl -0xfc(%rbp), %esi
movq -0xf8(%rbp), %rdx
callq 0x27f0
jmp 0x2b52
leaq -0x60(%rbp), %rdi
callq 0x20d0
jmp 0x2b87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x20d0
jmp 0x2eee
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x24b0
jmp 0x2ee5
movq -0x10(%rbp), %rax
testb $0x1, 0x8(%rax)
je 0x2cf1
movl $0x90, %edi
callq 0x2170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x110(%rbp)
callq 0x33f0
jmp 0x2bb8
movq -0x110(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x28e0
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x2c78
movq -0xf0(%rbp), %rsi
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x11c(%rbp)
leaq -0x90(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x2090
movq -0x128(%rbp), %rdi
movl -0x11c(%rbp), %esi
movq -0x118(%rbp), %rdx
callq 0x27f0
jmp 0x2c28
leaq -0x90(%rbp), %rdi
callq 0x20d0
jmp 0x2cec
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movl $0x90, %esi
callq 0x2180
jmp 0x2eee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x20d0
jmp 0x2eee
movq -0xf0(%rbp), %rsi
movq -0x38(%rbp), %rax
movq %rax, -0x140(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x134(%rbp)
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x2090
movq -0x140(%rbp), %rdi
movl -0x134(%rbp), %esi
movq -0x130(%rbp), %rdx
callq 0x27f0
jmp 0x2cc1
leaq -0xb0(%rbp), %rdi
callq 0x20d0
jmp 0x2cec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x20d0
jmp 0x2eee
jmp 0x2d93
movl $0x40, %edi
callq 0x2170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x148(%rbp)
callq 0x3480
jmp 0x2d0f
movq -0x148(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x2580
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x2d65
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x2d91
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movl $0x40, %esi
callq 0x2180
jmp 0x2eee
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0x2d7f
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x24b0
jmp 0x2d8f
movq -0x38(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x24b0
jmp 0x2d91
jmp 0x2d93
movq -0xe8(%rbp), %rcx
movq -0x10(%rbp), %rax
cmpq (%rcx), %rax
jne 0x2e44
movl $0x40, %edi
callq 0x2170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x150(%rbp)
callq 0x3480
jmp 0x2dc5
movq -0xe8(%rbp), %rax
movq -0x150(%rbp), %rcx
movq %rcx, -0xb8(%rbp)
movq -0xb8(%rbp), %rcx
movl $0x1, 0xc(%rcx)
movl -0x3c(%rbp), %edx
movq -0xb8(%rbp), %rcx
movl %edx, 0x30(%rcx)
movq -0x10(%rbp), %rdx
movq -0xb8(%rbp), %rcx
movq %rdx, 0x10(%rcx)
movq -0x38(%rbp), %rdx
movq -0xb8(%rbp), %rcx
movq %rdx, 0x18(%rcx)
movq -0xb8(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x2ee3
movq -0x150(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movl $0x40, %esi
callq 0x2180
jmp 0x2eee
movq -0x30(%rbp), %rdi
callq 0x34c0
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x30(%rbp), %rdi
callq 0x34e0
movq -0xf0(%rbp), %rsi
movq -0xc0(%rbp), %rax
movq %rax, -0x168(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x15c(%rbp)
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x2090
movq -0xe8(%rbp), %rdi
movq -0x168(%rbp), %rsi
movl -0x15c(%rbp), %edx
movq -0x158(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0x2ac0
jmp 0x2ebb
leaq -0xe0(%rbp), %rdi
callq 0x20d0
jmp 0x2ee3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x20d0
jmp 0x2eee
jmp 0x2ee5
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x2270
nopw (%rax,%rax)