// File: /workspace/github_cpp_makefile_star2_O2/BU-DiSC[P]BF-Shared-Hashing/db.cpp
// Function: db::GetLevel(int, BFHash&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, bool*)
inline string db::GetLevel( int i, BFHash & bfHash, string & key, bool * result )
{
	// Binary search for fense pointer
	//auto bs_start = high_resolution_clock::now();
	int bf_no = binary_search(key, fence_pointers[i]);
	//auto bs_end = high_resolution_clock::now();
	//bs_duration += duration_cast<microseconds>(bs_end - bs_start);	

 		//auto other_start = high_resolution_clock::now();

	// no matching sst
	if(bf_no < 0){
		*result = false;
 		//auto other_end = high_resolution_clock::now();
		//other_duration += duration_cast<microseconds>(other_end - other_start);
		return "";
	}
	//auto hash_start = high_resolution_clock::now();
	vector<uint64_t>* hash_digests = bfHash.getLevelwiseHashDigest(i);
	//auto hash_end = high_resolution_clock::now();
	//hash_duration += duration_cast<microseconds>(hash_end - hash_start);	


	bool bf_result = QueryFilter( i, bf_no, hash_digests, bf_prime[i][bf_no]);
		
	//cout << "QueryFilter result : " << i << " " << bf_no << " " << bf_result << endl;

	if( bf_result==false ){
		total_n++;
		//n_vec[i]++;
		*result = false;
 		//auto other_end = high_resolution_clock::now();
		//other_duration += duration_cast<microseconds>(other_end - other_start);
		return "";
	}

	int index_pos = GetFromIndex( i, bf_no, key );

	bool data_result = false;
	string data = GetFromData( i, bf_no, index_pos, key, &data_result );

	// false positive
	if (data_result == false){
		total_fp++;
		//fp_vec[i]++;
		total_n++;
		//n_vec[i]++;
	}else{

		total_p++;
	}
	

	*result = data_result;
 		//auto other_end = high_resolution_clock::now();
		//other_duration += duration_cast<microseconds>(other_end - other_start);
	return data;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x18(%rsp)
movq %r8, %r12
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, 0x20(%rsp)
leaq 0x68(%rsp), %r13
movq %r13, %rdi
movq %r8, %rsi
callq 0x6570
movslq %ebp, %r14
imulq $0x18, %r14, %rdx
addq 0x140(%r15), %rdx
movq %r13, %rsi
callq 0x9d28
movl %eax, %r13d
leaq 0x68(%rsp), %rdi
callq 0x61f0
testl %r13d, %r13d
js 0xb902
movq %rbx, %rdi
movl %r14d, %esi
callq 0xecc4
movq 0x158(%r15), %rcx
movq (%rcx,%r14,8), %rcx
movl %r13d, %edx
movq (%rcx,%rdx,8), %r8
movq %r15, %rdi
movl %r14d, %esi
movl %r13d, %edx
movq %rax, %rcx
callq 0xc724
testb %al, %al
je 0xb8fb
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6570
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %edx
movq %rbx, %rcx
callq 0xc800
movl %eax, %ebx
leaq 0x48(%rsp), %rdi
callq 0x61f0
leaq 0x17(%rsp), %r14
movb $0x0, (%r14)
leaq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x6570
movq %r14, (%rsp)
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %r13d, %ecx
movl %ebx, %r8d
leaq 0x28(%rsp), %r9
callq 0xc86a
leaq 0x28(%rsp), %rdi
callq 0x61f0
movb 0x17(%rsp), %al
movl $0x1a0, %ecx            # imm = 0x1A0
testb %al, %al
jne 0xb8ee
incq 0x1a8(%r15)
movl $0x198, %ecx            # imm = 0x198
incq (%r15,%rcx)
movq 0x18(%rsp), %rcx
movb %al, (%rcx)
jmp 0xb923
incq 0x198(%r15)
movq 0x18(%rsp), %rax
movb $0x0, (%rax)
leaq 0x16ac8(%rip), %rsi     # 0x223d9
leaq 0x17(%rsp), %rdx
movq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x61b0
movq %r14, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0xb954
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0xb954
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x61f0
movq %rbx, %rdi
callq 0x66b0
nop