// File: jaycelq[P]BPlusTree/BPlusTree.cpp
// Function: BPlusTree::put(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void BPlusTree::put(int key, string value)
{
    stack<Node *> parent;
    Node *n = root;
    if(root == NULL) {
        root = new leafNode();
        insertNode(root , key, value, NULL , &parent);
        return;
    }

    while(n->isLeaf == false) {
        innerNode *inner = (innerNode*) n;
        int slot = inner->getLower(key);
        parent.push(n);
        n = inner->child[slot];
    }

    leafNode *leaf = (leafNode *)n;

    int slot = leaf->getLower(key);
    if(slot > 0) slot -= 1; 
    if(leaf->key[slot] == key) leaf->value[slot] = value;
    else insertNode(leaf , key, value, NULL , &parent);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdx, -0xf8(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3500
movq -0xf0(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x70(%rbp)
cmpq $0x0, (%rax)
jne 0x3039
movl $0x90, %edi
callq 0x2170
movq %rax, -0x100(%rbp)
jmp 0x2f5c
movq -0x100(%rbp), %rdi
callq 0x33f0
jmp 0x2f6a
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rax
movq -0x100(%rbp), %rcx
movq %rcx, (%rax)
movq (%rax), %rax
movq %rax, -0x110(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x104(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x2090
jmp 0x2fa3
movl -0x104(%rbp), %edx
movq -0x110(%rbp), %rsi
movq -0xf0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %r8d
leaq -0xa0(%rbp), %rcx
leaq -0x68(%rbp), %r9
callq 0x2ac0
jmp 0x2fce
leaq -0xa0(%rbp), %rdi
callq 0x20d0
movl $0x1, -0xa4(%rbp)
jmp 0x31b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x31c7
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
movl $0x90, %esi
callq 0x2180
jmp 0x31c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x20d0
jmp 0x31c7
jmp 0x303b
movq -0x70(%rbp), %rax
movb 0x8(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x30a5
movq -0x70(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movl -0xc(%rbp), %esi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x114(%rbp)
jmp 0x3071
movl -0x114(%rbp), %eax
movl %eax, -0xb4(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3530
jmp 0x308c
movq -0xb0(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movq 0x10(%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
jmp 0x303b
movq -0x70(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
movl -0xc(%rbp), %esi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x118(%rbp)
jmp 0x30ca
movl -0x118(%rbp), %eax
movl %eax, -0xc4(%rbp)
cmpl $0x0, -0xc4(%rbp)
jle 0x30ee
movl -0xc4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xc4(%rbp)
movq -0xc0(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movl 0x70(%rax,%rcx,4), %eax
cmpl -0xc(%rbp), %eax
jne 0x312c
movq -0xf8(%rbp), %rsi
movq -0xc0(%rbp), %rax
movslq -0xc4(%rbp), %rcx
shlq $0x5, %rcx
leaq 0x10(%rax,%rcx), %rdi
callq 0x2030
jmp 0x312a
jmp 0x31ab
movq -0xf8(%rbp), %rsi
movq -0xc0(%rbp), %rax
movq %rax, -0x128(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x11c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x2090
jmp 0x3158
movl -0x11c(%rbp), %edx
movq -0x128(%rbp), %rsi
movq -0xf0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %r8d
leaq -0xe8(%rbp), %rcx
leaq -0x68(%rbp), %r9
callq 0x2ac0
jmp 0x3183
leaq -0xe8(%rbp), %rdi
callq 0x20d0
jmp 0x31ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x20d0
jmp 0x31c7
movl $0x0, -0xa4(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3560
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0x3560
movq -0x78(%rbp), %rdi
callq 0x2270
nopl (%rax)