// File: /workspace/github_cpp_makefile_star2_O1/deepaktabraham[P]BPlus-Tree/src/tree.cpp
// Function: BPlusTree::Search(float)
void BPlusTree :: Search(float key)
{
	// check if tree is empty
	if(NULL == root)
	{
		outputFile<<"Null"<<endl;
	}

	// if it is a vaild search
	else
	{
		int i = 0;	
		
		// obtain the search path from root to leaf node and push it on to a stack
		stack<Node*>* path = new stack<Node*>;
		Search_Path(root, key, path);
		
		// search for the key in the leaf node, which is at the top of the stack
		vector<float> keys = path->top()->Get_Keys();
		vector< vector <string> > values = path->top()->Get_Values(); 
		vector<float>::iterator index = lower_bound(keys.begin(), keys.end(), key);

		// check if key is found
		if(key == keys[index - keys.begin()])
		{
			// display the values
			for(i = 0; i < values[index - keys.begin()].size() - 1; i++)
			{
				outputFile<<values[index - keys.begin()][i]<<",";
			}
			outputFile<<values[index - keys.begin()][i]<<endl;
		}

		// if key is not found
		else
		{
			outputFile<<"Null"<<endl;
		}

		delete(path);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
cmpq $0x0, 0x8(%rdi)
je 0x32ca
movss %xmm0, -0x30(%rbp)
movl $0x50, %edi
callq 0x2170
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movq %rax, %rdi
xorl %esi, %esi
callq 0x3cc2
movq 0x8(%r14), %rsi
movq %r14, %rdi
movss -0x30(%rbp), %xmm0
movq %rbx, %rdx
callq 0x2d00
movq 0x30(%rbx), %rax
cmpq 0x38(%rbx), %rax
jne 0x3210
movq 0x48(%rbx), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rsi
leaq -0x48(%rbp), %rdi
callq 0x3eca
movq 0x30(%rbx), %rax
cmpq 0x38(%rbx), %rax
jne 0x3234
movq 0x48(%rbx), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rsi
movq (%rsi), %rax
leaq -0x68(%rbp), %rdi
callq *0x38(%rax)
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %rcx
subq %r13, %rcx
sarq $0x2, %rcx
testq %rcx, %rcx
movss -0x30(%rbp), %xmm1
jle 0x327c
movq %rcx, %rax
shrq %rax
ucomiss (%r13,%rax,4), %xmm1
jbe 0x3274
leaq 0x4(%r13,%rax,4), %r13
notq %rax
addq %rcx, %rax
movq %rax, %rcx
testq %rax, %rax
jg 0x325e
movss (%r13), %xmm0
ucomiss %xmm1, %xmm0
jne 0x3318
jp 0x3318
movq %rbx, -0x30(%rbp)
movq %r13, %rax
subq -0x48(%rbp), %rax
shrq $0x2, %rax
movq -0x68(%rbp), %rcx
leaq (%rax,%rax,2), %rdx
movq (%rcx,%rdx,8), %rax
movq 0x8(%rcx,%rdx,8), %rcx
subq %rax, %rcx
cmpq $0x20, %rcx
movq %r14, -0x50(%rbp)
jne 0x335c
xorl %r14d, %r14d
jmp 0x33c2
leaq 0x10(%r14), %rbx
leaq 0x2e0b(%rip), %rsi      # 0x60e0
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2190
movq 0x10(%r14), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20f0
addq $0x10, %r14
leaq 0x2dbd(%rip), %rsi      # 0x60e0
movl $0x4, %edx
movq %r14, %rdi
callq 0x2190
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
jmp 0x340a
leaq 0x10(%r14), %r15
movl $0x8, %ebx
xorl %r14d, %r14d
leaq 0x2d79(%rip), %r12      # 0x60e8
movq -0x8(%rax,%rbx), %rsi
movq (%rax,%rbx), %rdx
movq %r15, %rdi
callq 0x2190
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2190
incq %r14
movq %r13, %rax
subq -0x48(%rbp), %rax
shrq $0x2, %rax
movq -0x68(%rbp), %rcx
leaq (%rax,%rax,2), %rdx
movq (%rcx,%rdx,8), %rax
movq 0x8(%rcx,%rdx,8), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
decq %rcx
addq $0x20, %rbx
cmpq %r14, %rcx
ja 0x336f
movq -0x50(%rbp), %rdi
addq $0x10, %rdi
shlq $0x5, %r14
movq (%rax,%r14), %rsi
movq 0x8(%rax,%r14), %rdx
callq 0x2190
movq -0x30(%rbp), %rbx
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x3a4c
movq %rbx, %rdi
callq 0x2150
leaq -0x68(%rbp), %rdi
callq 0x39e8
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x3431
callq 0x2150
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x345d
movq %rax, %r14
movq %rbx, %rdi
jmp 0x3466
jmp 0x3451
jmp 0x3451
movq %rax, %r14
leaq -0x68(%rbp), %rdi
callq 0x39e8
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x346b
callq 0x2150
movq %r14, %rdi
callq 0x22a0
nop