// File: deepaktabraham[P]BPlus-Tree/src/internalnode.cpp
// Function: InternalNode::Split(float*)
Node* InternalNode :: Split(float* keyToParent)
{
	int length = keys.size();

	// create a new right internal node
	InternalNode* rightNode = new InternalNode;

	// key to be moved up to the parent is the middle element in the current internal node
	*keyToParent = keys[length/2];

	// Copy the second half of the current internal node excluding the middle element to the 
	// new right internal node. Erase the second half of the current internal node including 
	// the middle element, and thus current internal node becomes the left internal node.
	rightNode->keys.assign(keys.begin() + (length/2 + 1), keys.end());
	rightNode->children.assign(children.begin() + (length/2 + 1), children.end());
	keys.erase(keys.begin() + length/2, keys.end());
	children.erase(children.begin() + (length/2 + 1), children.end());

	// return the new right internal node
	return rightNode;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
addq $0x10, %rdi
callq 0x4480
movl %eax, -0x14(%rbp)
movl $0x40, %edi
callq 0x21a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc8(%rbp)
callq 0x72e0
jmp 0x7538
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rax
movq %rax, -0x20(%rbp)
addq $0x10, %rdi
movl -0x14(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movslq %eax, %rsi
callq 0x41c0
movq -0xd0(%rbp), %rdi
movss (%rax), %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, (%rax)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xf0(%rbp)
addq $0x10, %rdi
callq 0x4160
movq %rax, -0x40(%rbp)
movl -0x14(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x7e00
movq -0xd0(%rbp), %rdi
movq %rax, -0x38(%rbp)
addq $0x10, %rdi
callq 0x4190
movq -0xf0(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x7dc0
movq -0xd0(%rbp), %rdi
movq -0x20(%rbp), %rax
addq $0x28, %rax
movq %rax, -0xe8(%rbp)
addq $0x28, %rdi
callq 0x4300
movq %rax, -0x58(%rbp)
movl -0x14(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x7c60
movq -0xd0(%rbp), %rdi
movq %rax, -0x50(%rbp)
addq $0x28, %rdi
callq 0x4370
movq -0xe8(%rbp), %rdi
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x7e40
movq -0xd0(%rbp), %rdi
movq %rdi, %rax
addq $0x10, %rax
movq %rax, -0xe0(%rbp)
addq $0x10, %rdi
callq 0x4160
movq %rax, -0x78(%rbp)
movl -0x14(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movslq %eax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x7e00
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x7a20
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
callq 0x4190
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x7a20
movq -0xe0(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x80(%rbp), %rdx
callq 0x7e80
movq -0xd0(%rbp), %rdi
movq %rax, -0x90(%rbp)
movq %rdi, %rax
addq $0x28, %rax
movq %rax, -0xd8(%rbp)
addq $0x28, %rdi
callq 0x4300
movq %rax, -0xa8(%rbp)
movl -0x14(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movslq %eax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x7c60
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x7ca0
movq -0xd0(%rbp), %rdi
addq $0x28, %rdi
callq 0x4370
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x7ca0
movq -0xd8(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0xb0(%rbp), %rdx
callq 0x7f10
movq %rax, -0xc0(%rbp)
movq -0x20(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x2180
movq -0x28(%rbp), %rdi
callq 0x22d0