// File: /workspace/github_cpp_makefile_star2_O3/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 0x11de0
testl %eax, %eax
jne 0x6398
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x1b8(%rsp), %rsi
movq 0x1c0(%rsp), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0x6c14
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 0x6c14
leaq 0xf0(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x1f8(%rsp), %rsi
movq 0x200(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0x6c14
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 0x6c14
leaq 0x170(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x6514
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 0x63a2
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 0x672e
leaq 0x370(%rsp), %rdi
leaq 0x290(%rsp), %rsi
callq 0x74f6
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 0x5ded
xorl %ebp, %ebp
jmp 0x5e6b
leaq 0x370(%rsp), %rdi
callq 0x7d5e
movl %eax, %ebx
movq 0x331cd(%rip), %rdi     # 0x38fd0
leaq 0x231fe(%rip), %rsi     # 0x29008
movl $0xe, %edx
callq 0x5470
movq 0x331b5(%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
testb $0x1, 0x1b0(%rsp)
jne 0x5e6b
cmpl $0x1, %ebx
je 0x5e6b
cmpl $-0x1, %ebx
jne 0x6369
leaq 0x160(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rdx
leaq 0x150(%rsp), %rdi
callq 0x6c14
leaq 0x150(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x2c(%rsp), %rdx
callq 0x6514
movq 0x150(%rsp), %rdi
cmpq %r14, %rdi
je 0x5ebd
callq 0x53d0
leaq 0x118(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x690a
leaq 0x370(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xad48
leaq 0x118(%rsp), %rdi
callq 0x698e
leaq 0x100(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x69d8
movzbl %bpl, %edx
leaq 0x370(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x82ca
leaq 0x100(%rsp), %rdi
callq 0x6a6a
movq 0x33092(%rip), %rbx     # 0x38fd0
leaq 0x230d2(%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 0x33060(%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 0x61f8
leaq 0x140(%rsp), %rbp
leaq 0x130(%rsp), %r12
movl $0x4, %edx
movq %r14, %rdi
leaq 0x23058(%rip), %rsi     # 0x2902a
callq 0x5470
movq %r14, %rdi
movl %r15d, %esi
callq 0x5680
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x2303b(%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 0x61a4
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 0x6c14
leaq 0x270(%rsp), %rdi
leaq 0x370(%rsp), %rsi
movq %r12, %rdx
leaq 0xf(%rsp), %rcx
callq 0xaa46
movq 0x270(%rsp), %rdi
leaq 0x280(%rsp), %rax
cmpq %rax, %rdi
je 0x60a3
callq 0x53d0
movq 0x130(%rsp), %rdi
cmpq %rbp, %rdi
je 0x60b5
callq 0x53d0
movq $0x0, 0x58(%rsp)
movq 0x50(%rsp), %rax
movb $0x0, (%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
subq %rsi, %rcx
sarq $0x5, %rcx
movq %rcx, %rax
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rdx
movq %rdx, %rdi
shrq $0x3, %rdi
movq %rbx, %rax
xorl %edx, %edx
divq %rdi
testq %rdx, %rdx
jne 0x613a
addq %rax, %rax
leaq (%rax,%rax,4), %rsi
movq %r14, %rdi
callq 0x5290
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x22f1c(%rip), %rsi     # 0x29038
callq 0x5470
movq %r13, %rdi
callq 0x52a0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
subq %rsi, %rcx
sarq $0x5, %rcx
movq %rcx, %rax
shrq $0x2, %rax
movabsq $0x28f5c28f5c28f5c3, %rdx # imm = 0x28F5C28F5C28F5C3
mulq %rdx
movq %rdx, %rdi
shrq $0x2, %rdi
movq %rbx, %rax
xorl %edx, %edx
divq %rdi
testq %rbx, %rbx
je 0x6194
testq %rdx, %rdx
jne 0x6194
movl $0x1, %edx
movq %r14, %rdi
leaq 0x22ebd(%rip), %rsi     # 0x29033
callq 0x5470
movq %r14, %rdi
callq 0x52a0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
subq %rsi, %rcx
sarq $0x5, %rcx
incq %rbx
addq $0x20, %r15
cmpq %rcx, %rbx
jb 0x603d
movl $0x4, %edx
movq %r14, %rdi
leaq 0x22e82(%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 0x5fc3
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 0x22dd4(%rip), %xmm0    # 0x29004
cvtss2sd %xmm0, %xmm0
cvtss2sd 0x3321c(%rip), %xmm1    # 0x39458
leaq 0x370(%rsp), %rdi
callq 0xc9ee
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x625d
callq 0x53d0
leaq 0x370(%rsp), %rdi
callq 0x6aaa
leaq 0x90(%rsp), %rdi
callq 0x6a6a
leaq 0x10(%rsp), %rdi
callq 0x698e
leaq 0xb0(%rsp), %rdi
callq 0x698e
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x62a8
callq 0x53d0
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x62bf
callq 0x53d0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x62d3
callq 0x53d0
movq 0x240(%rsp), %rdi
leaq 0x250(%rsp), %rax
cmpq %rax, %rdi
je 0x62ed
callq 0x53d0
movq 0x1f8(%rsp), %rdi
leaq 0x208(%rsp), %rax
cmpq %rax, %rdi
je 0x6307
callq 0x53d0
movq 0x1d8(%rsp), %rdi
leaq 0x1e8(%rsp), %rax
cmpq %rax, %rdi
je 0x6321
callq 0x53d0
movq 0x1b8(%rsp), %rdi
leaq 0x1c8(%rsp), %rax
cmpq %rax, %rdi
je 0x633b
callq 0x53d0
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x6355
callq 0x53d0
xorl %eax, %eax
addq $0x5a8, %rsp            # imm = 0x5A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x370(%rsp), %rdi
callq 0xb3a0
leaq 0x370(%rsp), %rdi
callq 0xb52e
addss 0x330cd(%rip), %xmm0    # 0x39458
movss %xmm0, 0x330c5(%rip)    # 0x39458
jmp 0x5f37
movl $0x1, %edi
callq 0x54a0
leaq 0x22cca(%rip), %rdi     # 0x29073
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x55d0
jmp 0x6454
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x6a6a
jmp 0x6489
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x698e
jmp 0x6489
movq %rax, %rbx
movq 0x150(%rsp), %rdi
cmpq %r14, %rdi
jne 0x6484
jmp 0x6489
jmp 0x6472
movq %rax, %rbx
leaq 0x290(%rsp), %rdi
callq 0x68a4
jmp 0x6496
movq %rax, %rbx
jmp 0x6496
jmp 0x6431
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r14, %rdi
je 0x64a3
callq 0x53d0
jmp 0x64a3
movq %rax, %rbx
jmp 0x64a3
movq %rax, %rbx
jmp 0x64d4
jmp 0x644c
jmp 0x6442
movq %rax, %rbx
jmp 0x64ff
jmp 0x6454
movq %rax, %rbx
jmp 0x64eb
movq %rax, %rbx
jmp 0x6489
jmp 0x6472
movq %rax, %rbx
movq 0x130(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6475
callq 0x53d0
jmp 0x6475
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x6489
callq 0x53d0
leaq 0x370(%rsp), %rdi
callq 0x6aaa
leaq 0x90(%rsp), %rdi
callq 0x6a6a
leaq 0x10(%rsp), %rdi
callq 0x698e
leaq 0xb0(%rsp), %rdi
callq 0x698e
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x64d4
callq 0x53d0
leaq 0x80(%rsp), %rax
movq 0x70(%rsp), %rdi
cmpq %rax, %rdi
je 0x64eb
callq 0x53d0
leaq 0x40(%rsp), %rax
movq 0x30(%rsp), %rdi
cmpq %rax, %rdi
je 0x64ff
callq 0x53d0
leaq 0x190(%rsp), %rdi
callq 0x68a4
movq %rbx, %rdi
callq 0x56b0