// File: deepaktabraham[P]BPlus-Tree/src/leafnode.cpp
// Function: LeafNode::Split(float*)
Node* LeafNode :: Split(float* keyToParent)
{
	// create a new right leaf node
	LeafNode* rightNode = new LeafNode;

	// key to be moved up to the parent is the middle element in the current leaf node
	*keyToParent = keys[keys.size()/2];

	// Copy the second half of the current leaf node to the new right leaf node. Erase the second
	// half of the current leaf node, and thus the current leaf node becomes the left leaf node.
	rightNode->keys.assign(keys.begin() + keys.size()/2, keys.end());
	rightNode->values.assign(values.begin() + values.size()/2, values.end());
	keys.erase(keys.begin() + keys.size()/2, keys.end());
	values.erase(values.begin() + values.size()/2, values.end());

	// link the leaf nodes to form a doubly linked list
	rightNode->next = next;
	rightNode->prev = this;
	next = rightNode;
	(rightNode->next)->prev = rightNode;

	// return the right leaf node
	return rightNode;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movl $0x50, %edi
callq 0x21a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
callq 0xadb0
jmp 0xb11c
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movq %rax, -0x18(%rbp)
movq %rdi, %rax
addq $0x10, %rax
movq %rax, -0xf0(%rbp)
addq $0x10, %rdi
callq 0x4480
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
shrq %rsi
callq 0x41c0
movq -0xc8(%rbp), %rdi
movss (%rax), %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, (%rax)
movq -0x18(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xe8(%rbp)
addq $0x10, %rdi
callq 0x4160
movq -0xc8(%rbp), %rdi
movq %rax, -0x38(%rbp)
addq $0x10, %rdi
callq 0x4480
movq %rax, %rsi
shrq %rsi
leaq -0x38(%rbp), %rdi
callq 0x7e00
movq -0xc8(%rbp), %rdi
movq %rax, -0x30(%rbp)
addq $0x10, %rdi
callq 0x4190
movq -0xe8(%rbp), %rdi
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x7dc0
movq -0xc8(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x38, %rax
movq %rax, -0xe0(%rbp)
addq $0x38, %rdi
callq 0xb6e0
movq -0xc8(%rbp), %rdi
movq %rax, -0x50(%rbp)
addq $0x38, %rdi
callq 0xb7d0
movq %rax, %rsi
shrq %rsi
leaq -0x50(%rbp), %rdi
callq 0xb710
movq -0xc8(%rbp), %rdi
movq %rax, -0x48(%rbp)
addq $0x38, %rdi
callq 0xb800
movq -0xe0(%rbp), %rdi
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0xb790
movq -0xc8(%rbp), %rdi
movq %rdi, %rax
addq $0x10, %rax
movq %rax, -0xd8(%rbp)
addq $0x10, %rdi
callq 0x4160
movq -0xc8(%rbp), %rdi
movq %rax, -0x70(%rbp)
addq $0x10, %rdi
callq 0x4480
movq %rax, %rsi
shrq %rsi
leaq -0x70(%rbp), %rdi
callq 0x7e00
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x7a20
movq -0xc8(%rbp), %rdi
addq $0x10, %rdi
callq 0x4190
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x7a20
movq -0xd8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x7e80
movq -0xc8(%rbp), %rdi
movq %rax, -0x88(%rbp)
movq %rdi, %rax
addq $0x38, %rax
movq %rax, -0xd0(%rbp)
addq $0x38, %rdi
callq 0xb6e0
movq -0xc8(%rbp), %rdi
movq %rax, -0xa0(%rbp)
addq $0x38, %rdi
callq 0xb7d0
movq %rax, %rsi
shrq %rsi
leaq -0xa0(%rbp), %rdi
callq 0xb710
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xb750
movq -0xc8(%rbp), %rdi
addq $0x38, %rdi
callq 0xb800
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xb750
movq -0xd0(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0xb830
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, -0xb8(%rbp)
movq 0x30(%rax), %rdx
movq -0x18(%rbp), %rcx
movq %rdx, 0x30(%rcx)
movq -0x18(%rbp), %rcx
movq %rax, 0x28(%rcx)
movq -0x18(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x2180
movq -0x20(%rbp), %rdi
callq 0x22d0
nopl (%rax)