// File: /workspace/github_cpp_makefile_star2_O2/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
movss %xmm0, -0x2c(%rbp)
cmpq $0x0, 0x8(%rdi)
je 0x2f28
movss %xmm0, -0x38(%rbp)
pushq $0x50
popq %rdi
callq 0x2150
movq %rax, %rbx
movq %rax, %rdi
callq 0x33aa
movq 0x8(%r14), %rsi
movq %r14, %rdi
movss -0x38(%rbp), %xmm0
movq %rbx, %rdx
callq 0x2a48
movq 0x30(%rbx), %rax
cmpq 0x38(%rbx), %rax
jne 0x2e53
movq 0x48(%rbx), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rsi
leaq -0x50(%rbp), %rdi
callq 0x3b06
movq 0x30(%rbx), %rax
movq %rbx, -0x38(%rbp)
cmpq 0x38(%rbx), %rax
jne 0x2e7f
movq -0x38(%rbp), %rax
movq 0x48(%rax), %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 -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x3788
movq %rax, %r15
movss -0x2c(%rbp), %xmm0
addq $0x10, %r14
ucomiss (%rax), %xmm0
jne 0x2f51
jp 0x2f51
movq -0x50(%rbp), %rax
xorl %r13d, %r13d
leaq 0x31e5(%rip), %r12      # 0x60ac
xorl %ebx, %ebx
movq %r15, %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movq -0x68(%rbp), %rax
imulq $0x18, %rcx, %rcx
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rax
subq %rsi, %rax
sarq $0x5, %rax
decq %rax
addq %r13, %rsi
cmpq %rbx, %rax
jbe 0x2f16
movq %r14, %rdi
callq 0x2120
movq %rax, %rdi
movq %r12, %rsi
callq 0x2140
incq %rbx
movq -0x50(%rbp), %rax
addq $0x20, %r13
jmp 0x2ec9
movq %r14, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20b0
jmp 0x2f68
addq $0x10, %r14
leaq 0x3171(%rip), %rsi      # 0x60a4
movq %r14, %rdi
callq 0x2140
movq %rax, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20b0
leaq 0x314c(%rip), %rsi      # 0x60a4
movq %r14, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20b0
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x3424
movq %rbx, %rdi
callq 0x2130
leaq -0x68(%rbp), %rdi
callq 0x33ca
leaq -0x50(%rbp), %rdi
callq 0x3760
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x2fbf
movq %rax, %r14
movq %rbx, %rdi
callq 0x2130
jmp 0x2fc8
jmp 0x2fb3
jmp 0x2fb3
movq %rax, %r14
leaq -0x68(%rbp), %rdi
callq 0x33ca
leaq -0x50(%rbp), %rdi
callq 0x3760
movq %r14, %rdi
callq 0x2270