// File: jaycelq[P]BPlusTree/BPlusTree.cpp
// Function: BPlusTree::innerNode::split(BPlusTree::Node*, int)
int BPlusTree::innerNode::split(Node*  newNode, int k)
{
    if(k > key[minKeyNum] && k < key[minKeyNum+1]) {
        for(int i = 0; i < minKeyNum; i++) {
            ((innerNode *)newNode)->key[i] = key[i+minKeyNum+1];
            ((innerNode *)newNode)->child[i+1] = child[i+minKeyNum+2];
        }
        newNode->keyNum = minKeyNum;
        keyNum = minKeyNum + 1;
        return k;
    }
    else {
        int retkey = 0;
        if(k > key[minKeyNum + 1]) {
            retkey = key[minKeyNum + 1];
            for(int i = 0; i < minKeyNum - 1; i++) {
                ((innerNode *)newNode)->key[i] = key[i + minKeyNum + 2];
                ((innerNode *)newNode)->child[i+1] = child[i+minKeyNum+3];
            }
            ((innerNode *)newNode)->child[0] = child[minKeyNum + 2];
            newNode->keyNum = minKeyNum - 1;
            keyNum = minKeyNum + 1;
            return retkey;
        }
        else {
            retkey = key[minKeyNum];
            for(int i = 0; i < minKeyNum; i++) {
                ((innerNode *)newNode)->key[i] = key[i + minKeyNum + 1];
                ((innerNode *)newNode)->child[i+1] = child[i+minKeyNum+2];
            }
            ((innerNode *)newNode)->child[0] = child[minKeyNum + 1];
            newNode->keyNum = minKeyNum;
            keyNum = minKeyNum;
            return retkey;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x38(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x34(%rcx), %eax
jle 0x262b
movq -0x38(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x262b
movl $0x0, -0x20(%rbp)
cmpl $0x1, -0x20(%rbp)
jge 0x260a
movq -0x38(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl 0x30(%rax,%rcx,4), %esi
movq -0x18(%rbp), %rcx
movslq -0x20(%rbp), %rdx
movl %esi, 0x30(%rcx,%rdx,4)
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x10(%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x25b6
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movl $0x1, 0xc(%rcx)
movl $0x2, 0xc(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2761
movq -0x38(%rbp), %rcx
movl $0x0, -0x24(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x38(%rcx), %eax
jle 0x26d4
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jge 0x26a7
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movl 0x30(%rax,%rcx,4), %esi
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movl %esi, 0x30(%rcx,%rdx,4)
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x10(%rax,%rcx,8)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2653
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdx
movq -0x18(%rbp), %rcx
movq %rdx, 0x10(%rcx)
movq -0x18(%rbp), %rcx
movl $0x0, 0xc(%rcx)
movl $0x2, 0xc(%rax)
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2761
movq -0x38(%rbp), %rax
movl 0x34(%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x1, -0x2c(%rbp)
jge 0x2739
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl 0x30(%rax,%rcx,4), %esi
movq -0x18(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movl %esi, 0x30(%rcx,%rdx,4)
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x10(%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x26e5
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x18(%rbp), %rcx
movq %rdx, 0x10(%rcx)
movq -0x18(%rbp), %rcx
movl $0x1, 0xc(%rcx)
movl $0x1, 0xc(%rax)
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)