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

	// if it is a valid range search
	else
	{
		int i = 0;
		bool firstPass = true;
		float firstKey = ERROR;
		
		// 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, key1, 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(); 
		Node* next = path->top()->Get_Next();
		vector<float>::iterator index = lower_bound(keys.begin(), keys.end(), key1);

		// display all the keys in the search range, along with their corresponding values
		while(1)
		{
			// check if end of the current leaf node is reached
			if((index - keys.begin()) == keys.size())
			{
 				// go to the next leaf node
				keys = next->Get_Keys();
                		values = next->Get_Values();
                		next = next->Get_Next();
				index = keys.begin();
			}	
			
			// save the smallest key in the given search range
			if(firstPass)
			{	
				firstKey = keys[index - keys.begin()];						
			}


			// check if already iterated through the doubly linked list once
			if(!(firstPass || (keys[index - keys.begin()] != firstKey)))
			{
				// exit the loop
				break;
			}

			// check if key is within the search range
			if((key1 <= keys[index - keys.begin()]) && (keys[index - keys.begin()] <= key2)) 
			{
				if(!firstPass)
				{
					outputFile<<",";
				}

				// display the key and its corresponding values
				for(i = 0; i < values[index - keys.begin()].size() - 1; i++)
				{
					outputFile<<"("<<keys[index - keys.begin()]<<","<<values[index - keys.begin()][i]<<"),";
				}
				outputFile<<"("<<keys[index - keys.begin()]<<","<<values[index - keys.begin()][i]<<")";
			}

			// if key is not within the search range
			else
			{
				// check if atleast one key was in the search range
				if(!firstPass)
				{
					outputFile<<endl;
				}

				// if no keys belonged within the search range
				else
				{
					outputFile<<"Null"<<endl;
				}

				// exit the loop
				break;
			}

			firstPass = false;
			index++;
		}

		delete(path);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movss %xmm1, -0x54(%rbp)
movss %xmm0, -0x2c(%rbp)
movq %rdi, %r14
cmpq $0x0, 0x8(%rdi)
je 0x38c9
movl $0x50, %edi
callq 0x2170
movq %rax, %r15
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 -0x2c(%rbp), %xmm0
movq %r15, %rdx
callq 0x2d00
movq 0x30(%r15), %rax
cmpq 0x38(%r15), %rax
jne 0x34f8
movq 0x48(%r15), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rsi
leaq -0x48(%rbp), %rdi
callq 0x3eca
movq 0x30(%r15), %rax
cmpq 0x38(%r15), %rax
jne 0x351c
movq 0x48(%r15), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rsi
movq (%rsi), %rax
leaq -0x88(%rbp), %rdi
callq *0x38(%rax)
movq 0x30(%r15), %rax
cmpq 0x38(%r15), %rax
jne 0x3544
movq 0x48(%r15), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rbx
movq -0x40(%rbp), %rcx
subq %rbx, %rcx
sarq $0x2, %rcx
testq %rcx, %rcx
jle 0x358d
movq %rcx, %rax
movss -0x2c(%rbp), %xmm0
shrq %rax
ucomiss (%rbx,%rax,4), %xmm0
jbe 0x3585
leaq (%rbx,%rax,4), %rbx
addq $0x4, %rbx
notq %rax
addq %rcx, %rax
movq %rax, %rcx
testq %rax, %rax
jg 0x356e
movq %r15, -0x90(%rbp)
addq $0x10, %r14
movb $0x1, %r15b
movss 0x2b25(%rip), %xmm0     # 0x60c8
movss %xmm0, -0x30(%rbp)
cmpq -0x40(%rbp), %rbx
jne 0x367c
leaq -0x70(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x3eca
movq -0x48(%rbp), %rdi
movq -0x70(%rbp), %rax
movq %rax, -0x48(%rbp)
movups -0x68(%rbp), %xmm0
movups %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
testq %rdi, %rdi
je 0x35ec
callq 0x2150
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x35fa
callq 0x2150
movq -0x50(%rbp), %rbx
movq (%rbx), %rax
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq *0x38(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movups -0x88(%rbp), %xmm0
movq -0x78(%rbp), %rax
movups -0xa8(%rbp), %xmm1
movups %xmm1, -0x88(%rbp)
movq -0x98(%rbp), %rcx
movq %rcx, -0x78(%rbp)
movaps -0x70(%rbp), %xmm1
movaps %xmm0, -0x70(%rbp)
movq %rax, -0x60(%rbp)
movups %xmm1, -0xa8(%rbp)
movq $0x0, -0x98(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x39e8
movq %r12, %rdi
callq 0x39e8
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rbx
testb $0x1, %r15b
je 0x368b
movss (%rbx), %xmm0
movss %xmm0, -0x30(%rbp)
testb $0x1, %r15b
jne 0x36a1
movss (%rbx), %xmm0
ucomiss -0x30(%rbp), %xmm0
jne 0x36a1
jnp 0x3886
movss (%rbx), %xmm0
ucomiss -0x2c(%rbp), %xmm0
jb 0x3845
movss -0x54(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x3845
testb $0x1, %r15b
jne 0x36d7
movl $0x1, %edx
movq %r14, %rdi
leaq 0x2a16(%rip), %rsi      # 0x60e8
callq 0x2190
movq %rbx, %rax
subq -0x48(%rbp), %rax
shrq $0x2, %rax
movq -0x88(%rbp), %rcx
leaq (%rax,%rax,2), %rax
movq 0x8(%rcx,%rax,8), %rdx
subq (%rcx,%rax,8), %rdx
cmpq $0x20, %rdx
jne 0x3704
xorl %r12d, %r12d
jmp 0x37bc
movl $0x8, %r13d
xorl %r12d, %r12d
movl $0x1, %edx
movq %r14, %rdi
leaq 0x29c9(%rip), %rsi      # 0x60e5
callq 0x2190
xorps %xmm0, %xmm0
cvtss2sd (%rbx), %xmm0
movq %r14, %rdi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x29a6(%rip), %rsi      # 0x60e8
callq 0x2190
movq %rbx, %rax
subq -0x48(%rbp), %rax
shrq $0x2, %rax
movq -0x88(%rbp), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
movq -0x8(%rax,%r13), %rsi
movq (%rax,%r13), %rdx
movq %r15, %rdi
callq 0x2190
movl $0x2, %edx
movq %rax, %rdi
leaq 0x2966(%rip), %rsi      # 0x60e7
callq 0x2190
incq %r12
movq %rbx, %rax
subq -0x48(%rbp), %rax
shrq $0x2, %rax
movq -0x88(%rbp), %rcx
leaq (%rax,%rax,2), %rax
movq 0x8(%rcx,%rax,8), %rdx
subq (%rcx,%rax,8), %rdx
sarq $0x5, %rdx
decq %rdx
addq $0x20, %r13
cmpq %r12, %rdx
ja 0x370d
movl $0x1, %edx
movq %r14, %rdi
leaq 0x291a(%rip), %rsi      # 0x60e5
callq 0x2190
xorps %xmm0, %xmm0
cvtss2sd (%rbx), %xmm0
movq %r14, %rdi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x28f7(%rip), %rsi      # 0x60e8
callq 0x2190
movq %rbx, %rax
subq -0x48(%rbp), %rax
shrq $0x2, %rax
movq -0x88(%rbp), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
shlq $0x5, %r12
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
movq %r15, %rdi
callq 0x2190
movl $0x1, %edx
movq %rax, %rdi
leaq 0x28e4(%rip), %rsi      # 0x6118
callq 0x2190
addq $0x4, %rbx
xorl %r15d, %r15d
jmp 0x35a8
testb $0x1, %r15b
je 0x385f
leaq 0x288e(%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
movq -0x90(%rbp), %rbx
movq %rbx, %rdi
callq 0x3a4c
movq %rbx, %rdi
callq 0x2150
leaq -0x88(%rbp), %rdi
callq 0x39e8
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x38b7
callq 0x2150
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%r14), %rbx
leaq 0x280c(%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 $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20f0
jmp 0x3939
movq %rax, %rbx
jmp 0x3948
movq %rax, %rbx
movq %r15, %rdi
jmp 0x3951
jmp 0x3939
jmp 0x3939
jmp 0x3939
jmp 0x3939
jmp 0x3939
jmp 0x3939
jmp 0x3939
jmp 0x3939
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x39e8
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x3956
callq 0x2150
movq %rbx, %rdi
callq 0x22a0