// File: /workspace/github_cpp_makefile_star2_O1/BU-DiSC[P]BF-Shared-Hashing/lsm-emulation.cpp
// Function: main
int main(int argc, char * argv[])
{
	auto t_start = high_resolution_clock::now();
	options op;
	// parse the command line arguments
	if ( op.parse(argc, argv) ) {
	  exit(1);
	}
	string filename = op.out_path;
	cout << filename << endl;

	int aloc = 0;

	// -- load workload --------------------------------------------------------------------
	string file_in_set  = op.insert_path;
	string file_out_set = op.query_path;

	vector<string> table_in;
	vector<string> table_out;

	int S_size = 0;
	int SC_size = 0;
	auto l_start = high_resolution_clock::now();
	loadfile( file_out_set, &table_out, &SC_size );
	auto l_end = high_resolution_clock::now();
	load_duration += duration_cast<microseconds>(l_end - l_start);

	op.key_size = table_out.at(0).size();
	// -------------------------------------------------------------------------------------
	
	vector<vector<vector<string> > > reallocated_keys;

        db database( op );

	// -- Program && Bloom Filters -------------------------------------------------------------------
	// log file
	bool bf_only = false;
	bool rebuild = false;
	if ( op.destroy_db==false ){
		int read_result  = database.ReadSettings();
		cout << "read db check " << read_result << endl;
		bf_only = ( read_result==1 )? true : false;
		rebuild = ( read_result==-1 )? true : false;
	}
	if ( op.destroy_db || rebuild || bf_only ) {
		loadfile( file_in_set, &table_in, &S_size );
		database.split_keys( table_in, reallocated_keys );
		database.Build( reallocated_keys, bf_only );
	}
	else {
		database.SetTreeParam();
		load_duration += database.loadBFAndIndex();
	}
	cout << "DB has been loaded" << endl; 
	// ------------------------------------------------------------------------------


	// -- Query ---------------------------------------------------------------------
	unsigned long total_query = table_out.size();

	int temp = 0;

	string input_str;
	srand(time(0));

	bool result;

	
	//for ( long i=0 ; i<100 ; i++ ) {
	for(int k = 0; k < database.tries; k++){
		cout << "Run " << k << " : " << endl;
		for ( long i=0 ; i<table_out.size() ; i++ ) {
			input_str = table_out[i];
			//cout << input_str << endl;
			result = false;
			database.Get( input_str, &result );

			input_str.clear();
			if ( i%(table_out.size()/10) == 0 ) cout << i/(table_out.size()/10)*10 << "%" << std::flush;
			if ( i%(table_out.size()/100) == 0 && i != 0 ) cout << "=" << std::flush;
		}
		cout << "100%" << endl;
	}
	
	// ------------------------------------------------------------------------------
		// log file
	auto t_end = high_resolution_clock::now();
	fsec t_duration = duration_cast<std::chrono::microseconds>(t_end-t_start);
	database.PrintStat(t_duration.count(), load_duration.count());
	return temp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5a8, %rsp            # imm = 0x5A8
movq %rsi, %rbx
movl %edi, %ebp
callq 0x5080
movq %rax, 0xd0(%rsp)
leaq 0x1a0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x1c8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x1e8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x208(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x250(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x190(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x11e08
testl %eax, %eax
jne 0x638f
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x1b8(%rsp), %rsi
movq 0x1c0(%rsp), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0x6bf6
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x33404(%rip), %rdi     # 0x38fd0
callq 0x5470
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x52a0
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x1d8(%rsp), %rsi
movq 0x1e0(%rsp), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x6bf6
leaq 0xf0(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x1f8(%rsp), %rsi
movq 0x200(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0x6bf6
xorps %xmm0, %xmm0
movaps %xmm0, 0xb0(%rsp)
xorl %eax, %eax
movq %rax, 0xc0(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl %eax, 0x2c(%rsp)
movl %eax, 0x28(%rsp)
callq 0x5080
movq %rax, %rbx
leaq 0x180(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x170(%rsp), %rdi
callq 0x6bf6
leaq 0x170(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x6508
movq 0x170(%rsp), %rdi
cmpq %r14, %rdi
je 0x5cd4
callq 0x53d0
callq 0x5080
subq %rbx, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
divss 0x232fd(%rip), %xmm0    # 0x29004
addss 0x33749(%rip), %xmm0    # 0x39458
movss %xmm0, 0x33741(%rip)    # 0x39458
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x6399
movl 0x8(%rax), %eax
leaq 0x190(%rsp), %rsi
movl %eax, 0x98(%rsi)
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movq $0x0, 0xa0(%rsp)
leaq 0x290(%rsp), %rdi
callq 0x6722
leaq 0x370(%rsp), %rdi
leaq 0x290(%rsp), %rsi
callq 0x750e
leaq 0x350(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5d87
callq 0x53d0
leaq 0x308(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5d9d
callq 0x53d0
leaq 0x2e8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5db3
callq 0x53d0
leaq 0x2c8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5dc9
callq 0x53d0
leaq 0x2a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ddf
callq 0x53d0
cmpb $0x0, 0x1b0(%rsp)
je 0x5def
xorl %ebp, %ebp
xorl %eax, %eax
jmp 0x5e5b
leaq 0x370(%rsp), %rdi
callq 0x7d9c
movl %eax, %ebx
movq 0x331cb(%rip), %rdi     # 0x38fd0
leaq 0x231fc(%rip), %rsi     # 0x29008
movl $0xe, %edx
callq 0x5470
movq 0x331b3(%rip), %rdi     # 0x38fd0
movl %ebx, %esi
callq 0x5680
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x52a0
cmpl $0x1, %ebx
sete %bpl
cmpl $-0x1, %ebx
sete %al
testb %bpl, %bpl
jne 0x5e9d
testb %al, %al
jne 0x5e9d
cmpb $0x0, 0x1b0(%rsp)
jne 0x5e9d
leaq 0x370(%rsp), %rdi
callq 0xb4b4
leaq 0x370(%rsp), %rdi
callq 0xb642
addss 0x335c8(%rip), %xmm0    # 0x39458
movss %xmm0, 0x335c0(%rip)    # 0x39458
jmp 0x5f69
leaq 0x160(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rdx
leaq 0x150(%rsp), %rdi
callq 0x6bf6
leaq 0x150(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x2c(%rsp), %rdx
callq 0x6508
movq 0x150(%rsp), %rdi
cmpq %r14, %rdi
je 0x5eef
callq 0x53d0
leaq 0x118(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x68fe
leaq 0x370(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xae22
leaq 0x118(%rsp), %rdi
callq 0x6982
leaq 0x100(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x69c6
movzbl %bpl, %edx
leaq 0x370(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x8348
leaq 0x100(%rsp), %rdi
callq 0x6a58
movq 0x33060(%rip), %rbx     # 0x38fd0
leaq 0x230a0(%rip), %rsi     # 0x29017
movl $0x12, %edx
movq %rbx, %rdi
callq 0x5470
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x53f0
movsbl %al, %esi
movq 0x3302e(%rip), %r14     # 0x38fd0
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x52a0
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x53b0
movl %eax, %edi
callq 0x53e0
cmpl $0x0, 0x5a0(%rsp)
jle 0x621e
leaq 0x140(%rsp), %rbp
leaq 0x130(%rsp), %r12
movl $0x4, %edx
movq %r14, %rdi
leaq 0x23026(%rip), %rsi     # 0x2902a
callq 0x5470
movq %r14, %rdi
movl %r15d, %esi
callq 0x5680
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x23009(%rip), %rsi     # 0x2902f
callq 0x5470
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x52a0
movq %r15, 0xd8(%rsp)
movq 0x10(%rsp), %rsi
cmpq %rsi, 0x18(%rsp)
je 0x61ca
xorl %r15d, %r15d
xorl %ebx, %ebx
addq %r15, %rsi
leaq 0x50(%rsp), %rdi
callq 0x5230
movb $0x0, 0xf(%rsp)
movq %rbp, 0x130(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x6bf6
leaq 0x270(%rsp), %rdi
leaq 0x370(%rsp), %rsi
movq %r12, %rdx
leaq 0xf(%rsp), %rcx
callq 0xab20
movq 0x270(%rsp), %rdi
leaq 0x280(%rsp), %rax
cmpq %rax, %rdi
je 0x60d5
callq 0x53d0
movq 0x130(%rsp), %rdi
cmpq %rbp, %rdi
je 0x60e7
callq 0x53d0
movq $0x0, 0x58(%rsp)
movq 0x50(%rsp), %rax
movb $0x0, (%rax)
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x5, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
movq %rdx, %rcx
shrq $0x3, %rcx
movq %rbx, %rax
xorl %edx, %edx
divq %rcx
testq %rdx, %rdx
jne 0x6155
addq %rax, %rax
leaq (%rax,%rax,4), %rsi
movq %r14, %rdi
callq 0x5290
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x22ef0(%rip), %rsi     # 0x29038
callq 0x5470
movq %r13, %rdi
callq 0x52a0
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x5, %rax
shrq $0x2, %rax
movabsq $0x28f5c28f5c28f5c3, %rcx # imm = 0x28F5C28F5C28F5C3
mulq %rcx
movq %rdx, %rcx
shrq $0x2, %rcx
movq %rbx, %rax
xorl %edx, %edx
divq %rcx
testq %rbx, %rbx
je 0x61a9
testq %rdx, %rdx
jne 0x61a9
movl $0x1, %edx
movq %r14, %rdi
leaq 0x22e97(%rip), %rsi     # 0x29033
callq 0x5470
movq %r14, %rdi
callq 0x52a0
incq %rbx
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %rax, %rbx
jb 0x606f
movl $0x4, %edx
movq %r14, %rdi
leaq 0x22e5c(%rip), %rsi     # 0x29035
callq 0x5470
movq 0xd8(%rsp), %r15
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x52a0
incl %r15d
cmpl 0x5a0(%rsp), %r15d
jl 0x5ff5
callq 0x5080
subq 0xd0(%rsp), %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
divss 0x22dae(%rip), %xmm0    # 0x29004
cvtss2sd %xmm0, %xmm0
cvtss2sd 0x331f6(%rip), %xmm1    # 0x39458
leaq 0x370(%rsp), %rdi
callq 0xcb6e
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x6283
callq 0x53d0
leaq 0x370(%rsp), %rdi
callq 0x6a92
leaq 0x90(%rsp), %rdi
callq 0x6a58
leaq 0x10(%rsp), %rdi
callq 0x6982
leaq 0xb0(%rsp), %rdi
callq 0x6982
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x62ce
callq 0x53d0
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x62e5
callq 0x53d0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x62f9
callq 0x53d0
movq 0x240(%rsp), %rdi
leaq 0x250(%rsp), %rax
cmpq %rax, %rdi
je 0x6313
callq 0x53d0
movq 0x1f8(%rsp), %rdi
leaq 0x208(%rsp), %rax
cmpq %rax, %rdi
je 0x632d
callq 0x53d0
movq 0x1d8(%rsp), %rdi
leaq 0x1e8(%rsp), %rax
cmpq %rax, %rdi
je 0x6347
callq 0x53d0
movq 0x1b8(%rsp), %rdi
leaq 0x1c8(%rsp), %rax
cmpq %rax, %rdi
je 0x6361
callq 0x53d0
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x637b
callq 0x53d0
xorl %eax, %eax
addq $0x5a8, %rsp            # imm = 0x5A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x54a0
leaq 0x22cd3(%rip), %rdi     # 0x29073
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x55d0
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x6a58
jmp 0x647d
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x6982
jmp 0x647d
movq %rax, %rbx
movq 0x150(%rsp), %rdi
cmpq %r14, %rdi
jne 0x6478
jmp 0x647d
jmp 0x6448
jmp 0x6466
movq %rax, %rbx
leaq 0x290(%rsp), %rdi
callq 0x6898
jmp 0x648a
movq %rax, %rbx
jmp 0x648a
jmp 0x6425
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r14, %rdi
je 0x6497
callq 0x53d0
jmp 0x6497
movq %rax, %rbx
jmp 0x6497
movq %rax, %rbx
jmp 0x64c8
jmp 0x6440
jmp 0x6436
movq %rax, %rbx
jmp 0x64f3
jmp 0x6448
movq %rax, %rbx
jmp 0x64df
movq %rax, %rbx
jmp 0x647d
jmp 0x6466
movq %rax, %rbx
movq 0x130(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6469
callq 0x53d0
jmp 0x6469
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x647d
callq 0x53d0
leaq 0x370(%rsp), %rdi
callq 0x6a92
leaq 0x90(%rsp), %rdi
callq 0x6a58
leaq 0x10(%rsp), %rdi
callq 0x6982
leaq 0xb0(%rsp), %rdi
callq 0x6982
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x64c8
callq 0x53d0
leaq 0x80(%rsp), %rax
movq 0x70(%rsp), %rdi
cmpq %rax, %rdi
je 0x64df
callq 0x53d0
leaq 0x40(%rsp), %rax
movq 0x30(%rsp), %rdi
cmpq %rax, %rdi
je 0x64f3
callq 0x53d0
leaq 0x190(%rsp), %rdi
callq 0x6898
movq %rbx, %rdi
callq 0x56b0