// File: deepaktabraham[P]BPlus-Tree/src/leafnode.cpp
// Function: LeafNode::Insert(float, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void LeafNode :: Insert(float key, string value)
{
	// search for the key in the given leaf node
	vector<float>::iterator index = lower_bound(keys.begin(), keys.end(), key);

	// check if inserting a duplicate value for an existing key
	if((0 != keys.size()) && (key == keys[index - keys.begin()]))
	{
		// add the duplicate value for the given key
		values[index - keys.begin()].push_back(value);
	}

	// if inserting a new key and value
	else
	{
		// insert the new key
		keys.insert(index, key);

		//insert the corresponding value
		vector<string> newValue;
		newValue.push_back(value);
		index = lower_bound(keys.begin(), keys.end(), key);	
		values.insert(values.begin() + (index - keys.begin()), newValue);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rsi, -0xd0(%rbp)
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
addq $0x10, %rdi
callq 0x4160
movq -0xc8(%rbp), %rdi
movq %rax, -0x28(%rbp)
addq $0x10, %rdi
callq 0x4190
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0xc(%rbp), %rdx
callq 0x4110
movq -0xc8(%rbp), %rdi
movq %rax, -0x20(%rbp)
addq $0x10, %rdi
callq 0x4480
movq %rax, %rdx
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rdx, %rcx
movb %al, -0xb9(%rbp)
je 0xaee6
movq -0xc8(%rbp), %rdi
movss -0xc(%rbp), %xmm0
movss %xmm0, -0xd4(%rbp)
movq %rdi, %rax
addq $0x10, %rax
movq %rax, -0xe0(%rbp)
addq $0x10, %rdi
callq 0x4160
movq %rax, -0x38(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41e0
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
callq 0x41c0
movss -0xd4(%rbp), %xmm0
ucomiss (%rax), %xmm0
sete %al
setnp %cl
andb %cl, %al
movb %al, -0xb9(%rbp)
movb -0xb9(%rbp), %al
testb $0x1, %al
jne 0xaef2
jmp 0xaf44
movq -0xc8(%rbp), %rdi
movq %rdi, %rax
addq $0x38, %rax
movq %rax, -0xe8(%rbp)
addq $0x10, %rdi
callq 0x4160
movq %rax, -0x40(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x41e0
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x4500
movq -0xd0(%rbp), %rsi
movq %rax, %rdi
callq 0xb450
jmp 0xb0c2
movq -0xc8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xf8(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x7a20
movq -0xf8(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0xc(%rbp), %rdx
callq 0x7820
movq %rax, -0x50(%rbp)
leaq -0x68(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0xb4c0
movq -0xf0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0xb450
jmp 0xafa0
movq -0xc8(%rbp), %rdi
addq $0x10, %rdi
movq %rdi, -0x108(%rbp)
callq 0x4160
movq -0x108(%rbp), %rdi
movq %rax, -0x88(%rbp)
callq 0x4190
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
leaq -0xc(%rbp), %rdx
callq 0x4110
movq %rax, -0x100(%rbp)
jmp 0xaff1
movq -0xc8(%rbp), %rdi
movq -0x100(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x20(%rbp)
addq $0x38, %rdi
movq %rdi, -0x118(%rbp)
callq 0xb6e0
movq -0xc8(%rbp), %rdi
movq %rax, -0xa8(%rbp)
addq $0x10, %rdi
callq 0x4160
movq %rax, -0xb0(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x41e0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0xb710
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xb750
movq -0x118(%rbp), %rdi
movq -0x98(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0xb4e0
movq %rax, -0x110(%rbp)
jmp 0xb092
movq -0x110(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x6350
jmp 0xb0c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x6350
jmp 0xb0cb
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x22d0
nopw %cs:(%rax,%rax)