// File: /workspace/github_cpp_makefile_star2_O3/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, -0x30(%rbp)
movss %xmm0, -0x2c(%rbp)
movq %rdi, %r14
cmpq $0x0, 0x8(%rdi)
je 0x3846
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 0x3cce
movq 0x8(%r14), %rsi
movq %r14, %rdi
movss -0x2c(%rbp), %xmm0
movq %r15, %rdx
callq 0x2d04
movq 0x30(%r15), %rax
cmpq 0x38(%r15), %rax
jne 0x34f2
movq 0x48(%r15), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rsi
leaq -0x50(%rbp), %rdi
callq 0x3ede
movq 0x30(%r15), %rax
cmpq 0x38(%r15), %rax
jne 0x3516
movq 0x48(%r15), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rsi
movq (%rsi), %rax
leaq -0x70(%rbp), %rdi
callq *0x38(%rax)
movq 0x30(%r15), %rax
cmpq 0x38(%r15), %rax
jne 0x353b
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, -0x58(%rbp)
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %rax
movq %rax, %rdx
subq %rbx, %rdx
sarq $0x2, %rdx
testq %rdx, %rdx
jle 0x3587
movq %rdx, %rcx
movss -0x2c(%rbp), %xmm0
shrq %rcx
ucomiss (%rbx,%rcx,4), %xmm0
jbe 0x357f
leaq (%rbx,%rcx,4), %rbx
addq $0x4, %rbx
notq %rcx
addq %rdx, %rcx
movq %rcx, %rdx
testq %rcx, %rcx
jg 0x3568
movq %r15, -0x98(%rbp)
addq $0x10, %r14
movb $0x1, %r15b
movss 0x2b2b(%rip), %xmm0     # 0x60c8
movss %xmm0, -0x34(%rbp)
cmpq %rax, %rbx
jne 0x367c
leaq -0x90(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x3ede
movq -0x50(%rbp), %rdi
movq -0x90(%rbp), %rax
movq %rax, -0x50(%rbp)
movups -0x88(%rbp), %xmm0
movups %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
testq %rdi, %rdi
je 0x3602
callq 0x2150
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x3602
callq 0x2150
movq -0x58(%rbp), %rbx
movq (%rbx), %rax
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq *0x38(%rax)
movups -0x70(%rbp), %xmm0
movq -0x60(%rbp), %rax
movaps -0xb0(%rbp), %xmm1
movups %xmm1, -0x70(%rbp)
movq -0xa0(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movups %xmm0, -0x90(%rbp)
movq %rax, -0x80(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xb0(%rbp)
movq $0x0, -0xa0(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x39de
movq %r12, %rdi
callq 0x39de
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rbx
movss (%rbx), %xmm1
testb $0x1, %r15b
je 0x36a5
ucomiss -0x2c(%rbp), %xmm1
jb 0x3897
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x3897
movss %xmm1, -0x34(%rbp)
jmp 0x36dd
ucomiss -0x34(%rbp), %xmm1
jne 0x36b1
jnp 0x38d2
ucomiss -0x2c(%rbp), %xmm1
jb 0x38ab
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x38ab
movl $0x1, %edx
movq %r14, %rdi
leaq 0x2a10(%rip), %rsi      # 0x60e8
callq 0x2190
movq -0x50(%rbp), %rax
movq %rbx, %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movq -0x70(%rbp), %rax
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
subq (%rax,%rcx,8), %rdx
cmpq $0x20, %rdx
jne 0x370a
xorl %r12d, %r12d
jmp 0x37bc
movl $0x8, %r13d
xorl %r12d, %r12d
movl $0x1, %edx
movq %r14, %rdi
leaq 0x29c3(%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 0x29a0(%rip), %rsi      # 0x60e8
callq 0x2190
movq %rbx, %rax
subq -0x50(%rbp), %rax
shrq $0x2, %rax
movq -0x70(%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 0x2963(%rip), %rsi      # 0x60e7
callq 0x2190
incq %r12
movq %rbx, %rax
subq -0x50(%rbp), %rax
shrq $0x2, %rax
movq -0x70(%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 0x3713
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 -0x50(%rbp), %rax
shrq $0x2, %rax
movq -0x70(%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 0x28e7(%rip), %rsi      # 0x6118
callq 0x2190
addq $0x4, %rbx
movq -0x48(%rbp), %rax
xorl %r15d, %r15d
jmp 0x35a2
leaq 0x10(%r14), %rbx
leaq 0x288f(%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
leaq 0x2842(%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 -0x98(%rbp), %rbx
movq %rbx, %rdi
callq 0x3a4c
movq %rbx, %rdi
callq 0x2150
leaq -0x70(%rbp), %rdi
callq 0x39de
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x3900
callq 0x2150
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3931
movq %rax, %rbx
jmp 0x393d
movq %rax, %rbx
movq %r15, %rdi
jmp 0x3946
jmp 0x3931
jmp 0x3931
jmp 0x3931
jmp 0x3931
jmp 0x3931
jmp 0x3931
jmp 0x3931
jmp 0x3931
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x39de
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x394b
callq 0x2150
movq %rbx, %rdi
callq 0x22a0
nop