// File: /workspace/github_cpp_makefile_star2_O1/simonrharris[P]SKA/src/sk_unique.cpp
// Function: uniqueKmers(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>>>> const&, 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>>>> const&, float const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool)
int uniqueKmers(const std::vector < std::string > & ingroupsamples, const std::vector < std::string > & kmerfiles, const float & minproportion, const std::string & outputfile, const bool incNs)
{

	const std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
	// Create the kmer map
	std::unordered_map < std::string , std::vector < bool > > kmerMap;
	int oldkmersize=0;
	int totalingroupkmers=0;

	std::vector < std::string > sampleNames;

	if (collectSampleNames(kmerfiles, sampleNames)!=0){return 1;}
	int numSamples=sampleNames.size();

	float maxmissing=(1.0-minproportion)*ingroupsamples.size();

	float minrequired=ingroupsamples.size()-maxmissing;

	std::set < std::string > ingroupSet(ingroupsamples.begin(), ingroupsamples.end());

	if (ingroupSet.size()!=ingroupsamples.size()){
		std::cout << "Warning: Duplicate samples in your ingroup sample file have been removed" << std::endl;
	}

	std::vector < int > ingroupSamplePositions;

	for (int i=0; i<sampleNames.size(); ++i){
		std::set < std::string >::iterator it = ingroupSet.find(sampleNames[i]);//check if the kmer is in the map
			if ( it != ingroupSet.end() ){//if the kmer is in the map
				ingroupSamplePositions.push_back(i);
			}
	}
	
	if (ingroupsamples.size()!=ingroupSamplePositions.size()){
		std::cout << ingroupsamples.size() << " " << ingroupSamplePositions.size() << std::endl;
		std::cout << "Error: Some of your ingroup samples are not in your input files" << std::endl << std::endl;
		return 1;
	}

	std::vector < std::string > fileSampleNames;	
	int sampleNum=0;
	int numfiles=kmerfiles.size();
	std::ifstream fileStream;
	int kmersize;
	char * kmerbuffer;


	for (int s = 0; s < kmerfiles.size(); ++s){

		if (openFileStream(kmerfiles[s], fileStream)){return 1;};

		int newkmersize;
		
		readKmerHeader(fileStream, newkmersize, fileSampleNames);
		
		if (s==0){
			kmersize=newkmersize;
		}

		if (newkmersize!=kmersize){
			std::cout << "kmer files have different kmer sizes" << std::endl << std::endl;
			return 0;
		}


		int numFileSamples=fileSampleNames.size();

		char basebuffer[1];
		char kmerbuffer[(kmersize*2/3)+1];
		char asciibuffer[int(std::ceil(float(fileSampleNames.size())/6))];

		while (fileStream.read(asciibuffer, sizeof(asciibuffer))){//read the ascii representation of the taxa
			std::string asciibits (asciibuffer, sizeof(asciibuffer));
			std::vector < bool > mybits;
			vectorbool_from_ascii(asciibits, mybits);//read the ascii representation of the taxa to a vector of bools

			while (fileStream.peek()!='\n' && fileStream.read(kmerbuffer, sizeof(kmerbuffer))){
				std::string kmer (kmerbuffer, (kmersize*2/3)+1);
				
				std::unordered_map < std::string , std::vector < bool > >::iterator it = kmerMap.find(kmer);//check if the kmer is in the map
				if ( it != kmerMap.end() ){//if the kmer is in the map
					for (int i=0; i<mybits.size(); ++i){
						it->second[i+sampleNum]=mybits[i];
					}
				}
				else {//if the kmer is not in the hash
					std::vector < bool > taxonBitset(numSamples, false);//create a new vector of bools for all samples
					for (int i=0; i<mybits.size(); ++i){ //change the bools to true based for taxa in the file containing the kmer
						taxonBitset[i+sampleNum]=mybits[i];
					}
					kmerMap.insert(std::make_pair(kmer, taxonBitset));//add the new vector to the map
				}
	    	}
	    	fileStream.ignore(256,'\n');//skip the end ofline character
    	}
    	sampleNum+=numFileSamples; //add the number of samples in the file to the count of total samples
    	fileSampleNames.clear();
		fileStream.close();
	}

	std::cout << kmerMap.size() << " kmers identified from " << sampleNum << " samples in " << numfiles << " files" << std::endl;

	int uniquecount=0;
	std::unordered_map < std::string , std::vector < bool > >::iterator it = kmerMap.begin();
	std::unordered_map < std::string , std::vector < bool > >::iterator endIter = kmerMap.end();
	std::unordered_map < std::vector < bool >,  std::vector < std::string > > revKmerMap;

	for (; it!=endIter; ){

		if (not incNs && it->first[0]=='N'){
			kmerMap.erase(it++);
			continue;
		}

		int allcount=std::count(it->second.begin(), it->second.end(), true);
		int ingroupcount=0;

		for (std::vector < int >::iterator it2=ingroupSamplePositions.begin(); it2!=ingroupSamplePositions.end(); ++it2){
			if (it->second[*it2]){
				ingroupcount++;
			}
		}
		if (ingroupcount>=minrequired && (allcount-ingroupcount)==0){
			uniquecount++;

			std::vector < bool > ingroupBitString (ingroupSamplePositions.size(), false);
			int i=0;
			for (std::vector < int >::iterator it2=ingroupSamplePositions.begin(); it2!=ingroupSamplePositions.end(); ++it2, ++i){
				ingroupBitString[i]=it->second[*it2];
			}

			std::unordered_map < std::vector < bool >,  std::vector < std::string > >::iterator it2 = revKmerMap.find(ingroupBitString);//check if the bitset is in the map
			if ( it2 != revKmerMap.end() ){//if the bitset is in the map
				it2->second.push_back(it->first); //add the kmer
			}
			else {//if the bitset isn't in the map
				//std::vector < std::string > myvector; //create a new vector of strings
				//myvector.push_back(it->first); //add the bitset to the vector
				revKmerMap.insert(std::make_pair(ingroupBitString, std::vector < std::string > {it->first})); //insert the vector into the map
			}
		}
		kmerMap.erase(it++); //remove kmer from kmerMap to save space
	}

	std::cout << uniquecount << " unique shared kmers will be written to " << outputfile << std::endl;

	std::vector < std::string > orderedingroupsamples;
	for ( std::vector < int >::iterator it=ingroupSamplePositions.begin(); it!=ingroupSamplePositions.end(); ++it){ //print each sample name to output file stream
		orderedingroupsamples.push_back(sampleNames[*it]); 
	}

	if(printMergedKmerFile(revKmerMap, outputfile, orderedingroupsamples, kmersize)){return 1;}

	printDuration(start);
	
	return 0;
	
	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movl %r8d, -0x130(%rbp)
movq %rcx, -0x1e0(%rbp)
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %rbx
callq 0x5060
movq %rax, %r12
leaq -0x238(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
leaq -0x1a0(%rbp), %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movl $0x1, %r14d
movq %r13, %rdi
movl $0x1, %edx
callq 0x98af
testl %eax, %eax
jne 0x2401f
movq -0x198(%rbp), %rdi
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %rdx, %r14
subq %rsi, %r14
sarq $0x5, %r14
js 0x23165
xorps %xmm0, %xmm0
cvtsi2ss %r14, %xmm0
jmp 0x23180
movq %r14, %rax
shrq %rax
movl %r14d, %ecx
andl $0x1, %ecx
orq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movq %r13, -0x1b0(%rbp)
xorps %xmm0, %xmm0
cvtss2sd (%r15), %xmm0
movsd %xmm0, -0x1d8(%rbp)
subq -0x1a0(%rbp), %rdi
movq %rdi, -0x58(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x24270
movq %r14, -0x1a8(%rbp)
movq %r12, -0x1d0(%rbp)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x5, %rax
cmpq %rax, -0x270(%rbp)
je 0x2321b
movq 0x1dde4(%rip), %r14     # 0x40fc0
leaq 0x11496(%rip), %rsi     # 0x34679
movl $0x48, %edx
movq %r14, %rdi
callq 0x5420
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq 0x1ddb2(%rip), %rdi     # 0x40fc0
callq 0x5030
movq %rax, %rdi
callq 0x5250
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x4a0(%rbp)
movq -0x1a0(%rbp), %rax
cmpq %rax, -0x198(%rbp)
je 0x232c8
leaq -0x290(%rbp), %r13
xorl %esi, %esi
leaq -0x298(%rbp), %r14
leaq -0x50(%rbp), %r15
leaq -0x4a0(%rbp), %r12
shlq $0x5, %rsi
addq %rax, %rsi
movq %r14, %rdi
callq 0xb694
cmpq %r13, %rax
je 0x2329e
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x23293
movl -0x4a0(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0x2329e
movq %r15, %rdi
movq %r12, %rdx
callq 0xe01e
movslq -0x4a0(%rbp), %rsi
incq %rsi
movl %esi, -0x4a0(%rbp)
movq -0x1a0(%rbp), %rax
movq -0x198(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rsi, %rcx
ja 0x23263
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x5, %rsi
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
sarq $0x2, %rax
cmpq %rax, %rsi
jne 0x2395d
xorps %xmm0, %xmm0
movaps %xmm0, -0x120(%rbp)
movq $0x0, -0x110(%rbp)
movq -0x1b0(%rbp), %rbx
movq 0x8(%rbx), %r14
subq (%rbx), %r14
leaq -0x4a0(%rbp), %rdi
callq 0x5410
movabsq $-0x8000000000000000, %r15 # imm = 0x8000000000000000
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
setne -0x29(%rbp)
movq -0x1a8(%rbp), %r13
movq -0x58(%rbp), %rcx
movq %r14, -0x1c8(%rbp)
je 0x23a39
shrq $0x5, %rcx
movslq %ecx, %rcx
movq %rcx, -0x208(%rbp)
xorl %edi, %edi
movl $0x0, -0x34(%rbp)
movq %rdi, -0x1b8(%rbp)
shlq $0x5, %rdi
addq %rax, %rdi
leaq -0x4a0(%rbp), %rsi
movl $0x1, %edx
callq 0x7f73
testl %eax, %eax
jne 0x23a45
leaq -0x4a0(%rbp), %rdi
leaq -0x84(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x96e2
cmpq $0x0, -0x1b8(%rbp)
movl -0x84(%rbp), %eax
cmovel %eax, %r12d
movl %eax, -0x12c(%rbp)
cmpl %r12d, %eax
jne 0x2341c
movq %rsp, -0x1f0(%rbp)
movq %r12, -0x128(%rbp)
leal (%r12,%r12), %eax
cltq
imulq $0x55555556, %rax, %r12 # imm = 0x55555556
movq %r12, %rax
shrq $0x3f, %rax
shrq $0x20, %r12
leal (%r12,%rax), %ecx
incl %ecx
movq %rcx, -0x58(%rbp)
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rbx
subq %rcx, %rbx
movq %rbx, %rsp
movq -0x118(%rbp), %rcx
subq -0x120(%rbp), %rcx
sarq $0x5, %rcx
js 0x23495
cvtsi2ss %rcx, %xmm0
jmp 0x234aa
movl $0x24, %edx
movq 0x1db98(%rip), %rdi     # 0x40fc0
leaq 0x1005c(%rip), %rsi     # 0x3348b
callq 0x5420
movq 0x1db85(%rip), %rcx     # 0x40fc0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq 0x1db67(%rip), %rdi     # 0x40fc0
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
jmp 0x2391c
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
movq -0x118(%rbp), %rcx
subq -0x120(%rbp), %rcx
shrq $0x5, %rcx
movq %rcx, -0x1e8(%rbp)
addl %eax, %r12d
divss 0x101b2(%rip), %xmm0    # 0x33680
callq 0x51e0
cvttss2si %xmm0, %ecx
leaq 0xf(%rcx), %rax
andq $-0x10, %rax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, %rsp
movq %rcx, -0x200(%rbp)
movq %rdx, -0x1c0(%rbp)
leaq (%rdx,%rcx), %rax
movq %rax, -0x1f8(%rbp)
movslq %r12d, %rax
addq %rbx, %rax
incq %rax
movq %rax, -0x210(%rbp)
movslq -0x34(%rbp), %r13
leaq -0x4a0(%rbp), %rdi
movq -0x1c0(%rbp), %rsi
movq -0x200(%rbp), %rdx
callq 0x5480
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x238ac
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %r14
movq %r14, %rdi
movq -0x1c0(%rbp), %rsi
movq -0x1f8(%rbp), %rdx
callq 0x862a
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
movl %eax, -0xd8(%rbp)
movq %rax, -0xd0(%rbp)
movl %eax, -0xc8(%rbp)
movq %rax, -0xc0(%rbp)
movq %r14, %rdi
leaq -0xe0(%rbp), %rsi
callq 0x89ef
leaq -0x100(%rbp), %r14
leaq -0x4a0(%rbp), %rdi
callq 0x5140
cmpl $0xa, %eax
je 0x2382d
leaq -0x4a0(%rbp), %rdi
movq %rbx, %rsi
movq -0x58(%rbp), %rdx
callq 0x5480
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2382d
leaq -0xf0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq %r14, %rdi
movq %rbx, %rsi
movq -0x210(%rbp), %rdx
callq 0x862a
leaq -0x268(%rbp), %rdi
movq %r14, %rsi
callq 0x1b6e4
testq %rax, %rax
je 0x236a9
movq -0xe0(%rbp), %rdx
movq -0xd0(%rbp), %rsi
movl -0xc8(%rbp), %ecx
subq %rdx, %rsi
shlq $0x3, %rsi
addq %rcx, %rsi
je 0x23802
movq 0x28(%rax), %rax
xorl %edi, %edi
movq %rdi, %r10
shrq $0x6, %r10
movq %r13, %rcx
addq %rdi, %rcx
leaq 0x3f(%r13,%rdi), %r9
cmovnsq %rcx, %r9
sarq $0x6, %r9
leaq 0x3f(%r15), %r8
andq %rcx, %r8
xorl %r11d, %r11d
cmpq %r15, %r8
setbe %r11b
movl $0x1, %r8d
shlq %cl, %r8
leaq (%rax,%r9,8), %rcx
leaq -0x8(,%r11,8), %r9
movq (%rdx,%r10,8), %r10
btq %rdi, %r10
jae 0x23691
orq (%rcx,%r9), %r8
jmp 0x23698
notq %r8
andq (%rcx,%r9), %r8
movq %r8, (%rcx,%r9)
incq %rdi
cmpq %rdi, %rsi
ja 0x23641
jmp 0x23802
movb $0x0, -0x180(%rbp)
leaq -0x80(%rbp), %rdi
movq -0x208(%rbp), %rsi
leaq -0x180(%rbp), %rdx
leaq -0x35(%rbp), %rcx
callq 0xac4a
movq -0xe0(%rbp), %rax
movq -0xd0(%rbp), %rdx
movl -0xc8(%rbp), %ecx
subq %rax, %rdx
shlq $0x3, %rdx
addq %rcx, %rdx
je 0x23754
movq -0x80(%rbp), %rsi
xorl %edi, %edi
movq %rdi, %r10
shrq $0x6, %r10
movq %r13, %rcx
addq %rdi, %rcx
leaq 0x3f(%r13,%rdi), %r9
cmovnsq %rcx, %r9
sarq $0x6, %r9
leaq 0x3f(%r15), %r8
andq %rcx, %r8
xorl %r11d, %r11d
cmpq %r15, %r8
setbe %r11b
movl $0x1, %r8d
shlq %cl, %r8
leaq (%rsi,%r9,8), %rcx
leaq -0x8(,%r11,8), %r9
movq (%rax,%r10,8), %r10
btq %rdi, %r10
jae 0x23741
orq (%rcx,%r9), %r8
jmp 0x23748
notq %r8
andq (%rcx,%r9), %r8
movq %r8, (%rcx,%r9)
incq %rdi
cmpq %rdi, %rdx
ja 0x236f1
leaq -0x180(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
leaq -0x80(%rbp), %rdx
callq 0x1b5f2
leaq -0x268(%rbp), %rdi
movq %r12, %rsi
callq 0x1b7e0
movq -0x160(%rbp), %rdi
testq %rdi, %rdi
je 0x237b7
movq -0x140(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
xorl %eax, %eax
movq %rax, -0x160(%rbp)
movl %eax, -0x158(%rbp)
movq %rax, -0x150(%rbp)
movl %eax, -0x148(%rbp)
movq %rax, -0x140(%rbp)
movq -0x180(%rbp), %rdi
leaq -0x170(%rbp), %rax
cmpq %rax, %rdi
je 0x237d9
movq -0x170(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x23802
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
xorl %eax, %eax
movq %rax, -0x80(%rbp)
movl %eax, -0x78(%rbp)
movq %rax, -0x70(%rbp)
movl %eax, -0x68(%rbp)
movq %rax, -0x60(%rbp)
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x235a5
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x235a5
movl $0x100, %esi            # imm = 0x100
leaq -0x4a0(%rbp), %rdi
movl $0xa, %edx
callq 0x5220
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x23881
movq -0xc0(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
movl %eax, -0xd8(%rbp)
movq %rax, -0xd0(%rbp)
movl %eax, -0xc8(%rbp)
movq %rax, -0xc0(%rbp)
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x23515
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x23515
movq -0x120(%rbp), %rbx
movq -0x118(%rbp), %r14
cmpq %rbx, %r14
movq -0x1a8(%rbp), %r13
je 0x238f8
leaq 0x10(%rbx), %r12
movq -0x10(%r12), %rdi
cmpq %rdi, %r12
je 0x238e0
movq (%r12), %rsi
incq %rsi
callq 0x53c0
leaq 0x20(%r12), %rax
addq $0x10, %r12
cmpq %r14, %r12
movq %rax, %r12
jne 0x238ca
movq %rbx, -0x118(%rbp)
leaq -0x4a0(%rbp), %rdi
callq 0x50b0
movq -0x1e8(%rbp), %rax
addl %eax, -0x34(%rbp)
movq -0x1f0(%rbp), %rsp
movq -0x128(%rbp), %r12
xorl %r14d, %r14d
cmpl %r12d, -0x12c(%rbp)
jne 0x23a4b
movq -0x1b8(%rbp), %rdi
incq %rdi
movq -0x1b0(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rdi, %rcx
seta -0x29(%rbp)
ja 0x2335b
jmp 0x23a4b
movq 0x1d65c(%rip), %rdi     # 0x40fc0
callq 0x5240
movq %rax, %rbx
leaq 0x10a25(%rip), %rsi     # 0x34398
movl $0x1, %edx
movq %rax, %rdi
callq 0x5420
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x2, %rsi
movq %rbx, %rdi
callq 0x5240
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq 0x1d5fb(%rip), %rbx     # 0x40fc0
leaq 0x10cf6(%rip), %rsi     # 0x346c2
movl $0x3f, %edx
movq %rbx, %rdi
callq 0x5420
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq 0x1d5c9(%rip), %rdi     # 0x40fc0
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movl $0x1, %r14d
movq %rax, %rdi
callq 0x5250
jmp 0x23ffe
movl $0x0, -0x34(%rbp)
xorl %r14d, %r14d
jmp 0x23a4b
movl $0x1, %r14d
testb $0x1, -0x29(%rbp)
jne 0x23fe6
movq %r12, -0x128(%rbp)
movq -0x250(%rbp), %rsi
movq 0x1d556(%rip), %rdi     # 0x40fc0
callq 0x5240
movq %rax, %rbx
leaq 0xfcf0(%rip), %rsi      # 0x33769
movl $0x17, %edx
movq %rax, %rdi
callq 0x5420
movq %rbx, %rdi
movl -0x34(%rbp), %esi
callq 0x5690
movq %rax, %rbx
leaq 0xfa15(%rip), %rsi      # 0x334b0
movl $0xc, %edx
movq %rax, %rdi
callq 0x5420
movq -0x1c8(%rbp), %rsi
shrq $0x5, %rsi
movq %rbx, %rdi
callq 0x5690
movq %rax, %rbx
leaq 0x1103c(%rip), %rsi     # 0x34b01
movl $0x6, %edx
movq %rax, %rdi
callq 0x5420
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq %r13, %xmm0
punpckldq 0xf89a(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xf8a2(%rip), %xmm0     # 0x333b0
movsd 0xf752(%rip), %xmm1     # 0x33268
subsd -0x1d8(%rbp), %xmm1
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
xorps %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
movss -0x30(%rbp), %xmm1
subss %xmm0, %xmm1
movss %xmm1, -0x30(%rbp)
leaq -0x268(%rbp), %rbx
movq 0x10(%rbx), %r14
leaq -0xb0(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
xorl %r12d, %r12d
movl $0x0, -0x58(%rbp)
movq %r14, %rsi
testq %rsi, %rsi
je 0x23ea3
cmpb $0x0, -0x130(%rbp)
jne 0x23bae
movq 0x8(%rsi), %rax
cmpb $0x4e, (%rax)
jne 0x23bab
movq (%rsi), %r13
movq %rbx, %rdi
callq 0xc764
movq %r13, %rsi
jmp 0x23b80
movq %rsi, %r14
movq 0x28(%r14), %rax
movq 0x38(%r14), %rsi
movl 0x40(%r14), %edi
cmpq %rsi, %rax
setne %cl
testl %edi, %edi
setne %r8b
orb %cl, %r8b
xorl %ecx, %ecx
movl $0x0, %ebx
cmpb $0x1, %r8b
leaq -0x180(%rbp), %rdx
jne 0x23c1a
xorl %ebx, %ebx
xorl %r9d, %r9d
movq %rax, %r8
movq (%r8), %r10
btq %r9, %r10
adcq $0x0, %rbx
xorl %r10d, %r10d
cmpl $0x3f, %r9d
leal 0x1(%r9), %r9d
sete %r10b
leaq (%r8,%r10,8), %r8
cmovel %r12d, %r9d
cmpq %rsi, %r8
setne %r10b
cmpl %edi, %r9d
setne %r11b
orb %r10b, %r11b
jne 0x23be5
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
cmpq %rsi, %rdi
je 0x23c68
xorl %ecx, %ecx
movq %rdi, %r8
movslq (%r8), %r9
leaq 0x3f(%r9), %r10
testq %r9, %r9
cmovnsq %r9, %r10
sarq $0x6, %r10
leaq (%rax,%r10,8), %r10
leaq 0x3f(%r15), %r11
andq %r9, %r11
xorl %r13d, %r13d
cmpq %r15, %r11
setbe %r13b
movq -0x8(%r10,%r13,8), %r10
btq %r9, %r10
adcl $0x0, %ecx
addq $0x4, %r8
cmpq %rsi, %r8
jne 0x23c2c
cmpl %ebx, %ecx
jne 0x23e83
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
ucomiss -0x30(%rbp), %xmm0
jb 0x23e83
subq %rdi, %rsi
sarq $0x2, %rsi
movb $0x0, -0x180(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0xa8(%rbp), %rcx
callq 0xac4a
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
cmpq %rdx, %rax
je 0x23d1f
movq 0x28(%r14), %rsi
movq -0x80(%rbp), %rdi
xorl %r8d, %r8d
xorl %ecx, %ecx
movslq (%rax,%rcx,4), %r11
leaq 0x3f(%r11), %r9
testq %r11, %r11
cmovnsq %r11, %r9
sarq $0x6, %r9
leaq (%rsi,%r9,8), %r13
leaq 0x3f(%r15), %r9
andq %r11, %r9
xorl %ebx, %ebx
cmpq %r15, %r9
setbe %bl
movl $0x1, %r9d
shlq %cl, %r9
movq %rcx, %r10
shrq $0x6, %r10
movq -0x8(%r13,%rbx,8), %rbx
btq %r11, %rbx
jae 0x23d00
orq (%rdi,%r10,8), %r9
jmp 0x23d07
notq %r9
andq (%rdi,%r10,8), %r9
movq %r9, (%rdi,%r10,8)
incq %rcx
leaq (%rax,%r8), %r9
addq $0x4, %r9
addq $0x4, %r8
cmpq %rdx, %r9
jne 0x23cb9
leaq -0xe0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xc0e4
leaq -0x180(%rbp), %rbx
testq %rax, %rax
je 0x23d50
leaq 0x8(%r14), %rsi
addq $0x30, %rax
movq %rax, %rdi
callq 0x855c
jmp 0x23e57
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
callq 0x859a
movl $0x1, %edx
leaq -0x100(%rbp), %rdi
movq %r13, %rsi
leaq -0x84(%rbp), %rcx
callq 0xab86
movq %rbx, %rdi
leaq -0x80(%rbp), %rsi
callq 0xad94
movq -0x100(%rbp), %rax
movq %rax, -0x158(%rbp)
movups -0xf8(%rbp), %xmm0
movups %xmm0, -0x150(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x100(%rbp)
movq $0x0, -0xf0(%rbp)
leaq -0xe0(%rbp), %rdi
movq %rbx, %rsi
callq 0xc3e2
leaq -0x158(%rbp), %rdi
callq 0xabee
movq -0x180(%rbp), %rdi
testq %rdi, %rdi
je 0x23e29
movq -0x160(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq %r12, -0x180(%rbp)
movl %r12d, -0x178(%rbp)
movq %r12, -0x170(%rbp)
movl %r12d, -0x168(%rbp)
movq %r12, -0x160(%rbp)
leaq -0x100(%rbp), %rdi
callq 0xabee
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x23e57
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x23e80
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq %r12, -0x80(%rbp)
movl %r12d, -0x78(%rbp)
movq %r12, -0x70(%rbp)
movl %r12d, -0x68(%rbp)
movq %r12, -0x60(%rbp)
incl -0x58(%rbp)
movq (%r14), %rbx
leaq -0x268(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0xc764
movq %rbx, %r14
movq %r13, %rbx
jmp 0x23b7d
movq 0x1d116(%rip), %rdi     # 0x40fc0
movl -0x58(%rbp), %esi
callq 0x5690
movq -0x1e0(%rbp), %r12
movq %rax, %rbx
leaq 0x1083f(%rip), %rsi     # 0x34702
movl $0x28, %edx
movq %rax, %rdi
callq 0x5420
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %rbx, %rdi
callq 0x5420
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
xorps %xmm0, %xmm0
movaps %xmm0, -0x180(%rbp)
movq $0x0, -0x170(%rbp)
movq -0x50(%rbp), %r14
cmpq -0x48(%rbp), %r14
movq -0x1d0(%rbp), %r15
je 0x23f58
leaq -0x180(%rbp), %rbx
movslq (%r14), %rsi
shlq $0x5, %rsi
addq -0x1a0(%rbp), %rsi
movq %rbx, %rdi
callq 0x855c
addq $0x4, %r14
cmpq -0x48(%rbp), %r14
jne 0x23f38
leaq -0x220(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x230(%rbp), %rdi
callq 0x859a
leaq -0xe0(%rbp), %rdi
leaq -0x230(%rbp), %rsi
leaq -0x180(%rbp), %rdx
movq -0x128(%rbp), %rcx
callq 0x92ac
movl %eax, %ebx
movq -0x230(%rbp), %rdi
cmpq %r14, %rdi
je 0x23fb9
movq -0x220(%rbp), %rsi
incq %rsi
callq 0x53c0
movl $0x1, %r14d
testl %ebx, %ebx
jne 0x23fce
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x8354
leaq -0x180(%rbp), %rdi
callq 0xabee
leaq -0xe0(%rbp), %rdi
callq 0xdec6
leaq -0x4a0(%rbp), %rdi
callq 0x50d0
leaq -0x120(%rbp), %rdi
callq 0xabee
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x24013
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
leaq -0x298(%rbp), %rdi
callq 0xacb2
leaq -0x1a0(%rbp), %rdi
callq 0xabee
leaq -0x268(%rbp), %rdi
callq 0x1b646
movl %r14d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0xabce
jmp 0x2405d
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0xabee
jmp 0x2406e
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x240be
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x240be
jmp 0x240bb
jmp 0x24120
movq %rax, %rbx
movq -0x230(%rbp), %rdi
cmpq %r14, %rdi
je 0x24110
movq -0x220(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x24110
jmp 0x2410d
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x24123
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
xorl %eax, %eax
movq %rax, -0x80(%rbp)
movl %eax, -0x78(%rbp)
movq %rax, -0x70(%rbp)
movl %eax, -0x68(%rbp)
movq %rax, -0x60(%rbp)
jmp 0x24123
jmp 0x24120
movq %rax, %rbx
jmp 0x24223
jmp 0x24103
jmp 0x24120
jmp 0x24140
movq %rax, %rbx
jmp 0x24244
jmp 0x24140
movq %rax, %rbx
jmp 0x24250
jmp 0x24140
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0xabee
jmp 0x24123
jmp 0x24136
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0xdec6
jmp 0x24217
jmp 0x24140
movq %rax, %rbx
jmp 0x2422f
jmp 0x24140
movq %rax, %rbx
jmp 0x24217
jmp 0x241b4
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0x1b5c2
jmp 0x2415e
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x2418e
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
xorl %eax, %eax
movq %rax, -0x80(%rbp)
movl %eax, -0x78(%rbp)
movq %rax, -0x70(%rbp)
movl %eax, -0x68(%rbp)
movq %rax, -0x60(%rbp)
jmp 0x2418e
jmp 0x2418b
movq %rax, %rbx
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x241b7
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x241b7
jmp 0x241b4
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x241f5
movq -0xc0(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
movl %eax, -0xd8(%rbp)
movq %rax, -0xd0(%rbp)
movl %eax, -0xc8(%rbp)
movq %rax, -0xc0(%rbp)
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x24217
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x53c0
leaq -0x4a0(%rbp), %rdi
callq 0x50d0
leaq -0x120(%rbp), %rdi
callq 0xabee
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x24244
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
leaq -0x298(%rbp), %rdi
callq 0xacb2
leaq -0x1a0(%rbp), %rdi
callq 0xabee
leaq -0x268(%rbp), %rdi
callq 0x1b646
movq %rbx, %rdi
callq 0x56a0