// File: /workspace/github_cpp_makefile_star2_O2/BU-DiSC[P]BF-Shared-Hashing/db.cpp
// Function: db::Build(std::vector<std::vector<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, std::allocator<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>, std::allocator<std::vector<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, std::allocator<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>>>, bool)
void db::Build( vector<vector<vector<string> > > reallocated_keys, bool bf_only )
{
	cout << "DB Build started." << endl;

	string index_command = "rm -rf " + index_dir+"/*";
	string data_command = "rm -rf " + data_dir+"/*";
	string bf_command = "rm -rf " + bf_dir+"/*";
	system(bf_command.c_str());
	if ( bf_only==false ){
		system(data_command.c_str());
		system(index_command.c_str());
	}
	
	fp_vec = vector<uint64_t> (num_levels, 0);
	n_vec = vector<uint64_t> (num_levels, 0);
	ofstream file_settings (settings_file, ios::out);
	file_settings << P << endl;
	file_settings << B << endl;
	file_settings << E << endl;
	file_settings << K << endl;
	file_settings << num_filter_units << endl;
	hash_digests = vector<uint64_t> (num_filter_units, 0);
	file_settings << num_levels << endl;
	file_settings << last_sst_keys << endl;

	ofstream file_fence(fence_file, ios::out);
	for ( int i=0 ; i<num_levels ; i++ ){
                int len = fence_pointers[i].size();
		for ( int j=0 ; j<len ; j++ ){
			file_fence << fence_pointers[i][j] << endl;
		}
	}
	file_fence.close();
	if(fastlocal_bf){
		FastLocalBF tmpbf = FastLocalBF(bpk/num_filter_units);
		filter_size = tmpbf.CalculateSpace(B*P);
		last_filter_size = tmpbf.CalculateSpace(last_sst_keys);
		num_probes = tmpbf.num_probes_;
	}else{
		LegacyBF tmpbf = LegacyBF(bpk/num_filter_units);
		uint32_t dont_care;
		filter_size = tmpbf.CalculateSpace(B*P, &dont_care, &num_lines);
		last_filter_size = tmpbf.CalculateSpace(last_sst_keys, &dont_care, &last_num_lines);
		num_probes = tmpbf.num_probes_;

	}
	
	
	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*));
	cout << "total lv " << num_levels << endl;
	for( int l = 0; l < num_levels; l++){
		cout << "lv " << l << endl;
		vector<vector<string> > keys_one_level = reallocated_keys[l];
		int num_sst = keys_one_level.size();
		bf_prime[l] = (char***) malloc (num_sst*sizeof(char**));
		blk_fp_prime[l] = (char***) malloc (num_sst*sizeof(char**));
		blk_size_prime[l] = (int*) malloc (num_sst*sizeof(int));
		file_settings << num_sst << endl;
		for(int sst_index = 0; sst_index < num_sst; sst_index++){
			vector<string> keys_one_sst = keys_one_level[sst_index];
			char** sst_bf = (char**) malloc (num_filter_units*sizeof(char*));
			string sst_bf_prefix = bf_dir + "level_" + to_string(l) + "-sst_" + to_string(sst_index);



			for(int blo = 0; blo < num_filter_units; blo++){
				string sst_bf_filename = sst_bf_prefix + "_" + to_string(blo) +".txt";
				//cout << sst_bf_filename << endl;
				int end = keys_one_sst.size();
				if(fastlocal_bf){
					FastLocalBF bf = FastLocalBF(bpk/num_filter_units);
					for( int i=0 ; i <end ; i++){
					
						BFHash bfHash (keys_one_sst[i]);	
						vector<uint64_t>* hash_digests = bfHash.getLevelwiseHashDigest(l);
						BFHash::reset = true;
						bf.AddKey(keys_one_sst[i], hash_digests->at(blo));
					}
					bf.Finish();
					flushBFfile(sst_bf_filename, bf.data_, bf.space_);
					char* blo_bf = ( char*) malloc (bf.space_*sizeof(char));
					memcpy(blo_bf, bf.data_, bf.space_);
					sst_bf[blo] = blo_bf;
				}else{
					LegacyBF bf = LegacyBF(bpk/num_filter_units);
					for( int i=0 ; i <end ; i++){
					
						BFHash bfHash (keys_one_sst[i]);	
						vector<uint64_t>* hash_digests = bfHash.getLevelwiseHashDigest(l);
						BFHash::reset = true;
						bf.AddKey(keys_one_sst[i], hash_digests->at(blo));
					}
					bf.Finish();
					flushBFfile(sst_bf_filename, bf.data_, bf.space_);
					char* blo_bf = ( char*) malloc (bf.space_*sizeof(char));
					memcpy(blo_bf, bf.data_, bf.space_);
					sst_bf[blo] = blo_bf;
				}
				//FastLocalBF bf (bpk/num_filter_units*1000);
				
			}
			bf_prime[l][sst_index] = sst_bf;

			// fence pointers
			
			string sst_index_filename = index_dir + "level_" + to_string(l) + "-sst_" + to_string(sst_index) + ".txt";
			// building index
			char** index_one_sst = (char**) malloc (ceil(keys_one_sst.size()/B)*sizeof(char*));
			int j = 0;
			for( int i=0; i<keys_one_sst.size() ; i+=B ){
				index_one_sst[j] = (char *) malloc ((K+1)*sizeof(char));
				strcpy(index_one_sst[j], keys_one_sst[i].c_str());
				j++;
			}
			blk_fp_prime[l][sst_index] = index_one_sst;
			blk_size_prime[l][sst_index] = j;
			flushIndexes(sst_index_filename, index_one_sst, j, K);
			string sst_data_filename = data_dir + "level_" + to_string(l) + "-sst_" + to_string(sst_index) + ".txt";
			for( int i=0 ; i<keys_one_sst.size() ; i++ ){
				keys_one_sst[i].resize(E, '0');
			}
			flushfile(sst_data_filename, &keys_one_sst);
		
		}
	}

	file_settings.close();

	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6d8, %rsp            # imm = 0x6D8
movl %edx, %ebx
movq %rsi, 0xc8(%rsp)
movq %rdi, %r15
movq 0x2c80f(%rip), %rdi     # 0x34fc8
leaq 0x19ba0(%rip), %rsi     # 0x22360
callq 0x6410
movq %rax, %rdi
callq 0x6210
leaq 0x40(%r15), %rdx
leaq 0x19b9a(%rip), %rsi     # 0x22372
leaq 0x2d8(%rsp), %r14
movq %r14, %rdi
movq %rdx, 0xd8(%rsp)
callq 0xb2b0
leaq 0x19b83(%rip), %rdx     # 0x2237a
leaq 0x218(%rsp), %rdi
movq %r14, %rsi
callq 0xb514
leaq 0x2d8(%rsp), %rdi
callq 0x61f0
movq %r15, (%rsp)
leaq 0x60(%r15), %rdx
leaq 0x19b4f(%rip), %rsi     # 0x22372
leaq 0x2d8(%rsp), %rdi
movq %rdx, 0xd0(%rsp)
callq 0xb2b0
leaq 0x19b3b(%rip), %rdx     # 0x2237a
leaq 0x1f8(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0xb514
leaq 0x2d8(%rsp), %rdi
callq 0x61f0
movq (%rsp), %rax
leaq 0x20(%rax), %rdx
leaq 0x19b02(%rip), %rsi     # 0x22372
leaq 0x2d8(%rsp), %rdi
movq %rdx, 0xe0(%rsp)
callq 0xb2b0
leaq 0x19aee(%rip), %rdx     # 0x2237a
leaq 0x1d8(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0xb514
leaq 0x2d8(%rsp), %rdi
callq 0x61f0
movq 0x1d8(%rsp), %rdi
callq 0x6370
testb %bl, %bl
jne 0x88d9
movq 0x1f8(%rsp), %rdi
callq 0x6370
movq 0x218(%rsp), %rdi
callq 0x6370
movq (%rsp), %rbx
movslq 0xdc(%rbx), %rsi
leaq 0x4d8(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x2d8(%rsp), %rdi
leaq 0x58(%rsp), %rcx
callq 0xb326
leaq 0x1b0(%rbx), %rdi
leaq 0x2d8(%rsp), %rbx
movq %rbx, %rsi
callq 0xd66c
movq %rbx, %rdi
movq (%rsp), %rbx
callq 0x752a
movslq 0xdc(%rbx), %rsi
leaq 0x4d8(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x2d8(%rsp), %rdi
leaq 0x58(%rsp), %rcx
callq 0xb326
leaq 0x1c8(%rbx), %rdi
leaq 0x2d8(%rsp), %rbx
movq %rbx, %rsi
callq 0xd66c
movq %rbx, %rdi
movq (%rsp), %rbx
callq 0x752a
leaq 0x80(%rbx), %rsi
leaq 0x2d8(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x6730
movl 0xc4(%rbx), %esi
leaq 0x2d8(%rsp), %rdi
callq 0x6690
movq %rax, %rdi
callq 0x6210
movl 0xc8(%rbx), %esi
leaq 0x2d8(%rsp), %rdi
callq 0x6690
movq %rax, %rdi
callq 0x6210
movl 0xcc(%rbx), %esi
leaq 0x2d8(%rsp), %rdi
callq 0x6690
movq %rax, %rdi
callq 0x6210
movl 0xd0(%rbx), %esi
leaq 0x2d8(%rsp), %rdi
callq 0x6690
movq %rax, %rdi
callq 0x6210
movl 0x110(%rbx), %esi
leaq 0x2d8(%rsp), %rdi
callq 0x6690
movq %rax, %rdi
callq 0x6210
movslq 0x110(%rbx), %rsi
leaq 0x58(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x4d8(%rsp), %rdi
leaq 0x198(%rsp), %rcx
callq 0xb326
leaq 0x170(%rbx), %rdi
leaq 0x4d8(%rsp), %rbx
movq %rbx, %rsi
callq 0xd66c
movq %rbx, %rdi
movq (%rsp), %rbx
callq 0x752a
movl 0xdc(%rbx), %esi
leaq 0x2d8(%rsp), %rdi
callq 0x6690
movq %rax, %rdi
callq 0x6210
movl 0x100(%rbx), %esi
leaq 0x2d8(%rsp), %rdi
callq 0x6690
movq %rax, %rdi
callq 0x6210
leaq 0xa0(%rbx), %rsi
leaq 0x4d8(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x6730
xorl %r14d, %r14d
leaq 0x4d8(%rsp), %rbx
xorl %r15d, %r15d
movq (%rsp), %r12
movslq 0xdc(%r12), %rax
cmpq %rax, %r15
jge 0x8b17
movq 0x140(%r12), %rax
imulq $0x18, %r15, %r12
movq 0x8(%rax,%r12), %r13
subq (%rax,%r12), %r13
shrq $0x5, %r13
testl %r13d, %r13d
cmovlel %r14d, %r13d
shlq $0x5, %r13
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0x8b12
movq (%rsp), %rax
movq 0x140(%rax), %rax
movq (%rax,%r12), %rsi
addq %rbp, %rsi
movq %rbx, %rdi
callq 0x63b0
movq %rax, %rdi
callq 0x6210
addq $0x20, %rbp
jmp 0x8ae5
incq %r15
jmp 0x8aae
leaq 0x4d8(%rsp), %rdi
callq 0x6590
movq %r12, %rbx
cmpb $0x1, 0x10c(%r12)
pushq $0x1
popq %rsi
pushq $0x1e
popq %rdi
jne 0x8bad
movl 0x104(%rbx), %eax
cltd
idivl 0x110(%rbx)
leaq 0x58(%rsp), %rdi
movl %eax, %esi
callq 0xb534
movl 0xc4(%rbx), %esi
imull 0xc8(%rbx), %esi
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0xb586
movq (%rsp), %rcx
movl %eax, 0x120(%rcx)
movq (%rsp), %rax
movl 0x100(%rax), %esi
movq %rbx, %rdi
callq 0xb586
movq (%rsp), %rcx
movl %eax, 0x124(%rcx)
movl 0x4(%rbx), %eax
movq (%rsp), %rcx
movl %eax, 0x130(%rcx)
leaq 0x78(%rsp), %rdi
callq 0xc22a
jmp 0x8c6e
movl 0x104(%rbx), %eax
cltd
idivl 0x110(%rbx)
leaq 0x68(%rsp), %rbx
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rbx)
movups %xmm0, (%rbx)
cvtsi2sd %eax, %xmm0
mulsd 0x1951a(%rip), %xmm0    # 0x220f0
cvttsd2si %xmm0, %ecx
movl %eax, -0x10(%rbx)
cmpl $0x2, %ecx
cmovll %esi, %ecx
cmpl $0x1e, %ecx
cmovgel %edi, %ecx
movl %ecx, -0xc(%rbx)
movq (%rsp), %rax
movl 0xc4(%rax), %esi
movq (%rsp), %rax
imull 0xc8(%rax), %esi
movq (%rsp), %rax
leaq 0x128(%rax), %rcx
leaq 0x58(%rsp), %r14
leaq 0x198(%rsp), %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x7c18
movq (%rsp), %rcx
movl %eax, 0x120(%rcx)
movq (%rsp), %rax
movl 0x100(%rax), %esi
movq (%rsp), %rax
leaq 0x12c(%rax), %rcx
movq %r14, %rdi
movq %r15, %rdx
callq 0x7c18
movq (%rsp), %rcx
movl %eax, 0x124(%rcx)
movl 0x4(%r14), %eax
movq (%rsp), %rcx
movl %eax, 0x130(%rcx)
movq %rbx, %rdi
callq 0xc250
movq (%rsp), %rax
movslq 0xdc(%rax), %rbx
shlq $0x3, %rbx
movq %rbx, %rdi
callq 0x6550
movq (%rsp), %rcx
movq %rax, 0x158(%rcx)
movq %rbx, %rdi
callq 0x6550
movq (%rsp), %rcx
movq %rax, 0x160(%rcx)
movq %rbx, %rdi
movq (%rsp), %rbx
callq 0x6550
movq %rax, 0x168(%rbx)
movq 0x2c30b(%rip), %rdi     # 0x34fc8
leaq 0x196b9(%rip), %rsi     # 0x2237d
callq 0x6410
movl 0xdc(%rbx), %esi
movq %rax, %rdi
callq 0x6690
movq %rax, %rdi
callq 0x6210
leaq 0x158(%rsp), %r13
xorl %r14d, %r14d
movslq 0xdc(%rbx), %rax
cmpq %rax, %r14
jge 0x952e
movq 0x2c2c7(%rip), %rdi     # 0x34fc8
leaq 0x1967b(%rip), %rsi     # 0x22383
callq 0x6410
movq %rax, %rdi
movl %r14d, %esi
callq 0x6690
movq %rax, %rdi
callq 0x6210
imulq $0x18, %r14, %rsi
movq 0xc8(%rsp), %rax
addq (%rax), %rsi
leaq 0x120(%rsp), %rdi
callq 0x77a8
movq %r14, %rbp
movq 0x128(%rsp), %rax
subq 0x120(%rsp), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, %r14
movq %rax, %r15
shlq $0x20, %r15
movq %r15, %r12
sarq $0x1d, %r12
movq %r12, %rdi
callq 0x6550
movq 0x158(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
movq %r12, %rdi
callq 0x6550
movq 0x160(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
sarq $0x1e, %r15
movq %r15, %rdi
callq 0x6550
movq 0x168(%rbx), %rcx
movq %rbp, 0x8(%rsp)
movq %rax, (%rcx,%rbp,8)
leaq 0x2d8(%rsp), %rdi
movl %r14d, %esi
callq 0x6690
movq %rax, %rdi
callq 0x6210
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
movq %rax, 0xe8(%rsp)
xorl %eax, %eax
leaq 0x20(%rsp), %r15
cmpq 0xe8(%rsp), %rax
je 0x9514
movq %rax, 0x10(%rsp)
imulq $0x18, %rax, %rsi
addq 0x120(%rsp), %rsi
movq %r15, %rdi
callq 0x734a
movslq 0x110(%rbx), %rdi
shlq $0x3, %rdi
callq 0x6550
movq %rax, 0x18(%rsp)
movq %r13, %rdi
movq 0xe0(%rsp), %rsi
leaq 0x1955c(%rip), %rdx     # 0x22387
callq 0xb278
leaq 0x38(%rsp), %r15
leaq 0x138(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0xb620
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0xb5b9
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
leaq 0x19527(%rip), %rdx     # 0x2238e
callq 0xb514
leaq 0x100(%rsp), %rbp
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
callq 0xb620
leaq 0x198(%rsp), %rdi
leaq 0x58(%rsp), %r12
movq %r12, %rsi
movq %rbp, %rdx
callq 0xb5b9
movq %rbp, %rdi
callq 0x61f0
movq %r12, %rdi
callq 0x61f0
movq %r15, %rdi
callq 0x61f0
movq %r14, %rdi
callq 0x61f0
movq %r13, %rdi
callq 0x61f0
xorl %r12d, %r12d
movslq 0x110(%rbx), %rax
cmpq %rax, %r12
jge 0x9184
movq %r13, %rdi
leaq 0x198(%rsp), %rsi
leaq 0x194a6(%rip), %rdx     # 0x2238c
callq 0xb278
movq %r14, %rdi
movl %r12d, %esi
callq 0xb620
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0xb5b9
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x19dd7(%rip), %rdx     # 0x22ced
callq 0xb514
movq %rbp, %rdi
callq 0x61f0
movq %r14, %rdi
callq 0x61f0
movq %r13, %rdi
callq 0x61f0
movq 0x28(%rsp), %r15
subq 0x20(%rsp), %r15
shrq $0x5, %r15
cmpb $0x1, 0x10c(%rbx)
jne 0x8fd8
movl 0x104(%rbx), %eax
cltd
idivl 0x110(%rbx)
movq %rbp, %rdi
movl %eax, %esi
callq 0xb534
testl %r15d, %r15d
movl $0x0, %eax
cmovlel %eax, %r15d
shlq $0x5, %r15
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x90f8
movq 0x20(%rsp), %rsi
addq %rbx, %rsi
movq %r13, %rdi
callq 0xb67a
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0xecc4
leaq 0x2c444(%rip), %rcx     # 0x353e8
movb $0x1, (%rcx)
movq 0x20(%rsp), %r14
movq %rax, %rdi
movq %r12, %rsi
callq 0xb6d8
addq %rbx, %r14
movq (%rax), %rdx
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
callq 0xb6c6
movq %r13, %rdi
callq 0x61f0
addq $0x20, %rbx
jmp 0x8f77
movl 0x104(%rbx), %eax
cltd
idivl 0x110(%rbx)
leaq 0x68(%rsp), %rcx
andq $0x0, 0x10(%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rcx)
cvtsi2sd %eax, %xmm0
movl %eax, 0x58(%rsp)
mulsd 0x190e9(%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, 0x5c(%rsp)
testl %r15d, %r15d
movl $0x0, %eax
cmovlel %eax, %r15d
shlq $0x5, %r15
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x9085
movq 0x20(%rsp), %rsi
addq %rbx, %rsi
movq %r13, %rdi
callq 0xb67a
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0xecc4
leaq 0x2c38c(%rip), %rcx     # 0x353e8
movb $0x1, (%rcx)
movq %rax, %rdi
movq %r12, %rsi
callq 0xb6d8
movq (%rax), %rdx
leaq 0x58(%rsp), %rdi
callq 0x7a70
movq %r13, %rdi
callq 0x61f0
addq $0x20, %rbx
jmp 0x9033
leaq 0x58(%rsp), %rdi
callq 0x7a98
leaq 0x38(%rsp), %rsi
leaq 0x298(%rsp), %rbx
movq %rbx, %rdi
callq 0x6570
movq 0x80(%rsp), %rdx
movl 0x64(%rsp), %ecx
movq %rbx, %rsi
callq 0x98a0
movq %rbx, %rdi
callq 0x61f0
movslq 0x64(%rsp), %r14
movq %r14, %rdi
callq 0x6550
movq %rax, %r15
movq 0x80(%rsp), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x6350
movq 0x18(%rsp), %rax
movq %r15, (%rax,%r12,8)
leaq 0x68(%rsp), %rdi
callq 0xc250
jmp 0x9163
leaq 0x58(%rsp), %rdi
callq 0xb6fa
leaq 0x38(%rsp), %rsi
leaq 0x2b8(%rsp), %rbx
movq %rbx, %rdi
callq 0x6570
movq 0x68(%rsp), %rdx
movl 0x70(%rsp), %ecx
movq %rbx, %rsi
callq 0x98a0
movq %rbx, %rdi
callq 0x61f0
movl 0x70(%rsp), %r14d
movq %r14, %rdi
callq 0x6550
movq %rax, %r15
movq 0x68(%rsp), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x6350
movq 0x18(%rsp), %rax
movq %r15, (%rax,%r12,8)
leaq 0x78(%rsp), %rdi
callq 0xc22a
leaq 0x38(%rsp), %r15
movq %r15, %rdi
callq 0x61f0
incq %r12
movq (%rsp), %rbx
leaq 0x138(%rsp), %r14
jmp 0x8ec4
movq 0x158(%rbx), %rax
movq 0x8(%rsp), %rbp
movq (%rax,%rbp,8), %rax
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq %rdx, (%rax,%rcx,8)
leaq 0x100(%rsp), %rdi
movq 0xd8(%rsp), %rsi
leaq 0x191ce(%rip), %rdx     # 0x22387
callq 0xb278
leaq 0x1b8(%rsp), %r12
movq %r12, %rdi
movl %ebp, %esi
callq 0xb620
movq %r14, %rdi
leaq 0x100(%rsp), %rsi
movq %r12, %rdx
callq 0xb5b9
movq %r13, %rdi
movq %r14, %rsi
leaq 0x1919e(%rip), %rdx     # 0x2238e
callq 0xb514
leaq 0x178(%rsp), %r12
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0xb620
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0xb5b9
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
leaq 0x19ac6(%rip), %rdx     # 0x22ced
callq 0xb514
movq %r15, %rdi
callq 0x61f0
leaq 0x178(%rsp), %rdi
callq 0x61f0
movq %r13, %rdi
callq 0x61f0
movq %r14, %rdi
callq 0x61f0
leaq 0x1b8(%rsp), %rdi
callq 0x61f0
leaq 0x100(%rsp), %rdi
callq 0x61f0
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %rax
subq %r12, %rax
sarq $0x5, %rax
movslq 0xc8(%rbx), %r14
movq %rax, 0xf8(%rsp)
xorl %edx, %edx
divq %r14
movq %rax, %xmm0
punpckldq 0x18e73(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x18e7b(%rip), %xmm0    # 0x22120
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x18e07(%rip), %xmm1    # 0x220c0
cvttsd2si %xmm1, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x18e2b(%rip), %xmm1    # 0x220f8
cvttsd2si %xmm1, %rdi
andq %rcx, %rdi
orq %rax, %rdi
callq 0x6550
movq %rax, 0x18(%rsp)
movslq 0xd0(%rbx), %rax
incq %rax
movq %rax, 0xf0(%rsp)
movq %r14, %rbp
movq %r14, %rbx
shlq $0x5, %rbx
xorl %r15d, %r15d
xorl %r14d, %r14d
cmpq %r15, 0xf8(%rsp)
jbe 0x933b
movq 0xf0(%rsp), %rdi
callq 0x6550
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
movq (%r12), %rsi
movq %rax, %rdi
callq 0x63e0
incq %r14
addq %rbp, %r15
addq %rbx, %r12
jmp 0x9304
movq (%rsp), %rbx
movq 0x160(%rbx), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %r12
movq %r12, (%rax,%rdx,8)
movq 0x168(%rbx), %rax
movq (%rax,%rcx,8), %rax
movl %r14d, (%rax,%rdx,4)
leaq 0x278(%rsp), %r15
movq %r15, %rdi
leaq 0x58(%rsp), %rsi
callq 0x6570
movl 0xd0(%rbx), %r8d
movq %r15, %rsi
movq %r12, %rdx
movl %r14d, %ecx
callq 0x993a
movq %r15, %rdi
callq 0x61f0
leaq 0x1b8(%rsp), %r15
movq %r15, %rdi
movq 0xd0(%rsp), %rsi
leaq 0x18fcf(%rip), %rdx     # 0x22387
callq 0xb278
leaq 0x178(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0xb620
leaq 0x100(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xb5b9
leaq 0x138(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x18f91(%rip), %rdx     # 0x2238e
callq 0xb514
leaq 0x238(%rsp), %r12
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0xb620
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xb5b9
leaq 0x38(%rsp), %rdi
movq %r13, %rsi
leaq 0x198b9(%rip), %rdx     # 0x22ced
callq 0xb514
movq %r13, %rdi
callq 0x61f0
leaq 0x238(%rsp), %rdi
callq 0x61f0
movq %rbx, %rdi
callq 0x61f0
movq %r14, %rdi
callq 0x61f0
leaq 0x178(%rsp), %rdi
callq 0x61f0
movq %r15, %rdi
callq 0x61f0
xorl %ebx, %ebx
xorl %r14d, %r14d
leaq 0x20(%rsp), %r15
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %r14, %rax
jbe 0x94b2
addq %rbx, %rdi
movq (%rsp), %rax
movslq 0xcc(%rax), %rsi
pushq $0x30
popq %rdx
callq 0x6160
incq %r14
addq $0x20, %rbx
jmp 0x947d
leaq 0x258(%rsp), %rbx
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x6570
movq %rbx, %rsi
movq %r15, %rdx
callq 0x9a2c
movq %rbx, %rdi
callq 0x61f0
leaq 0x38(%rsp), %rdi
callq 0x61f0
leaq 0x58(%rsp), %rdi
callq 0x61f0
leaq 0x198(%rsp), %rdi
callq 0x61f0
movq %r15, %rdi
callq 0x739e
movq 0x10(%rsp), %rax
incq %rax
movq (%rsp), %rbx
jmp 0x8ddd
leaq 0x120(%rsp), %rdi
callq 0x74f0
movq 0x8(%rsp), %r14
incq %r14
jmp 0x8cea
leaq 0x2d8(%rsp), %rdi
callq 0x6590
leaq 0x4d8(%rsp), %rdi
callq 0x65d0
leaq 0x2d8(%rsp), %rdi
callq 0x65d0
leaq 0x1d8(%rsp), %rdi
callq 0x61f0
leaq 0x1f8(%rsp), %rdi
callq 0x61f0
leaq 0x218(%rsp), %rdi
callq 0x61f0
addq $0x6d8, %rsp            # imm = 0x6D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9770
jmp 0x95ef
jmp 0x95ef
jmp 0x95dd
jmp 0x95dd
jmp 0x95dd
movq %rax, %rbx
leaq 0x2d8(%rsp), %rdi
jmp 0x9878
movq %rax, %rbx
jmp 0x987d
movq %rax, %rbx
leaq 0x2d8(%rsp), %rdi
jmp 0x9885
movq %rax, %rbx
jmp 0x988a
movq %rax, %rbx
leaq 0x2d8(%rsp), %rdi
jmp 0x9892
movq %rax, %rbx
jmp 0x9870
jmp 0x9770
jmp 0x9770
movq %rax, %rbx
jmp 0x9863
jmp 0x9768
jmp 0x9770
movq %rax, %rbx
leaq 0x258(%rsp), %rdi
callq 0x61f0
jmp 0x97a4
jmp 0x97a1
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x61f0
jmp 0x9635
movq %rax, %rbx
jmp 0x9642
movq %rax, %rbx
leaq 0x238(%rsp), %rdi
callq 0x61f0
leaq 0x138(%rsp), %rdi
callq 0x61f0
jmp 0x9654
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x61f0
jmp 0x9683
movq %rax, %rbx
leaq 0x278(%rsp), %rdi
jmp 0x97a9
movq %rax, %rbx
jmp 0x9690
movq %rax, %rbx
jmp 0x9701
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x61f0
leaq 0x1b8(%rsp), %rdi
jmp 0x97a9
jmp 0x96a9
movq %rax, %rbx
jmp 0x96e7
movq %rax, %rbx
jmp 0x96c8
movq %rax, %rbx
jmp 0x97ae
jmp 0x97c4
movq %rax, %rbx
jmp 0x96f4
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x61f0
leaq 0x178(%rsp), %rdi
callq 0x61f0
jmp 0x96da
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x61f0
leaq 0x138(%rsp), %rdi
callq 0x61f0
leaq 0x1b8(%rsp), %rdi
callq 0x61f0
leaq 0x100(%rsp), %rdi
jmp 0x982d
movq %rax, %rbx
jmp 0x9730
movq %rax, %rbx
jmp 0x974e
movq %rax, %rbx
jmp 0x983f
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x61f0
leaq 0x58(%rsp), %rdi
callq 0x61f0
jmp 0x9744
movq %rax, %rbx
jmp 0x975b
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x61f0
leaq 0x138(%rsp), %rdi
callq 0x61f0
leaq 0x158(%rsp), %rdi
jmp 0x983a
movq %rax, %rbx
jmp 0x9849
movq %rax, %rbx
jmp 0x9856
movq %rax, %rbx
leaq 0x298(%rsp), %rdi
jmp 0x9819
movq %rax, %rbx
leaq 0x2b8(%rsp), %rdi
jmp 0x97fd
movq %rax, %rbx
jmp 0x9828
jmp 0x97e8
jmp 0x97ed
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x61f0
leaq 0x58(%rsp), %rdi
jmp 0x982d
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x61f0
jmp 0x97cc
movq %rax, %rbx
jmp 0x9832
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x61f0
jmp 0x97de
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
jmp 0x982d
movq %rax, %rbx
jmp 0x981e
movq %rax, %rbx
jmp 0x9802
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x61f0
leaq 0x78(%rsp), %rdi
callq 0xc22a
jmp 0x9828
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x61f0
leaq 0x68(%rsp), %rdi
callq 0xc250
leaq 0x38(%rsp), %rdi
callq 0x61f0
leaq 0x198(%rsp), %rdi
callq 0x61f0
leaq 0x20(%rsp), %rdi
callq 0x739e
leaq 0x120(%rsp), %rdi
callq 0x74f0
leaq 0x4d8(%rsp), %rdi
callq 0x65d0
leaq 0x2d8(%rsp), %rdi
callq 0x65d0
leaq 0x1d8(%rsp), %rdi
callq 0x61f0
leaq 0x1f8(%rsp), %rdi
callq 0x61f0
leaq 0x218(%rsp), %rdi
callq 0x61f0
movq %rbx, %rdi
callq 0x66b0
nop