// File: /workspace/github_cpp_makefile_star2_O3/simonrharris[P]SKA/src/sk_weed.cpp
// Function: weedKmers(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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, float, float, int, int)
int weedKmers(const std::vector < std::string > & weedfiles, const std::string & kmerfile, const float minproportion, const float maxproportion, int minsamples, int maxsamples)
{

	const std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
	// Create the kmer map
	std::set < std::string > kmerSet;
	
	std::ifstream fileStream;

	

	int kmersize=0;
	char base;
	
	

	if (kmerfile!=""){
		if (openFileStream(kmerfile, fileStream)){return 1;};
		std::vector < std::string > weednames;
		
		readKmerHeader(fileStream, kmersize, weednames);
		char kmerbuffer[kmersize*2/3];
		char asciibuffer[int(ceil(float(weednames.size())/6))];
		
		while (fileStream.read(asciibuffer, sizeof(asciibuffer))){
			std::string asciibits (asciibuffer, sizeof(asciibuffer));
			
			while (fileStream.peek()!='\n' && fileStream.get(base)){
				fileStream.read(kmerbuffer, sizeof(kmerbuffer));
				std::string kmer (kmerbuffer, sizeof(kmerbuffer));
				kmerSet.insert(kmer);
			}
			fileStream.ignore(256,'\n');//skip the end ofline character
	    }
		fileStream.close();
		
		std::cout << kmerSet.size() << " unique kmers in weed set" << std::endl;

		
	}


	std:: vector < std::string > sampleNames;
	if (collectSampleNames(weedfiles, sampleNames)!=0){return 1;}

	if (maxsamples==0){
		maxsamples=sampleNames.size();
	}
	else if (maxsamples>sampleNames.size()){
		std::cerr << "Warning: Maxsamples is greater than the number of samples in your files." << std::endl;
	}
	if (minsamples>sampleNames.size()){
		std::cerr << "Error: Minsamples is greater than the number of samples in your files." << std::endl;
		return 1;
	}

	int myminsamples=std::ceil(minproportion*sampleNames.size());
	int mymaxsamples;
	if (maxproportion==1.0){
		mymaxsamples=sampleNames.size();
	}
	else{
		mymaxsamples=std::floor(maxproportion*sampleNames.size());
	}

	if (myminsamples>minsamples){
		minsamples=myminsamples;
	}
	if (mymaxsamples<maxsamples){
		maxsamples=mymaxsamples;
	}

	if (minsamples>0 || maxsamples<sampleNames.size()){
		if (addKmersByFilters (kmerSet, weedfiles, minsamples, maxsamples, kmersize, sampleNames.size())){return 1;};
		std::cout << kmerSet.size() << " unique kmers in weed set" << std::endl;
	}
	
	int weeded=0;
	int totalweedkmers=0;
	
	for (std::vector < std::string >::const_iterator it = weedfiles.begin(); it != weedfiles.end(); ++it){

		if (openFileStream(*it, fileStream)){return 1;};

		int weedkmersize;
		std::vector < std::string > names;
		
		readKmerHeader(fileStream, weedkmersize, names);
		char kmerbuffer[weedkmersize*2/3];
		
		if (weedkmersize!=kmersize){
			std::cerr << "Files have different kmer sizes" << std::endl << std::endl;
			return 1;
		}
		std::string filename=std::string(*it);
		std::string outputfile=filename.substr(0, filename.find_last_of("."))+".weeded"+filename.substr(filename.find_last_of("."), filename.length());

		std::cout << "Writing weeded kmers to " << outputfile << std::endl;
	
		std::ofstream weededfile(outputfile);
		weededfile << "SKA v" << versionNumber << std::endl;
		weededfile << kmersize << std::endl;
		for ( std::vector < std::string >::iterator it=names.begin(); it!=names.end(); ++it){ //print each sample name to output file stream
			weededfile << *it << " "; 
		}
		weededfile << std::endl;

		bool firstkmer=true;

		char asciibuffer[int(ceil(float(names.size())/6))];
		while (fileStream.read(asciibuffer, sizeof(asciibuffer))){
			std::string asciibits (asciibuffer, sizeof(asciibuffer));
			
			while (fileStream.peek()!='\n' && fileStream.get(base)){
				fileStream.read(kmerbuffer, sizeof(kmerbuffer));
				std::string kmer (kmerbuffer, kmersize*2/3);
				
				std::set < std::string >::iterator it2 = kmerSet.find(kmer);//check if the kmer is in the hash
				if ( it2 == kmerSet.end() ){//if the kmer is not in the hash
					if (firstkmer){//if it's the first kmer, print the ascii bitstring
						weededfile << asciibits;
						firstkmer=false;
					}
					weededfile << base << kmer;//print the kmer
					weeded++;
				}
				totalweedkmers++;
			}
			if (firstkmer==false){
				weededfile << std::endl;
			}
			firstkmer=true;
			fileStream.ignore(256,'\n');//skip the end ofline character
    	}
		fileStream.close();
		weededfile.close();
	}
	std::cout << totalweedkmers << " kmers prior to weeding" << std::endl;
	std::cout << weeded << " kmers remaining after weeding" << std::endl;
	std::cout << totalweedkmers-weeded << " kmers weeded (Note this may be more than the number of kmers in the weed set due to mulitple variants of a kmer being in the file)" << std::endl;

	printDuration(start);
	
	return 0;
	
	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x558, %rsp            # imm = 0x558
movl %ecx, %r13d
movl %edx, %r15d
movss %xmm1, -0x100(%rbp)
movss %xmm0, -0x98(%rbp)
movq %rsi, %rbx
movq %rdi, %r12
callq 0x5060
movq %rax, -0x148(%rbp)
leaq -0x170(%rbp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0x580(%rbp), %rdi
callq 0x5410
movl $0x0, -0x30(%rbp)
leaq 0xfabe(%rip), %rsi      # 0x342a2
movq %rbx, %rdi
callq 0x50f0
testl %eax, %eax
je 0x24a8c
leaq -0x580(%rbp), %rsi
movl $0x1, %r14d
movq %rbx, %rdi
movl $0x1, %edx
callq 0x7f3f
testl %eax, %eax
jne 0x25596
movq %r12, -0xf8(%rbp)
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq -0x580(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x9684
movq %rsp, %rcx
movl -0x30(%rbp), %eax
addl %eax, %eax
cltq
imulq $0x55555556, %rax, %rdx # imm = 0x55555556
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x20, %rdx
addl %eax, %edx
movq %rdx, -0x40(%rbp)
leaq 0xf(%rdx), %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq -0x58(%rbp), %rax
subq -0x60(%rbp), %rax
sarq $0x5, %rax
movl %r15d, -0x90(%rbp)
movq %r13, -0xf0(%rbp)
movq %rcx, -0xe8(%rbp)
js 0x2489f
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x248b7
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
divss 0xedc1(%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, -0xa0(%rbp)
movq %rdx, -0x38(%rbp)
leaq (%rdx,%rcx), %rax
movq %rax, -0x108(%rbp)
leaq -0xb0(%rbp), %r15
movq -0x40(%rbp), %rax
leaq (%r12,%rax), %r14
leaq -0x580(%rbp), %r13
leaq -0xc0(%rbp), %rbx
movq %r13, %rdi
movq -0x38(%rbp), %rsi
movq -0xa0(%rbp), %rdx
callq 0x5480
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x24a0a
leaq -0x368(%rbp), %rax
movq %rax, -0x378(%rbp)
leaq -0x378(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x108(%rbp), %rdx
callq 0x85fc
movq %r13, %rdi
callq 0x5140
cmpl $0xa, %eax
je 0x249cd
movq %r13, %rdi
leaq -0x29(%rbp), %rsi
callq 0x5500
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x249cd
movq %r13, %rdi
movq %r12, %rsi
movq -0x40(%rbp), %rdx
callq 0x5480
movq %r15, -0xc0(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x85fc
leaq -0x178(%rbp), %rdi
movq %rbx, %rsi
callq 0xb4a0
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x24956
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x24956
movl $0x100, %esi            # imm = 0x100
movq %r13, %rdi
movl $0xa, %edx
callq 0x5220
movq -0x378(%rbp), %rdi
leaq -0x368(%rbp), %rax
cmpq %rax, %rdi
je 0x2490c
movq -0x368(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x2490c
leaq -0x580(%rbp), %rdi
callq 0x50b0
movl -0x90(%rbp), %r15d
movq -0xf0(%rbp), %r13
movq -0x150(%rbp), %rsi
movq 0x1c58e(%rip), %rdi     # 0x40fc0
callq 0x5240
movq %rax, %rbx
leaq 0xfd5e(%rip), %rsi      # 0x3479f
movl $0x19, %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 -0xe8(%rbp), %rsp
leaq -0x60(%rbp), %rdi
callq 0xab8e
movq -0xf8(%rbp), %r12
xorps %xmm0, %xmm0
leaq -0x140(%rbp), %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movl $0x1, %r14d
movq %r12, %rdi
movl $0x1, %edx
callq 0x9851
testl %eax, %eax
jne 0x2558a
testl %r13d, %r13d
je 0x24b34
movq -0x138(%rbp), %rbx
subq -0x140(%rbp), %rbx
movslq %r13d, %rax
movq %rbx, %rcx
sarq $0x5, %rcx
cmpq %rax, %rcx
jae 0x24b49
movq 0x1c50b(%rip), %rbx     # 0x40ff0
leaq 0xfccd(%rip), %rsi      # 0x347b9
movl $0x48, %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 0x1c4d9(%rip), %rdi     # 0x40ff0
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq -0x138(%rbp), %rbx
subq -0x140(%rbp), %rbx
jmp 0x24b49
movq -0x138(%rbp), %rbx
subq -0x140(%rbp), %rbx
movq %rbx, %r13
shrq $0x5, %r13
movslq %r15d, %rax
sarq $0x5, %rbx
cmpq %rax, %rbx
jae 0x24ba0
movq 0x1c494(%rip), %rbx     # 0x40ff0
leaq 0xfc9f(%rip), %rsi      # 0x34802
movl $0x46, %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 0x1c462(%rip), %rdi     # 0x40ff0
callq 0x5030
movq %rax, %rdi
callq 0x5250
jmp 0x2558a
testq %rbx, %rbx
js 0x24bac
cvtsi2ss %rbx, %xmm1
jmp 0x24bc3
movq %rbx, %rax
shrq %rax
movl %ebx, %ecx
andl $0x1, %ecx
orq %rax, %rcx
cvtsi2ss %rcx, %xmm1
addss %xmm1, %xmm1
movss -0x98(%rbp), %xmm0
movss %xmm1, -0x40(%rbp)
mulss %xmm1, %xmm0
callq 0x51e0
cvttss2si %xmm0, %r14d
movss -0x100(%rbp), %xmm1
ucomiss 0xe417(%rip), %xmm1     # 0x33004
jne 0x24bf5
jp 0x24bf5
movl %ebx, %eax
jmp 0x24c07
movss -0x40(%rbp), %xmm0
mulss %xmm1, %xmm0
callq 0x5150
cvttss2si %xmm0, %eax
cmpl %r15d, %r14d
cmovgl %r14d, %r15d
cmpl %r13d, %eax
cmovll %eax, %r13d
testl %r15d, %r15d
jg 0x24c22
movslq %r13d, %rax
cmpq %rax, %rbx
jbe 0x24c9d
leaq -0x178(%rbp), %rdi
leaq -0x30(%rbp), %r8
movq %r12, %rsi
movl %r15d, %edx
movl %r13d, %ecx
movl %ebx, %r9d
callq 0x240a8
testl %eax, %eax
movl $0x1, %r14d
jne 0x2558a
movq -0x150(%rbp), %rsi
movq 0x1c366(%rip), %rdi     # 0x40fc0
callq 0x5240
movq %rax, %rbx
leaq 0xfb36(%rip), %rsi      # 0x3479f
movl $0x19, %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), %r14
cmpq 0x8(%r12), %r14
je 0x253f0
movq 0x1c2fd(%rip), %rax     # 0x40fb0
movq (%rax), %rcx
movq %rcx, -0xf0(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0xe8(%rbp)
xorl %r15d, %r15d
leaq -0x580(%rbp), %rbx
leaq -0xc0(%rbp), %r13
movl $0x0, -0x38(%rbp)
movq %r12, -0xf8(%rbp)
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x7f3f
testl %eax, %eax
jne 0x254fc
movq %r14, -0x98(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x120(%rbp)
movq $0x0, -0x110(%rbp)
movq %rbx, %rdi
leaq -0x64(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x9684
movq %rsp, -0x90(%rbp)
movl -0x64(%rbp), %eax
addl %eax, %eax
cltq
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
addl %eax, %ecx
movq %rcx, -0x40(%rbp)
leaq 0xf(%rcx), %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movl -0x64(%rbp), %eax
cmpl -0x30(%rbp), %eax
movl $0x1, %r14d
jne 0x25507
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x98(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x8566
movl $0x1, %ecx
movq %r13, %rdi
leaq 0x11649(%rip), %rsi     # 0x363f6
movq $-0x1, %rdx
callq 0x5740
leaq -0xe0(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x53e0
movq %r14, %rdi
leaq 0xfa6f(%rip), %rsi      # 0x34849
callq 0x5710
leaq -0x368(%rbp), %rsi
movq %rsi, -0x378(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x24e0f
movq %rdx, -0x378(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x368(%rbp)
jmp 0x24e15
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x370(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl $0x1, %ecx
movq %r13, %rdi
leaq 0x115b8(%rip), %rsi     # 0x363f6
movq $-0x1, %rdx
callq 0x5740
movq -0xb8(%rbp), %rcx
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x53e0
movq -0x378(%rbp), %rcx
movl $0xf, %edi
leaq -0x368(%rbp), %rax
cmpq %rax, %rcx
leaq -0x378(%rbp), %r14
movq 0x1c139(%rip), %r13     # 0x40fc0
je 0x24e90
movq -0x368(%rbp), %rdi
movq -0x370(%rbp), %r8
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
leaq -0x88(%rbp), %rdi
jbe 0x24eca
movl $0xf, %r10d
leaq -0x78(%rbp), %r9
cmpq %r9, %rsi
je 0x24ec5
movq -0x78(%rbp), %r10
cmpq %r10, %rax
jbe 0x24ed4
movq %r14, %rdi
callq 0x5110
jmp 0x24edd
xorl %esi, %esi
xorl %edx, %edx
callq 0x5400
leaq -0x50(%rbp), %rsi
movq %rsi, -0x60(%rbp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x24efe
movq %rdx, -0x60(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x50(%rbp)
jmp 0x24f04
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, -0x58(%rbp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x24f3c
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0x378(%rbp), %rdi
leaq -0x368(%rbp), %rax
cmpq %rax, %rdi
je 0x24f5e
movq -0x368(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x24f80
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x53c0
movl $0x18, %edx
movq %r13, %rdi
leaq 0xf8c2(%rip), %rsi      # 0x34851
callq 0x5420
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r13, %rdi
callq 0x5420
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %r13, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
movl $0x10, %edx
callq 0x5720
movl $0x5, %edx
movq %r14, %rdi
leaq 0xed7c(%rip), %rsi      # 0x33d6a
callq 0x5420
leaq 0x1c516(%rip), %rax     # 0x41510
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r14, %rdi
callq 0x5420
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %r13, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
movl -0x30(%rbp), %esi
movq %r14, %rdi
callq 0x5690
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq -0x120(%rbp), %r13
cmpq -0x118(%rbp), %r13
leaq 0xf30b(%rip), %r14      # 0x34388
je 0x250b0
movq (%r13), %rsi
movq 0x8(%r13), %rdx
leaq -0x378(%rbp), %rdi
callq 0x5420
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x5420
addq $0x20, %r13
cmpq -0x118(%rbp), %r13
jne 0x2507f
movq -0x378(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x378(%rbp), %r14
addq %r14, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq -0x118(%rbp), %rax
subq -0x120(%rbp), %rax
sarq $0x5, %rax
js 0x250fd
cvtsi2ss %rax, %xmm0
jmp 0x25112
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
leaq -0xc0(%rbp), %r13
divss 0xe55f(%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, -0x108(%rbp)
movq %rdx, -0xa0(%rbp)
leaq (%rdx,%rcx), %rax
movq %rax, -0x100(%rbp)
movq %rbx, %rdi
movq -0xa0(%rbp), %rsi
movq -0x108(%rbp), %rdx
callq 0x5480
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x25336
leaq -0xd0(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xe0(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x100(%rbp), %rdx
callq 0x85fc
movb $0x1, %r13b
movq %rbx, %rdi
callq 0x5140
cmpl $0xa, %eax
je 0x252b6
movq %rbx, %rdi
leaq -0x29(%rbp), %rsi
callq 0x5500
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x252b6
movq %rbx, %rdi
movq %r12, %rsi
movq -0x40(%rbp), %rdx
callq 0x5480
movl -0x30(%rbp), %eax
addl %eax, %eax
cltq
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
movslq %eax, %rdx
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
addq %r12, %rdx
leaq -0x88(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x85fc
leaq -0x178(%rbp), %rdi
movq %r14, %rsi
callq 0xb648
leaq -0x170(%rbp), %rcx
cmpq %rcx, %rax
jne 0x25292
testb $0x1, %r13b
je 0x25261
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
leaq -0x378(%rbp), %rdi
callq 0x5420
xorl %r13d, %r13d
movb -0x29(%rbp), %al
movb %al, -0x2a(%rbp)
movl $0x1, %edx
leaq -0x378(%rbp), %rdi
leaq -0x2a(%rbp), %rsi
callq 0x5420
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq %rax, %rdi
callq 0x5420
incl -0x38(%rbp)
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x252ae
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x53c0
incl %r15d
jmp 0x251a7
testb $0x1, %r13b
jne 0x252f2
movq -0x378(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x378(%rbp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
leaq -0x378(%rbp), %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
movl $0xa, %edx
callq 0x5220
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
leaq -0xc0(%rbp), %r13
je 0x25154
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x25154
movq %rbx, %rdi
callq 0x50b0
leaq -0x378(%rbp), %rdi
callq 0x5530
movq -0xf0(%rbp), %rax
movq %rax, -0x378(%rbp)
movq -0x18(%rax), %rax
movq -0xe8(%rbp), %rcx
movq %rcx, -0x378(%rbp,%rax)
leaq -0x370(%rbp), %rdi
callq 0x5330
leaq -0x280(%rbp), %rdi
callq 0x5120
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
movq -0xf8(%rbp), %r12
movq -0x98(%rbp), %r14
je 0x253aa
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x253cc
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0x90(%rbp), %rsp
leaq -0x120(%rbp), %rdi
callq 0xab8e
addq $0x20, %r14
cmpq 0x8(%r12), %r14
jne 0x24ce7
jmp 0x253fa
movl $0x0, -0x38(%rbp)
xorl %r15d, %r15d
movq 0x1bbbf(%rip), %rdi     # 0x40fc0
movl %r15d, %esi
callq 0x5690
movl -0x38(%rbp), %r14d
movq %rax, %rbx
leaq 0xf453(%rip), %rsi      # 0x3486a
movl $0x17, %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 0x1bb6e(%rip), %rdi     # 0x40fc0
movl %r14d, %esi
callq 0x5690
movq %rax, %rbx
leaq 0xf41e(%rip), %rsi      # 0x34882
movl $0x1e, %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
subl %r14d, %r15d
movq 0x1bb1e(%rip), %rdi     # 0x40fc0
movl %r15d, %esi
callq 0x5690
movq %rax, %rbx
leaq 0xf3ed(%rip), %rsi      # 0x348a1
movl $0x83, %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
xorl %r14d, %r14d
movq -0x148(%rbp), %rdi
callq 0x8320
jmp 0x2558a
movl $0x1, %r14d
jmp 0x2558a
movq 0x1bae2(%rip), %rbx     # 0x40ff0
leaq 0xf26a(%rip), %rsi      # 0x3477f
movl $0x1f, %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 0x1bab0(%rip), %rdi     # 0x40ff0
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
movq -0x90(%rbp), %rsp
leaq -0x120(%rbp), %rdi
callq 0xab8e
leaq -0x140(%rbp), %rdi
callq 0xab8e
leaq -0x580(%rbp), %rdi
callq 0x50d0
leaq -0x178(%rbp), %rdi
callq 0xac54
movl %r14d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25641
jmp 0x2565f
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x255f8
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x255f8
movq %rax, %rbx
jmp 0x25747
movq %rax, %rbx
jmp 0x2561a
movq %rax, %rbx
movq -0x378(%rbp), %rdi
leaq -0x368(%rbp), %rax
cmpq %rax, %rdi
je 0x2561a
movq -0x368(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x25747
movq -0xd0(%rbp), %rsi
jmp 0x2573f
jmp 0x25641
jmp 0x25669
movq %rax, %rbx
jmp 0x25769
jmp 0x2565f
movq %rax, %rbx
jmp 0x25781
jmp 0x2565f
jmp 0x25680
movq %rax, %rbx
jmp 0x2578d
movq %rax, %rbx
jmp 0x25775
jmp 0x25677
movq %rax, %rbx
jmp 0x2572e
jmp 0x25680
jmp 0x256ae
jmp 0x25677
movq %rax, %rbx
jmp 0x256d3
jmp 0x25680
jmp 0x25680
movq %rax, %rbx
jmp 0x25722
jmp 0x256fd
jmp 0x256ae
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x256b1
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x256b1
jmp 0x256fd
movq %rax, %rbx
movq -0x378(%rbp), %rdi
leaq -0x368(%rbp), %rax
cmpq %rax, %rdi
je 0x256d3
movq -0x368(%rbp), %rsi
incq %rsi
callq 0x53c0
leaq -0x60(%rbp), %rdi
jmp 0x2577c
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x25700
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x53c0
jmp 0x25700
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x25722
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x53c0
leaq -0x378(%rbp), %rdi
callq 0x55a0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x25747
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x53c0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x25769
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x53c0
leaq -0x120(%rbp), %rdi
callq 0xab8e
leaq -0x140(%rbp), %rdi
callq 0xab8e
leaq -0x580(%rbp), %rdi
callq 0x50d0
leaq -0x178(%rbp), %rdi
callq 0xac54
movq %rbx, %rdi
callq 0x56a0
nop