// File: /workspace/github_cpp_makefile_star2_O2/BU-DiSC[P]BF-Shared-Hashing/db.cpp
// Function: db::loadBFAndIndex()
fsec db::loadBFAndIndex(){
	fp_vec = vector<uint64_t> (num_levels, 0);
	n_vec = vector<uint64_t> (num_levels, 0);
	bf_prime = (char****) malloc  ( num_levels * sizeof(char***));
	blk_fp_prime = (char****) malloc  ( num_levels * sizeof(char***));
	blk_size_prime = (int**) malloc (num_levels*sizeof(int*));
	if(fastlocal_bf){
		FastLocalBF bf = FastLocalBF(bpk/num_filter_units);
		filter_size = bf.CalculateSpace(B*P);
        	num_probes = bf.num_probes_;
	}else{
		LegacyBF bf = LegacyBF(bpk/num_filter_units);
		uint32_t dont_care;
		filter_size = bf.CalculateSpace(B*P, &dont_care, &num_lines);
        	num_probes = bf.num_probes_;
	}
	int tmp_filter_size = filter_size;
	auto l_start = high_resolution_clock::now();
	auto l_end = high_resolution_clock::now();
	fsec load_duration = std::chrono::microseconds::zero();
	for(int i = 0; i < num_levels; i++){
		bf_prime[i] = (char***) malloc (num_sstPerLevel[i]*sizeof(char**));
		blk_fp_prime[i] = (char***) malloc (num_sstPerLevel[i]*sizeof(char**));
		blk_size_prime[i] = (int*) malloc (num_sstPerLevel[i]*sizeof(int));

		for(int j = 0; j < num_sstPerLevel[i]; j++){
			string sst_index_filename = index_dir + "level_" + to_string(i) + "-sst_" + to_string(j) + ".txt";
			l_start = high_resolution_clock::now();
			int index_size = read_index_size(sst_index_filename);	
			l_end = high_resolution_clock::now();
			load_duration += duration_cast<microseconds>(l_end - l_start);

			char** index = (char**) malloc((index_size+1)*sizeof(char*));
			for(int k = 0; k <= index_size; k++){
				index[k] = (char*) malloc ((K+1)*sizeof(char));
			}
			l_start = high_resolution_clock::now();
			read_index(sst_index_filename, index_size, index);
			l_end = high_resolution_clock::now();
			load_duration += duration_cast<microseconds>(l_end - l_start);

			blk_fp_prime[i][j] = index;
			blk_size_prime[i][j] = index_size;

			if(i == num_levels - 1 && j == num_sstPerLevel[i] - 1){
				if(fastlocal_bf){
					FastLocalBF bf = FastLocalBF(bpk/num_filter_units);
					last_filter_size = bf.CalculateSpace(last_sst_keys);
					last_num_lines = bf.num_lines_;
				}else{
					LegacyBF bf = LegacyBF(bpk/num_filter_units);
					uint32_t dont_care;
					last_filter_size = bf.CalculateSpace(last_sst_keys, &dont_care, &last_num_lines);
					last_num_lines = bf.num_lines_;

				}
				tmp_filter_size = last_filter_size;
			} 
			
			char** sst_bf = (char**) malloc (num_filter_units*sizeof(char*));

			for(int k = 0; k < num_filter_units; k++){
				string sst_bf_filename = bf_dir + "level_" + to_string(i) + "-sst_" + to_string(j) + "_" + to_string(k) + ".txt";
				char* blo_bf = (char*) malloc (tmp_filter_size*sizeof(char));
				l_start = high_resolution_clock::now();
				read_bf(sst_bf_filename, blo_bf, tmp_filter_size);
				l_end = high_resolution_clock::now();
				load_duration += duration_cast<microseconds>(l_end - l_start);
				sst_bf[k] = blo_bf;
			}
			bf_prime[i][j] = sst_bf;
		}
	}
	return load_duration;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rdi, %rbx
movslq 0xdc(%rdi), %rsi
leaq 0xa8(%rsp), %r14
andq $0x0, (%r14)
leaq 0xe8(%rsp), %r15
leaq 0x30(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rdx
callq 0xb326
leaq 0x1b0(%rbx), %rdi
movq %r15, %rsi
callq 0xd66c
movq %r15, %rdi
callq 0x752a
movslq 0xdc(%rbx), %rsi
andq $0x0, (%r14)
leaq 0xe8(%rsp), %r14
leaq 0xa8(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %r14, %rdi
callq 0xb326
leaq 0x1c8(%rbx), %rdi
movq %r14, %rsi
callq 0xd66c
movq %r14, %rdi
callq 0x752a
movslq 0xdc(%rbx), %r14
shlq $0x3, %r14
movq %r14, %rdi
callq 0x6550
movq %rax, 0x158(%rbx)
movq %r14, %rdi
callq 0x6550
movq %rax, 0x160(%rbx)
movq %r14, %rdi
callq 0x6550
movq %rax, 0x168(%rbx)
cmpb $0x1, 0x10c(%rbx)
pushq $0x1
popq %rsi
pushq $0x1e
popq %rdi
movq %rbx, (%rsp)
jne 0xa5a4
movl 0x104(%rbx), %eax
cltd
idivl 0x110(%rbx)
leaq 0xe8(%rsp), %r14
movq %r14, %rdi
movl %eax, %esi
callq 0xb534
movq (%rsp), %rax
movl 0xc4(%rax), %esi
movq (%rsp), %rax
imull 0xc8(%rax), %esi
movq %r14, %rdi
callq 0xb586
movq (%rsp), %rcx
movl %eax, 0x120(%rcx)
movl 0x4(%r14), %eax
movq (%rsp), %rbx
movl %eax, 0x130(%rbx)
leaq 0x108(%rsp), %rdi
callq 0xc22a
jmp 0xa645
movl 0x104(%rbx), %eax
cltd
idivl 0x110(%rbx)
leaq 0xf8(%rsp), %r14
xorps %xmm0, %xmm0
andq $0x0, 0x10(%r14)
movups %xmm0, (%r14)
cvtsi2sd %eax, %xmm0
mulsd 0x17b1f(%rip), %xmm0    # 0x220f0
cvttsd2si %xmm0, %ecx
movl %eax, -0x10(%r14)
cmpl $0x2, %ecx
cmovll %esi, %ecx
cmpl $0x1e, %ecx
cmovgel %edi, %ecx
movl %ecx, -0xc(%r14)
movq (%rsp), %rax
movl 0xc4(%rax), %esi
movq (%rsp), %rax
imull 0xc8(%rax), %esi
movq (%rsp), %rax
leaq 0x128(%rax), %rcx
leaq 0xe8(%rsp), %r15
leaq 0xa8(%rsp), %rdx
movq %r15, %rdi
callq 0x7c18
movq (%rsp), %rcx
movl %eax, 0x120(%rcx)
movl 0x4(%r15), %eax
movq (%rsp), %rcx
movl %eax, 0x130(%rcx)
movq %r14, %rdi
movq (%rsp), %rbx
callq 0xc250
movl 0x120(%rbx), %eax
movl %eax, 0xc(%rsp)
callq 0x6070
callq 0x6070
leaq 0x40(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0x12c(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x20(%rbx), %rax
movq %rax, 0x60(%rsp)
xorpd %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
xorl %r13d, %r13d
leaq 0x158(%rsp), %r14
movq (%rsp), %rbx
movslq 0xdc(%rbx), %rax
cmpq %rax, %r13
jge 0xaca8
movq 0xe8(%rbx), %rax
movslq (%rax,%r13,4), %rdi
shlq $0x3, %rdi
callq 0x6550
movq 0x158(%rbx), %rcx
movq %rax, (%rcx,%r13,8)
movq 0xe8(%rbx), %rax
movslq (%rax,%r13,4), %rdi
shlq $0x3, %rdi
callq 0x6550
movq 0x160(%rbx), %rcx
movq %rax, (%rcx,%r13,8)
movq 0xe8(%rbx), %rax
movslq (%rax,%r13,4), %rdi
shlq $0x2, %rdi
callq 0x6550
movq 0x168(%rbx), %rcx
movq %rax, (%rcx,%r13,8)
xorl %r15d, %r15d
movq %r13, 0x28(%rsp)
movq 0xe8(%rbx), %rax
movslq (%rax,%r13,4), %rax
movq %r15, 0x10(%rsp)
cmpq %rax, %r15
jge 0xaca0
movq %r14, %rdi
movq 0x58(%rsp), %rsi
leaq 0x17c5a(%rip), %rdx     # 0x22387
callq 0xb278
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movl %r13d, %esi
callq 0xb620
leaq 0x88(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xb5b9
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
leaq 0x17c27(%rip), %rdx     # 0x2238e
callq 0xb514
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0xb620
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0xb5b9
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x1853f(%rip), %rdx     # 0x22ced
callq 0xb514
movq %rbx, %rdi
callq 0x61f0
leaq 0xc8(%rsp), %rdi
callq 0x61f0
leaq 0x30(%rsp), %rdi
callq 0x61f0
leaq 0x88(%rsp), %rdi
callq 0x61f0
leaq 0x68(%rsp), %rdi
callq 0x61f0
movq %r14, %rdi
callq 0x61f0
callq 0x6070
movq %rax, %r14
leaq 0x238(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6570
movq %rbx, %r15
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xba7a
movl %eax, %ebp
movq %r15, %rdi
callq 0x61f0
callq 0x6070
subq %r14, %rax
cqto
movl $0x3e8, %ecx            # imm = 0x3E8
idivq %rcx
cvtsi2ss %rax, %xmm0
divss 0x177bd(%rip), %xmm0    # 0x22004
movss %xmm0, 0x18(%rsp)
movslq %ebp, %r12
leaq 0x8(,%r12,8), %rdi
callq 0x6550
movq %rax, %r14
movslq 0xd0(%rbx), %r15
incq %r15
xorl %r13d, %r13d
cmpq %r12, %r13
jg 0xa883
movq %r15, %rdi
callq 0x6550
movq %rax, (%r14,%r13,8)
incq %r13
jmp 0xa86d
callq 0x6070
movq %rax, %r15
leaq 0x218(%rsp), %r12
movq %r12, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x6570
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0xbb44
movq %r12, %rdi
callq 0x61f0
callq 0x6070
subq %r15, %rax
cqto
movl $0x3e8, %ecx            # imm = 0x3E8
idivq %rcx
cvtsi2ss %rax, %xmm1
divss 0x17726(%rip), %xmm1    # 0x22004
movq 0x160(%rbx), %rax
movq 0x28(%rsp), %r13
movq (%rax,%r13,8), %rax
movq 0x10(%rsp), %rcx
movq %r14, (%rax,%rcx,8)
movq 0x168(%rbx), %rax
movq (%rax,%r13,8), %rax
movl %ebp, (%rax,%rcx,4)
movl 0xdc(%rbx), %eax
decl %eax
cmpq %rax, %r13
movq %rbx, %r14
jne 0xaa42
movq 0xe8(%r14), %rax
movl (%rax,%r13,4), %eax
decl %eax
cmpq %rax, %rcx
jne 0xaa42
movss %xmm1, 0x24(%rsp)
cmpb $0x1, 0x10c(%r14)
jne 0xa996
movl 0x104(%r14), %eax
cltd
idivl 0x110(%r14)
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
movl %eax, %esi
callq 0xb534
movl 0x100(%r14), %esi
movq %rbx, %rdi
callq 0xb586
movl %eax, 0x124(%r14)
movl 0xf0(%rsp), %eax
movl %eax, 0x12c(%r14)
leaq 0x108(%rsp), %rdi
callq 0xc22a
jmp 0xaa31
movl 0x104(%r14), %eax
cltd
idivl 0x110(%r14)
leaq 0xf8(%rsp), %r14
andq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
cvtsi2sd %eax, %xmm0
movl %eax, 0xe8(%rsp)
mulsd 0x17724(%rip), %xmm0    # 0x220f0
cvttsd2si %xmm0, %eax
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovll %ecx, %eax
cmpl $0x1e, %eax
pushq $0x1e
popq %rcx
cmovgel %ecx, %eax
movl %eax, 0xec(%rsp)
movq (%rsp), %rax
movl 0x100(%rax), %esi
leaq 0xe8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq 0x50(%rsp), %rcx
callq 0x7c18
movq (%rsp), %rcx
movl %eax, 0x124(%rcx)
movl 0xf0(%rsp), %eax
movq (%rsp), %rcx
movl %eax, 0x12c(%rcx)
movq %r14, %rdi
movq (%rsp), %r14
callq 0xc250
movl 0x124(%r14), %eax
movl %eax, 0xc(%rsp)
movss 0x24(%rsp), %xmm1
movss 0x8(%rsp), %xmm0
addss 0x18(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x8(%rsp)
movslq 0x110(%r14), %r15
movq %r15, %rdi
shlq $0x3, %rdi
callq 0x6550
movq %rax, %r14
movslq 0xc(%rsp), %rax
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
movslq %r15d, %rax
cmpq %rax, %rbp
jge 0xac6b
leaq 0x178(%rsp), %rdi
movq 0x60(%rsp), %rsi
leaq 0x178ed(%rip), %rdx     # 0x22387
callq 0xb278
leaq 0x158(%rsp), %r15
leaq 0x1d8(%rsp), %rbx
movq %rbx, %rdi
movl %r13d, %esi
callq 0xb620
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
leaq 0x178(%rsp), %rsi
movq %rbx, %rdx
callq 0xb5b9
leaq 0x68(%rsp), %rdi
movq %r13, %rsi
leaq 0x178aa(%rip), %rdx     # 0x2238e
callq 0xb514
leaq 0x1b8(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xb620
movq %r15, %rdi
leaq 0x68(%rsp), %rsi
movq %rbx, %rdx
callq 0xb5b9
leaq 0x88(%rsp), %rdi
movq %r15, %rsi
leaq 0x1786c(%rip), %rdx     # 0x2238c
callq 0xb514
leaq 0x198(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %esi
callq 0xb620
leaq 0x30(%rsp), %r13
movq %r13, %rdi
leaq 0x88(%rsp), %rsi
movq %rbx, %rdx
callq 0xb5b9
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x18189(%rip), %rdx     # 0x22ced
callq 0xb514
movq %r13, %rdi
callq 0x61f0
leaq 0x198(%rsp), %rdi
callq 0x61f0
leaq 0x88(%rsp), %rdi
callq 0x61f0
movq %r15, %rdi
callq 0x61f0
leaq 0x1b8(%rsp), %rdi
callq 0x61f0
leaq 0x68(%rsp), %rdi
callq 0x61f0
leaq 0xc8(%rsp), %rdi
callq 0x61f0
leaq 0x1d8(%rsp), %rdi
callq 0x61f0
leaq 0x178(%rsp), %rdi
callq 0x61f0
movq 0x18(%rsp), %rdi
callq 0x6550
movq %rax, %r13
callq 0x6070
movq %rax, %r15
leaq 0x1f8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x6570
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl 0xc(%rsp), %ecx
callq 0xbd20
movq %r12, %rdi
callq 0x61f0
callq 0x6070
subq %r15, %rax
cqto
movl $0x3e8, %ecx            # imm = 0x3E8
idivq %rcx
cvtsi2ss %rax, %xmm0
divss 0x173ce(%rip), %xmm0    # 0x22004
movss 0x8(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
movq %r13, (%r14,%rbp,8)
leaq 0xe8(%rsp), %rdi
callq 0x61f0
incq %rbp
movl 0x110(%rbx), %r15d
movq 0x28(%rsp), %r13
jmp 0xaa7a
movq (%rsp), %rbx
movq 0x158(%rbx), %rax
movq (%rax,%r13,8), %rax
movq 0x10(%rsp), %r15
movq %r14, (%rax,%r15,8)
leaq 0xa8(%rsp), %rdi
callq 0x61f0
incq %r15
leaq 0x158(%rsp), %r14
jmp 0xa705
incq %r13
jmp 0xa68c
movss 0x8(%rsp), %xmm0
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xae2a
movq %rax, %rbx
leaq 0x218(%rsp), %rdi
jmp 0xae10
movq %rax, %rbx
jmp 0xad01
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x61f0
jmp 0xacf4
movq %rax, %rbx
jmp 0xad46
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x61f0
leaq 0x30(%rsp), %rdi
callq 0x61f0
jmp 0xad2f
movq %rax, %rbx
jmp 0xad3c
movq %rax, %rbx
leaq 0x238(%rsp), %rdi
jmp 0xae10
jmp 0xae2a
jmp 0xae2a
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x61f0
leaq 0x68(%rsp), %rdi
callq 0x61f0
leaq 0x158(%rsp), %rdi
jmp 0xae1d
movq %rax, %rbx
jmp 0xadee
movq %rax, %rbx
jmp 0xae08
movq %rax, %rbx
jmp 0xadd7
movq %rax, %rbx
jmp 0xadca
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x61f0
jmp 0xad82
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0xae10
movq %rax, %rbx
jmp 0xade4
movq %rax, %rbx
jmp 0xada6
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x61f0
leaq 0x198(%rsp), %rdi
callq 0x61f0
jmp 0xadbd
movq %rax, %rbx
jmp 0xadfb
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x61f0
leaq 0x158(%rsp), %rdi
callq 0x61f0
leaq 0x1b8(%rsp), %rdi
callq 0x61f0
leaq 0x68(%rsp), %rdi
callq 0x61f0
leaq 0xc8(%rsp), %rdi
callq 0x61f0
leaq 0x1d8(%rsp), %rdi
callq 0x61f0
leaq 0x178(%rsp), %rdi
callq 0x61f0
leaq 0xa8(%rsp), %rdi
callq 0x61f0
movq %rbx, %rdi
callq 0x66b0
movq %rax, %rbx
jmp 0xae15
nop