// File: /workspace/github_cpp_makefile_star2_O3/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, -0xcc(%rbp)
movq %rcx, -0x1d8(%rbp)
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %rbx
callq 0x5060
movq %rax, -0x1d0(%rbp)
leaq -0x268(%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 0x9851
testl %eax, %eax
jne 0x23cbb
movq -0x198(%rbp), %rdi
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %rdx, %r12
subq %rsi, %r12
sarq $0x5, %r12
js 0x22e8d
xorps %xmm0, %xmm0
cvtsi2ss %r12, %xmm0
jmp 0x22ea8
movq %r12, %rax
shrq %rax
movl %r12d, %ecx
andl $0x1, %ecx
orq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
xorps %xmm0, %xmm0
cvtss2sd (%r15), %xmm0
movsd %xmm0, -0x1c8(%rbp)
subq -0x1a0(%rbp), %rdi
movq %rdi, -0x58(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x23eec
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x5, %rax
cmpq %rax, -0x238(%rbp)
je 0x22f2e
movq 0x1e0d1(%rip), %r14     # 0x40fc0
leaq 0x11773(%rip), %rsi     # 0x34669
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 0x1e09f(%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)
movq %r12, -0x1a8(%rbp)
movq %r13, -0x1b0(%rbp)
je 0x23005
leaq -0x258(%rbp), %r13
xorl %esi, %esi
leaq -0x260(%rbp), %r14
leaq -0x50(%rbp), %r15
leaq -0x4a0(%rbp), %r12
shlq $0x5, %rsi
addq %rax, %rsi
movq %r14, %rdi
callq 0xb648
cmpq %r13, %rax
je 0x22fbf
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x22fb4
movl -0x4a0(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0x22fbf
movq %r15, %rdi
movq %r12, %rdx
callq 0xdeae
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 0x22f84
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
sarq $0x2, %rax
movq -0x1a8(%rbp), %r12
movq -0x1b0(%rbp), %r13
jmp 0x23007
xorl %eax, %eax
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x5, %rsi
cmpq %rax, %rsi
jne 0x235c3
xorps %xmm0, %xmm0
movaps %xmm0, -0xc0(%rbp)
movq $0x0, -0xb0(%rbp)
movq 0x8(%r13), %rbx
subq (%r13), %rbx
leaq -0x4a0(%rbp), %rdi
callq 0x5410
movq %rbx, -0x1c0(%rbp)
movabsq $-0x8000000000000000, %r15 # imm = 0x8000000000000000
movq (%r13), %rax
cmpq %rax, 0x8(%r13)
movq -0x58(%rbp), %rcx
je 0x2369f
shrq $0x5, %rcx
movslq %ecx, %rcx
movq %rcx, -0x208(%rbp)
xorl %r14d, %r14d
movl $0x0, -0x30(%rbp)
movq %r14, %rdi
shlq $0x5, %rdi
addq %rax, %rdi
leaq -0x4a0(%rbp), %rsi
movl $0x1, %edx
callq 0x7f3f
testl %eax, %eax
jne 0x23c07
leaq -0x4a0(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x9684
testq %r14, %r14
sete %al
movl -0x5c(%rbp), %edx
cmpl %edx, %ebx
sete %cl
orb %al, %cl
je 0x23c0f
movq %r14, -0x1f0(%rbp)
movq %rsp, -0x1e8(%rbp)
movq %rdx, -0xc8(%rbp)
leal (%rdx,%rdx), %eax
cltq
imulq $0x55555556, %rax, %r14 # imm = 0x55555556
movq %r14, %rax
shrq $0x3f, %rax
shrq $0x20, %r14
leal (%r14,%rax), %ecx
incl %ecx
movq %rcx, -0x58(%rbp)
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rbx
subq %rcx, %rbx
movq %rbx, %rsp
movq -0xb8(%rbp), %rcx
subq -0xc0(%rbp), %rcx
sarq $0x5, %rcx
js 0x23131
cvtsi2ss %rcx, %xmm0
jmp 0x23146
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
movq -0xb8(%rbp), %rcx
subq -0xc0(%rbp), %rcx
shrq $0x5, %rcx
movq %rcx, -0x1e0(%rbp)
addl %eax, %r14d
divss 0x10516(%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, -0x1b8(%rbp)
leaq (%rdx,%rcx), %rax
movq %rax, -0x1f8(%rbp)
movslq %r14d, %rax
addq %rbx, %rax
incq %rax
movq %rax, -0x210(%rbp)
movslq -0x30(%rbp), %r14
movl %r14d, %r13d
leaq -0x4a0(%rbp), %rdi
movq -0x1b8(%rbp), %rsi
movq -0x200(%rbp), %rdx
callq 0x5480
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x23523
leaq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x80(%rbp), %r12
movq %r12, %rdi
movq -0x1b8(%rbp), %rsi
movq -0x1f8(%rbp), %rdx
callq 0x85fc
xorl %eax, %eax
movq %rax, -0x180(%rbp)
movl %eax, -0x178(%rbp)
movq %rax, -0x170(%rbp)
movl %eax, -0x168(%rbp)
movq %rax, -0x160(%rbp)
movq %r12, %rdi
leaq -0x180(%rbp), %rsi
callq 0x8993
leaq -0x4a0(%rbp), %rdi
callq 0x5140
cmpl $0xa, %eax
je 0x234d0
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 0x234d0
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0xa0(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq -0x210(%rbp), %rdx
callq 0x85fc
leaq -0x298(%rbp), %rdi
movq %r12, %rsi
callq 0x1b44a
testq %rax, %rax
je 0x23346
movq -0x180(%rbp), %rdx
movq -0x170(%rbp), %rsi
movl -0x168(%rbp), %ecx
subq %rdx, %rsi
shlq $0x3, %rsi
addq %rcx, %rsi
je 0x234a5
movq 0x28(%rax), %rax
xorl %edi, %edi
movl %edi, %r8d
shrl $0x6, %r8d
leaq (%r14,%rdi), %rcx
movl %r13d, %r9d
addl %edi, %r9d
leal 0x3f(%r13,%rdi), %r10d
cmovnsl %r9d, %r10d
sarl $0x6, %r10d
movslq %r10d, %r10
leaq 0x3f(%r15), %r9
andq %rcx, %r9
xorl %r11d, %r11d
cmpq %r15, %r9
setbe %r11b
movl $0x1, %r9d
shlq %cl, %r9
leaq (%rax,%r10,8), %rcx
leaq -0x8(,%r11,8), %r10
movq (%rdx,%r8,8), %r8
btq %rdi, %r8
jae 0x2332e
orq (%rcx,%r10), %r9
jmp 0x23335
notq %r9
andq (%rcx,%r10), %r9
movq %r9, (%rcx,%r10)
incq %rdi
cmpq %rdi, %rsi
ja 0x232d7
jmp 0x234a5
movb $0x0, -0x120(%rbp)
leaq -0x148(%rbp), %rdi
movq -0x208(%rbp), %rsi
leaq -0x120(%rbp), %rdx
leaq -0x31(%rbp), %rcx
callq 0xabec
movq -0x180(%rbp), %rax
movq -0x170(%rbp), %rdx
movl -0x168(%rbp), %ecx
subq %rax, %rdx
shlq $0x3, %rdx
addq %rcx, %rdx
je 0x233fe
movq -0x148(%rbp), %rsi
xorl %edi, %edi
movl %edi, %r8d
shrl $0x6, %r8d
leaq (%r14,%rdi), %rcx
movl %r13d, %r9d
addl %edi, %r9d
leal 0x3f(%r13,%rdi), %r10d
cmovnsl %r9d, %r10d
sarl $0x6, %r10d
movslq %r10d, %r10
leaq 0x3f(%r15), %r9
andq %rcx, %r9
xorl %r11d, %r11d
cmpq %r15, %r9
setbe %r11b
movl $0x1, %r9d
shlq %cl, %r9
leaq (%rsi,%r10,8), %rcx
leaq -0x8(,%r11,8), %r10
movq (%rax,%r8,8), %r8
btq %rdi, %r8
jae 0x233eb
orq (%rcx,%r10), %r9
jmp 0x233f2
notq %r9
andq (%rcx,%r10), %r9
movq %r9, (%rcx,%r10)
incq %rdi
cmpq %rdi, %rdx
ja 0x23394
leaq -0x120(%rbp), %r12
movq %r12, %rdi
leaq -0xa0(%rbp), %rsi
leaq -0x148(%rbp), %rdx
callq 0x1b358
leaq -0x298(%rbp), %rdi
movq %r12, %rsi
callq 0x1b546
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x23468
movq -0xe0(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
xorl %eax, %eax
movq %rax, -0x100(%rbp)
movl %eax, -0xf8(%rbp)
movq %rax, -0xf0(%rbp)
movl %eax, -0xe8(%rbp)
movq %rax, -0xe0(%rbp)
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x2348a
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0x148(%rbp), %rdi
testq %rdi, %rdi
je 0x234a5
movq -0x128(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x23234
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x23234
movl $0x100, %esi            # imm = 0x100
leaq -0x4a0(%rbp), %rdi
movl $0xa, %edx
callq 0x5220
movq -0x180(%rbp), %rdi
testq %rdi, %rdi
je 0x23501
movq -0x160(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x231b4
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x231b4
movq -0xc0(%rbp), %rbx
movq -0xb8(%rbp), %r14
cmpq %rbx, %r14
movq -0x1b0(%rbp), %r13
je 0x2356f
leaq 0x10(%rbx), %r12
movq -0x10(%r12), %rdi
cmpq %rdi, %r12
je 0x23557
movq (%r12), %rsi
incq %rsi
callq 0x53c0
leaq 0x20(%r12), %rax
addq $0x10, %r12
cmpq %r14, %r12
movq %rax, %r12
jne 0x23541
movq %rbx, -0xb8(%rbp)
leaq -0x4a0(%rbp), %rdi
callq 0x50b0
movq -0x1e0(%rbp), %rax
addl %eax, -0x30(%rbp)
movq -0x1e8(%rbp), %rsp
movq -0x1f0(%rbp), %r14
incq %r14
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
movq -0xc8(%rbp), %rdx
movl %edx, %ebx
cmpq %r14, %rcx
movq -0x1a8(%rbp), %r12
ja 0x2307f
jmp 0x236a6
movq 0x1d9f6(%rip), %rdi     # 0x40fc0
callq 0x5240
movq %rax, %rbx
leaq 0x10daf(%rip), %rsi     # 0x34388
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 0x1d995(%rip), %rbx     # 0x40fc0
leaq 0x11080(%rip), %rsi     # 0x346b2
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 0x1d963(%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 0x23c9a
movl $0x0, -0x30(%rbp)
movq %rdx, -0xc8(%rbp)
movq -0x280(%rbp), %rsi
movq 0x1d905(%rip), %rdi     # 0x40fc0
callq 0x5240
movq %rax, %rbx
leaq 0x1009f(%rip), %rsi     # 0x33769
movl $0x17, %edx
movq %rax, %rdi
callq 0x5420
movq %rbx, %rdi
movl -0x30(%rbp), %esi
callq 0x5690
movq %rax, %rbx
leaq 0xfdc4(%rip), %rsi      # 0x334b0
movl $0xc, %edx
movq %rax, %rdi
callq 0x5420
movq -0x1c0(%rbp), %rsi
shrq $0x5, %rsi
movq %rbx, %rdi
callq 0x5690
movq %rax, %rbx
leaq 0x113db(%rip), %rsi     # 0x34af1
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 %r12, %xmm0
punpckldq 0xfc49(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xfc51(%rip), %xmm0     # 0x333b0
movsd 0xfb01(%rip), %xmm1     # 0x33268
subsd -0x1c8(%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 -0x2c(%rbp), %xmm1
subss %xmm0, %xmm1
movss %xmm1, -0x2c(%rbp)
leaq -0x298(%rbp), %rbx
movq 0x10(%rbx), %r14
leaq -0x150(%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 0x23ac9
cmpb $0x0, -0xcc(%rbp)
jne 0x237ff
movq 0x8(%rsi), %rax
cmpb $0x4e, (%rax)
jne 0x237fc
movq (%rsi), %r13
movq %rbx, %rdi
callq 0xc6d8
movq %r13, %rsi
jmp 0x237d1
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, %edx
cmpb $0x1, %r8b
jne 0x23864
xorl %edx, %edx
xorl %r9d, %r9d
movq %rax, %r8
movq (%r8), %r10
btq %r9, %r10
adcq $0x0, %rdx
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 0x2382f
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
cmpq %rsi, %rdi
je 0x238b5
xorl %ecx, %ecx
movq %rdi, %r8
movslq (%r8), %r9
leal 0x3f(%r9), %r10d
testq %r9, %r9
cmovnsl %r9d, %r10d
sarl $0x6, %r10d
movslq %r10d, %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 0x23876
cmpl %edx, %ecx
jne 0x23ab3
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
ucomiss -0x2c(%rbp), %xmm0
jb 0x23ab3
subq %rdi, %rsi
sarq $0x2, %rsi
movb $0x0, -0x120(%rbp)
leaq -0x148(%rbp), %rdi
leaq -0x120(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0xabec
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
cmpq %rdx, %rax
je 0x2396e
movq 0x28(%r14), %rsi
xorl %ecx, %ecx
movq -0x148(%rbp), %rdi
movslq (%rax), %r8
leal 0x3f(%r8), %r9d
testq %r8, %r8
cmovnsl %r8d, %r9d
sarl $0x6, %r9d
movslq %r9d, %r9
leaq (%rsi,%r9,8), %r11
leaq 0x3f(%r15), %r9
andq %r8, %r9
xorl %r13d, %r13d
cmpq %r15, %r9
setbe %r13b
movl $0x1, %r9d
shlq %cl, %r9
movl %ecx, %r10d
shrl $0x6, %r10d
movq -0x8(%r11,%r13,8), %r11
btq %r8, %r11
jae 0x23958
orq (%rdi,%r10,8), %r9
jmp 0x2395f
notq %r9
andq (%rdi,%r10,8), %r9
movq %r9, (%rdi,%r10,8)
addq $0x4, %rax
incl %ecx
cmpq %rdx, %rax
jne 0x2390d
leaq -0x180(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0xc07c
leaq -0x120(%rbp), %r13
testq %rax, %rax
je 0x239a2
leaq 0x8(%r14), %rsi
addq $0x30, %rax
movq %rax, %rdi
callq 0x8528
jmp 0x23a95
leaq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
addq %rsi, %rdx
leaq -0x80(%rbp), %rdi
callq 0x8566
movl $0x1, %edx
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x5c(%rbp), %rcx
callq 0xab26
movq %r13, %rdi
leaq -0x148(%rbp), %rsi
callq 0xad36
movaps -0xa0(%rbp), %xmm0
movups %xmm0, -0xf8(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xe8(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xa0(%rbp)
movq $0x0, -0x90(%rbp)
leaq -0x180(%rbp), %rdi
movq %r13, %rsi
callq 0xc360
leaq -0xf8(%rbp), %rdi
callq 0xab8e
movq -0x120(%rbp), %rdi
testq %rdi, %rdi
je 0x23a70
movq -0x100(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq %r12, -0x120(%rbp)
movl %r12d, -0x118(%rbp)
movq %r12, -0x110(%rbp)
movl %r12d, -0x108(%rbp)
movq %r12, -0x100(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xab8e
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x23a95
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0x148(%rbp), %rdi
testq %rdi, %rdi
je 0x23ab0
movq -0x128(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
incl -0x58(%rbp)
movq (%r14), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc6d8
movq %r13, %r14
jmp 0x237ce
movq 0x1d4f0(%rip), %rdi     # 0x40fc0
movl -0x58(%rbp), %esi
callq 0x5690
movq -0x1d8(%rbp), %r15
movq %rax, %rbx
leaq 0x10c09(%rip), %rsi     # 0x346f2
movl $0x28, %edx
movq %rax, %rdi
callq 0x5420
movq (%r15), %rsi
movq 0x8(%r15), %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, -0x120(%rbp)
movq $0x0, -0x110(%rbp)
movq -0x50(%rbp), %r14
cmpq -0x48(%rbp), %r14
je 0x23b75
leaq -0x120(%rbp), %rbx
movslq (%r14), %rsi
shlq $0x5, %rsi
addq -0x1a0(%rbp), %rsi
movq %rbx, %rdi
callq 0x8528
addq $0x4, %r14
cmpq -0x48(%rbp), %r14
jne 0x23b55
leaq -0x220(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x230(%rbp), %rdi
callq 0x8566
leaq -0x180(%rbp), %rdi
leaq -0x230(%rbp), %rsi
leaq -0x120(%rbp), %rdx
movq -0xc8(%rbp), %rcx
callq 0x9250
movl %eax, %ebx
movq -0x230(%rbp), %rdi
cmpq %r14, %rdi
je 0x23bd4
movq -0x220(%rbp), %rsi
incq %rsi
callq 0x53c0
movl $0x1, %r14d
testl %ebx, %ebx
jne 0x23bed
xorl %r14d, %r14d
movq -0x1d0(%rbp), %rdi
callq 0x8320
leaq -0x120(%rbp), %rdi
callq 0xab8e
leaq -0x180(%rbp), %rdi
callq 0xdd56
jmp 0x23c82
movl $0x1, %r14d
jmp 0x23c82
movq 0x1d3aa(%rip), %rbx     # 0x40fc0
leaq 0xf86e(%rip), %rsi      # 0x3348b
movl $0x24, %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 0x1d378(%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
xorl %r14d, %r14d
leaq -0x4a0(%rbp), %rdi
callq 0x50d0
leaq -0xc0(%rbp), %rdi
callq 0xab8e
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x23caf
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
leaq -0x260(%rbp), %rdi
callq 0xac54
leaq -0x1a0(%rbp), %rdi
callq 0xab8e
leaq -0x298(%rbp), %rdi
callq 0x1b3ac
movl %r14d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0xab6e
jmp 0x23cf9
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0xab8e
jmp 0x23d0a
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x23d51
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x23d51
jmp 0x23d4e
jmp 0x23dc3
movq %rax, %rbx
movq -0x230(%rbp), %rdi
cmpq %r14, %rdi
je 0x23db3
movq -0x220(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x23db3
jmp 0x23db0
movq %rax, %rbx
movq -0x148(%rbp), %rdi
testq %rdi, %rdi
je 0x23dc6
movq -0x128(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
xorl %eax, %eax
movq %rax, -0x148(%rbp)
movl $0x0, -0x140(%rbp)
movq %rax, -0x138(%rbp)
jmp 0x23dc6
movq %rax, %rbx
jmp 0x23e9f
jmp 0x23dc3
jmp 0x23de1
jmp 0x23da2
jmp 0x23dc3
movq %rax, %rbx
jmp 0x23ec0
jmp 0x23de1
movq %rax, %rbx
jmp 0x23ecc
jmp 0x23de1
jmp 0x23de1
jmp 0x23de1
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0xab8e
jmp 0x23dc6
jmp 0x23dd7
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0xdd56
jmp 0x23e93
movq %rax, %rbx
jmp 0x23eab
jmp 0x23de1
movq %rax, %rbx
jmp 0x23e93
jmp 0x23e47
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x1b328
jmp 0x23dff
movq %rax, %rbx
movq -0x148(%rbp), %rdi
testq %rdi, %rdi
je 0x23e21
movq -0x128(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
jmp 0x23e21
jmp 0x23e1e
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x23e4a
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x23e4a
jmp 0x23e47
movq %rax, %rbx
movq -0x180(%rbp), %rdi
testq %rdi, %rdi
je 0x23e7a
movq -0x160(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq $0x0, -0x180(%rbp)
movl $0x0, -0x178(%rbp)
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x23e93
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x53c0
leaq -0x4a0(%rbp), %rdi
callq 0x50d0
leaq -0xc0(%rbp), %rdi
callq 0xab8e
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x23ec0
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x53c0
leaq -0x260(%rbp), %rdi
callq 0xac54
leaq -0x1a0(%rbp), %rdi
callq 0xab8e
leaq -0x298(%rbp), %rdi
callq 0x1b3ac
movq %rbx, %rdi
callq 0x56a0