// File: simonrharris[P]SKA/src/sk_merge.cpp
// Function: mergeKmerFiles(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&, 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&)
int mergeKmerFiles(const std::string & outfile, const std::vector < std::string > & kmerfiles, const std::vector < std::string > & sample)
{

	const std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();//start the clock

	int numfiles=kmerfiles.size();
	
	// Create the kmer map
	std::unordered_map < std::string, std::vector < bool > > kmerMap;
	
	std::vector< int > kmerCounts;
	int kmersize=0;
	std::vector < std::string > sampleNames;

	if (collectSampleNames(kmerfiles, sampleNames)!=0){return 1;}

	std::vector < bool > include (sampleNames.size());
	getSubsample(sample, sampleNames, include);//get a vector of bools representing which samples to include based on a provided sample file. This also removed duplicate samples in the input files

	std::vector < std::string > includedSampleNames;
	for (std::vector < bool >::iterator it=include.begin(); it!=include.end(); ++it){//make a vector of all included sample names to help printing output files later
		if (*it){
			includedSampleNames.push_back(sampleNames[distance(include.begin(), it)]);
		}
	}

	//int numSamples=sampleNames.size();
	int numSamples = std::count(include.begin(), include.end(), true);

	std::vector < std::string > fileSampleNames;

	int sampleNum=0;
	int includedSampleNum=0;
	std::ifstream fileStream;

	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;
		}

		std::vector < int > fileInclude;

		for (int i=0; i<fileSampleNames.size(); ++i){ //put the index of all sample names that are to be included into a vector
			if (include[sampleNum+i]){
				fileInclude.push_back(i);
			}
		}
		if (fileInclude.size()==0){ // if no sample names in the file are going to be included then don't read the file
			fileStream.close();
			sampleNum+=int(fileSampleNames.size());
			fileSampleNames.clear();
			continue;
		}

		//int numFileSamples=fileSampleNames.size();
		int numFileSamples = fileInclude.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

			int mybitcount=0;
			for (int i=0; i< fileInclude.size(); ++i){
				if (mybits[fileInclude[i]]){
					mybitcount++;
				}
			}

			if (mybitcount==0){
				std::string line;
				std::getline(fileStream, line);
				continue;
			}

			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<fileInclude.size(); ++i){
						it->second[i+includedSampleNum]=mybits[fileInclude[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<fileInclude.size(); ++i){ //change the bools to true based for taxa in the file containing the kmer
						taxonBitset[i+includedSampleNum]=mybits[fileInclude[i]];
					}
					kmerMap.insert(std::make_pair(kmer, taxonBitset));//add the new vector to the map
				}
	    	}
	    	fileStream.ignore(256,'\n');//skip the end of line character
    	}
    	sampleNum+=numFileSamples; //add the number of samples in the file to the count of total samples
    	includedSampleNum+=fileInclude.size();
    	fileSampleNames.clear();
		fileStream.close();
	}

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

	std::unordered_map < std::vector < bool >,  std::vector < std::string > > revKmerMap;

	reverseVectorBoolKmerMap(kmerMap, revKmerMap);//reverse the map so that we have a new map of kmers for each combination of samples

	std::cout << revKmerMap.size() << " unique taxon combinations in map" << std::endl;
	
	if(printMergedKmerFile(revKmerMap, outfile, includedSampleNames, kmersize)){return 1;}
	
	printDuration(start);//stop the clock
	
	return 0;
		
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x830, %rsp            # imm = 0x830
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
callq 0x6080
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0xb670
movl %eax, -0x2c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x35160
leaq -0x80(%rbp), %rdi
callq 0x1ac10
movl $0x0, -0x84(%rbp)
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x650(%rbp)
callq 0x1ab40
movq -0x650(%rbp), %rsi
movq -0x18(%rbp), %rdi
movl $0x1, %edx
callq 0xced0
movl %eax, -0x644(%rbp)
jmp 0x33f68
movl -0x644(%rbp), %eax
cmpl $0x0, %eax
je 0x33fa0
movl $0x1, -0x4(%rbp)
movl $0x1, -0xb0(%rbp)
jmp 0x35106
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x3512c
leaq -0xa0(%rbp), %rdi
callq 0xb670
movq %rax, -0x660(%rbp)
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x658(%rbp)
callq 0xf380
movq -0x660(%rbp), %rsi
movq -0x658(%rbp), %rdx
leaq -0xd8(%rbp), %rdi
callq 0xf3a0
jmp 0x33fe2
leaq -0xd9(%rbp), %rdi
callq 0xf3e0
movq -0x20(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0xd240
jmp 0x34007
leaq -0xf8(%rbp), %rdi
callq 0x1ab40
leaq -0xd8(%rbp), %rdi
callq 0xf580
movl %edx, -0x110(%rbp)
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x108(%rbp)
movl -0x110(%rbp), %eax
movl %eax, -0x100(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xf5c0
movl %edx, -0x130(%rbp)
movq %rax, -0x138(%rbp)
movl -0x130(%rbp), %eax
movl %eax, -0x120(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0xf1c0
movb %al, -0x661(%rbp)
jmp 0x34094
movb -0x661(%rbp), %al
testb $0x1, %al
jne 0x340a3
jmp 0x341e5
leaq -0x108(%rbp), %rdi
callq 0xf5e0
movq %rdx, -0x678(%rbp)
movq %rax, -0x670(%rbp)
jmp 0x340bf
movq -0x678(%rbp), %rax
movq -0x670(%rbp), %rcx
movq %rcx, -0x148(%rbp)
movq %rax, -0x140(%rbp)
leaq -0x148(%rbp), %rdi
callq 0xf510
testb $0x1, %al
jne 0x340f0
jmp 0x341d0
leaq -0xd8(%rbp), %rdi
callq 0xf580
movl %edx, -0x160(%rbp)
movq %rax, -0x168(%rbp)
movl -0x160(%rbp), %eax
movl %eax, -0x150(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x158(%rbp)
movups -0x108(%rbp), %xmm0
movaps %xmm0, -0x180(%rbp)
movq -0x158(%rbp), %rdi
movl -0x150(%rbp), %esi
movq -0x180(%rbp), %rdx
movl -0x178(%rbp), %ecx
callq 0xf670
movq %rax, -0x680(%rbp)
jmp 0x34159
movq -0x680(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x1ab60
movq %rax, %rsi
leaq -0xf8(%rbp), %rdi
callq 0xabd0
jmp 0x3417d
jmp 0x341d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xd9(%rbp), %rdi
callq 0xf3e0
jmp 0x3512c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x350f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x350ec
jmp 0x341d2
leaq -0x108(%rbp), %rdi
callq 0xf6f0
jmp 0x341e0
jmp 0x34046
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x690(%rbp)
callq 0xf580
movq -0x690(%rbp), %rdi
movl %edx, -0x1a0(%rbp)
movq %rax, -0x1a8(%rbp)
movl -0x1a0(%rbp), %eax
movl %eax, -0x190(%rbp)
movq -0x1a8(%rbp), %rax
movq %rax, -0x198(%rbp)
callq 0xf5c0
movl %edx, -0x1c0(%rbp)
movq %rax, -0x1c8(%rbp)
movl -0x1c0(%rbp), %eax
movl %eax, -0x1b0(%rbp)
movq -0x1c8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movb $0x1, -0x1c9(%rbp)
movq -0x198(%rbp), %rdi
movl -0x190(%rbp), %esi
movq -0x1b8(%rbp), %rdx
movl -0x1b0(%rbp), %ecx
leaq -0x1c9(%rbp), %r8
callq 0x1ab80
movq %rax, -0x688(%rbp)
jmp 0x34288
movq -0x688(%rbp), %rax
movl %eax, -0x184(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x1ab40
movl $0x0, -0x1ec(%rbp)
movl $0x0, -0x1f0(%rbp)
leaq -0x3f8(%rbp), %rdi
callq 0x65f0
jmp 0x342c3
movl $0x0, -0x3fc(%rbp)
movslq -0x3fc(%rbp), %rax
movq %rax, -0x698(%rbp)
movq -0x18(%rbp), %rdi
callq 0xb670
movq %rax, %rcx
movq -0x698(%rbp), %rax
cmpq %rcx, %rax
jae 0x34e5c
movq -0x18(%rbp), %rdi
movslq -0x3fc(%rbp), %rsi
callq 0xf2d0
movq %rax, %rdi
leaq -0x3f8(%rbp), %rsi
movl $0x1, %edx
callq 0xa4f0
movl %eax, -0x69c(%rbp)
jmp 0x34323
movl -0x69c(%rbp), %eax
cmpl $0x0, %eax
je 0x34372
movl $0x1, -0x4(%rbp)
movl $0x1, -0xb0(%rbp)
jmp 0x350a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x350e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x350d4
leaq -0x3f8(%rbp), %rdi
leaq -0x400(%rbp), %rsi
leaq -0x1e8(%rbp), %rdx
callq 0xcd40
jmp 0x3438e
cmpl $0x0, -0x3fc(%rbp)
jne 0x343a3
movl -0x400(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x400(%rbp), %eax
cmpl -0x84(%rbp), %eax
je 0x34414
movq 0x44bf0(%rip), %rdi     # 0x78fa8
leaq 0x250cc(%rip), %rsi     # 0x5948b
callq 0x6520
movq %rax, -0x6a8(%rbp)
jmp 0x343cd
movq -0x6a8(%rbp), %rdi
movq 0x44bb5(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x6b0(%rbp)
jmp 0x343e9
movq -0x6b0(%rbp), %rdi
movq 0x44b99(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x343fe
movl $0x0, -0x4(%rbp)
movl $0x1, -0xb0(%rbp)
jmp 0x350a2
leaq -0x418(%rbp), %rdi
callq 0x1ac10
movl $0x0, -0x41c(%rbp)
movslq -0x41c(%rbp), %rax
movq %rax, -0x6b8(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0xb670
movq %rax, %rcx
movq -0x6b8(%rbp), %rax
cmpq %rcx, %rax
jae 0x344f6
movl -0x1ec(%rbp), %eax
movl -0x41c(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0xedc0
movq %rdx, -0x6c8(%rbp)
movq %rax, -0x6c0(%rbp)
jmp 0x34484
movq -0x6c8(%rbp), %rax
movq -0x6c0(%rbp), %rcx
movq %rcx, -0x430(%rbp)
movq %rax, -0x428(%rbp)
leaq -0x430(%rbp), %rdi
callq 0xf510
testb $0x1, %al
jne 0x344b2
jmp 0x344e0
leaq -0x418(%rbp), %rdi
leaq -0x41c(%rbp), %rsi
callq 0x1ac30
jmp 0x344c7
jmp 0x344e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x34e4b
jmp 0x344e2
movl -0x41c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x41c(%rbp)
jmp 0x3442a
leaq -0x418(%rbp), %rdi
callq 0xf7f0
cmpq $0x0, %rax
jne 0x34549
leaq -0x3f8(%rbp), %rdi
callq 0x60f0
jmp 0x34516
leaq -0x1e8(%rbp), %rdi
callq 0xb670
addl -0x1ec(%rbp), %eax
movl %eax, -0x1ec(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x1aca0
movl $0x7, -0xb0(%rbp)
jmp 0x34e1b
leaq -0x418(%rbp), %rdi
callq 0xf7f0
movl %eax, -0x434(%rbp)
movl -0x84(%rbp), %eax
addl %eax, %eax
cltq
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x20, %rcx
movl %ecx, %edx
shrq $0x3f, %rax
movl %eax, %ecx
movl %edx, %eax
leal 0x1(%rax,%rcx), %eax
movq %rax, -0x6e0(%rbp)
movq %rsp, %rcx
movq %rcx, -0x440(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x6d8(%rbp)
movq %rcx, %rsp
movq %rax, -0x448(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0xb670
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x6d0(%rbp)
testq %rax, %rax
movss %xmm0, -0x6cc(%rbp)
js 0x34601
movss -0x6d0(%rbp), %xmm0
movss %xmm0, -0x6cc(%rbp)
movss -0x6cc(%rbp), %xmm0
movss 0x2506b(%rip), %xmm1    # 0x5967c
divss %xmm1, %xmm0
callq 0x33ed0
movss %xmm0, -0x6e4(%rbp)
jmp 0x34624
movss -0x6e4(%rbp), %xmm0
cvttss2si %xmm0, %eax
movq %rax, -0x6f8(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x6f0(%rbp)
movq %rcx, %rsp
movq %rax, -0x450(%rbp)
movq -0x6f8(%rbp), %rdx
movq -0x6f0(%rbp), %rsi
leaq -0x3f8(%rbp), %rdi
callq 0x6680
movq %rax, -0x700(%rbp)
jmp 0x3467c
movq -0x700(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x6670
movb %al, -0x701(%rbp)
jmp 0x3469a
movb -0x701(%rbp), %al
testb $0x1, %al
jne 0x346a9
jmp 0x34dbc
leaq -0x471(%rbp), %rdi
movq %rdi, -0x710(%rbp)
callq 0x6910
movq -0x6f0(%rbp), %rsi
movq -0x6f8(%rbp), %rdx
movq -0x710(%rbp), %rcx
leaq -0x470(%rbp), %rdi
callq 0x65e0
jmp 0x346df
leaq -0x471(%rbp), %rdi
callq 0x65a0
leaq -0x4a0(%rbp), %rdi
movq %rdi, -0x718(%rbp)
callq 0x1acc0
movq -0x718(%rbp), %rsi
leaq -0x470(%rbp), %rdi
callq 0xbd50
jmp 0x34713
movl $0x0, -0x4a4(%rbp)
movl $0x0, -0x4a8(%rbp)
movslq -0x4a8(%rbp), %rax
movq %rax, -0x720(%rbp)
leaq -0x418(%rbp), %rdi
callq 0xf7f0
movq %rax, %rcx
movq -0x720(%rbp), %rax
cmpq %rcx, %rax
jae 0x34815
movslq -0x4a8(%rbp), %rsi
leaq -0x418(%rbp), %rdi
callq 0x1a9b0
movslq (%rax), %rsi
leaq -0x4a0(%rbp), %rdi
callq 0xedc0
movq %rdx, -0x730(%rbp)
movq %rax, -0x728(%rbp)
jmp 0x34786
movq -0x730(%rbp), %rax
movq -0x728(%rbp), %rcx
movq %rcx, -0x4b8(%rbp)
movq %rax, -0x4b0(%rbp)
leaq -0x4b8(%rbp), %rdi
callq 0xf510
testb $0x1, %al
jne 0x347b4
jmp 0x347ff
movl -0x4a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4a4(%rbp)
jmp 0x347ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x471(%rbp), %rdi
callq 0x65a0
jmp 0x34e4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x34d9f
jmp 0x34801
movl -0x4a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4a8(%rbp)
jmp 0x34727
cmpl $0x0, -0x4a4(%rbp)
jne 0x34884
leaq -0x4d8(%rbp), %rdi
movq %rdi, -0x738(%rbp)
callq 0x6730
movq -0x738(%rbp), %rsi
leaq -0x3f8(%rbp), %rdi
callq 0x60d0
jmp 0x34846
movl $0xb, -0xb0(%rbp)
leaq -0x4d8(%rbp), %rdi
callq 0x6a08
jmp 0x34d71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x4d8(%rbp), %rdi
callq 0x6a08
jmp 0x34d9f
jmp 0x34886
leaq -0x3f8(%rbp), %rdi
callq 0x61c0
movl %eax, -0x73c(%rbp)
jmp 0x3489a
movl -0x73c(%rbp), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x73d(%rbp)
je 0x348fc
movq -0x6e0(%rbp), %rdx
movq -0x6d8(%rbp), %rsi
leaq -0x3f8(%rbp), %rdi
callq 0x6680
movq %rax, -0x748(%rbp)
jmp 0x348d0
movq -0x748(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x6670
movb %al, -0x749(%rbp)
jmp 0x348ee
movb -0x749(%rbp), %al
movb %al, -0x73d(%rbp)
jmp 0x348fc
movb -0x73d(%rbp), %al
testb $0x1, %al
jne 0x3490b
jmp 0x34d4f
movl -0x84(%rbp), %eax
addl %eax, %eax
cltq
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x20, %rcx
movl %ecx, %edx
shrq $0x3f, %rax
movl %eax, %ecx
movl %edx, %eax
leal 0x1(%rax,%rcx), %eax
cltq
movq %rax, -0x760(%rbp)
leaq -0x4f9(%rbp), %rdi
movq %rdi, -0x758(%rbp)
callq 0x6910
movq -0x6d8(%rbp), %rsi
movq -0x760(%rbp), %rdx
movq -0x758(%rbp), %rcx
leaq -0x4f8(%rbp), %rdi
callq 0x65e0
jmp 0x34970
leaq -0x4f9(%rbp), %rdi
callq 0x65a0
leaq -0x68(%rbp), %rdi
leaq -0x4f8(%rbp), %rsi
callq 0x35180
movq %rax, -0x768(%rbp)
jmp 0x34995
movq -0x768(%rbp), %rax
movq %rax, -0x508(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xfc20
movq %rax, -0x510(%rbp)
leaq -0x508(%rbp), %rdi
leaq -0x510(%rbp), %rsi
callq 0xfc50
testb $0x1, %al
jne 0x349cf
jmp 0x34b0f
movl $0x0, -0x514(%rbp)
movslq -0x514(%rbp), %rax
movq %rax, -0x770(%rbp)
leaq -0x418(%rbp), %rdi
callq 0xf7f0
movq %rax, %rcx
movq -0x770(%rbp), %rax
cmpq %rcx, %rax
jae 0x34b0a
movslq -0x514(%rbp), %rsi
leaq -0x418(%rbp), %rdi
callq 0x1a9b0
movslq (%rax), %rsi
leaq -0x4a0(%rbp), %rdi
callq 0xedc0
movq %rdx, -0x780(%rbp)
movq %rax, -0x778(%rbp)
jmp 0x34a38
movq -0x780(%rbp), %rax
movq -0x778(%rbp), %rcx
movq %rcx, -0x528(%rbp)
movq %rax, -0x520(%rbp)
leaq -0x508(%rbp), %rdi
callq 0xfcb0
movq %rax, %rdi
addq $0x20, %rdi
movl -0x514(%rbp), %eax
movl -0x1f0(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0xedc0
movq %rdx, -0x790(%rbp)
movq %rax, -0x788(%rbp)
jmp 0x34a8d
movq -0x790(%rbp), %rax
movq -0x788(%rbp), %rcx
movq %rcx, -0x538(%rbp)
movq %rax, -0x530(%rbp)
leaq -0x538(%rbp), %rdi
leaq -0x528(%rbp), %rsi
callq 0x12720
movl -0x514(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x514(%rbp)
jmp 0x349d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x4f9(%rbp), %rdi
callq 0x65a0
jmp 0x34d9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x34d41
jmp 0x34d30
movslq -0x184(%rbp), %rax
movq %rax, -0x7a0(%rbp)
movb $0x0, -0x561(%rbp)
leaq -0x562(%rbp), %rdi
movq %rdi, -0x798(%rbp)
callq 0xf380
movq -0x7a0(%rbp), %rsi
movq -0x798(%rbp), %rcx
leaq -0x560(%rbp), %rdi
leaq -0x561(%rbp), %rdx
callq 0xffb0
jmp 0x34b5a
leaq -0x562(%rbp), %rdi
callq 0xf3e0
movl $0x0, -0x568(%rbp)
movslq -0x568(%rbp), %rax
movq %rax, -0x7a8(%rbp)
leaq -0x418(%rbp), %rdi
callq 0xf7f0
movq %rax, %rcx
movq -0x7a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x34c95
movslq -0x568(%rbp), %rsi
leaq -0x418(%rbp), %rdi
callq 0x1a9b0
movslq (%rax), %rsi
leaq -0x4a0(%rbp), %rdi
callq 0xedc0
movq %rdx, -0x7b8(%rbp)
movq %rax, -0x7b0(%rbp)
jmp 0x34bcf
movq -0x7b8(%rbp), %rax
movq -0x7b0(%rbp), %rcx
movq %rcx, -0x578(%rbp)
movq %rax, -0x570(%rbp)
movl -0x568(%rbp), %eax
movl -0x1f0(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq -0x560(%rbp), %rdi
callq 0xedc0
movq %rdx, -0x7c8(%rbp)
movq %rax, -0x7c0(%rbp)
jmp 0x34c18
movq -0x7c8(%rbp), %rax
movq -0x7c0(%rbp), %rcx
movq %rcx, -0x588(%rbp)
movq %rax, -0x580(%rbp)
leaq -0x588(%rbp), %rdi
leaq -0x578(%rbp), %rsi
callq 0x12720
movl -0x568(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x568(%rbp)
jmp 0x34b70
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x562(%rbp), %rdi
callq 0xf3e0
jmp 0x34d41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x34d22
leaq -0x5d0(%rbp), %rdi
leaq -0x4f8(%rbp), %rsi
leaq -0x560(%rbp), %rdx
callq 0x351f0
jmp 0x34cb1
leaq -0x68(%rbp), %rdi
leaq -0x5d0(%rbp), %rsi
callq 0x351b0
movb %dl, -0x7d1(%rbp)
movq %rax, -0x7d0(%rbp)
jmp 0x34cd0
movb -0x7d1(%rbp), %al
movq -0x7d0(%rbp), %rcx
movq %rcx, -0x5e0(%rbp)
movb %al, -0x5d8(%rbp)
leaq -0x5d0(%rbp), %rdi
callq 0x35230
leaq -0x560(%rbp), %rdi
callq 0xf720
jmp 0x34d30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x5d0(%rbp), %rdi
callq 0x35230
leaq -0x560(%rbp), %rdi
callq 0xf720
jmp 0x34d41
leaq -0x4f8(%rbp), %rdi
callq 0x6a08
jmp 0x34886
leaq -0x4f8(%rbp), %rdi
callq 0x6a08
jmp 0x34d9f
leaq -0x3f8(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0xa, %edx
callq 0x6340
jmp 0x34d67
movl $0x0, -0xb0(%rbp)
leaq -0x4a0(%rbp), %rdi
callq 0xf720
leaq -0x470(%rbp), %rdi
callq 0x6a08
movl -0xb0(%rbp), %eax
testl %eax, %eax
je 0x34d9a
jmp 0x34d95
jmp 0x34659
jmp 0x34659
leaq -0x4a0(%rbp), %rdi
callq 0xf720
leaq -0x470(%rbp), %rdi
callq 0x6a08
jmp 0x34e4b
movl -0x434(%rbp), %ecx
movl -0x1ec(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x1ec(%rbp)
leaq -0x418(%rbp), %rdi
callq 0xf7f0
movq %rax, %rcx
movl -0x1f0(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x1f0(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x1aca0
leaq -0x3f8(%rbp), %rdi
callq 0x60f0
jmp 0x34e07
movq -0x440(%rbp), %rax
movq %rax, %rsp
movl $0x0, -0xb0(%rbp)
leaq -0x418(%rbp), %rdi
callq 0x1aa00
movl -0xb0(%rbp), %eax
testl %eax, %eax
je 0x34e35
jmp 0x34e33
jmp 0x34e37
jmp 0x34e37
movl -0x3fc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3fc(%rbp)
jmp 0x342cd
leaq -0x418(%rbp), %rdi
callq 0x1aa00
jmp 0x350d4
leaq -0x68(%rbp), %rdi
callq 0x35260
movq %rax, %rsi
movq 0x44139(%rip), %rdi     # 0x78fa8
callq 0x6120
movq %rax, -0x7e0(%rbp)
jmp 0x34e7d
movq -0x7e0(%rbp), %rdi
leaq 0x248e2(%rip), %rsi     # 0x5976d
callq 0x6520
movq %rax, -0x7e8(%rbp)
jmp 0x34e99
movq -0x7e8(%rbp), %rdi
movl -0x1f0(%rbp), %esi
callq 0x68d0
movq %rax, -0x7f0(%rbp)
jmp 0x34eb4
movq -0x7f0(%rbp), %rdi
leaq 0x245ee(%rip), %rsi     # 0x594b0
callq 0x6520
movq %rax, -0x7f8(%rbp)
jmp 0x34ed0
movq -0x7f8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x68d0
movq %rax, -0x800(%rbp)
jmp 0x34ee8
movq -0x800(%rbp), %rdi
leaq 0x25bc3(%rip), %rsi     # 0x5aab9
callq 0x6520
movq %rax, -0x808(%rbp)
jmp 0x34f04
movq -0x808(%rbp), %rdi
movq 0x4407e(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x34f19
movq 0x44088(%rip), %rdi     # 0x78fa8
leaq 0x25456(%rip), %rsi     # 0x5a37d
callq 0x6520
movq %rax, -0x810(%rbp)
jmp 0x34f35
movq -0x810(%rbp), %rdi
movq 0x4404d(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x34f4a
leaq -0x618(%rbp), %rdi
movq %rdi, -0x818(%rbp)
callq 0x1ae50
movq -0x818(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0xe350
jmp 0x34f6f
leaq -0x618(%rbp), %rdi
callq 0x1ae70
movq %rax, %rsi
movq 0x44023(%rip), %rdi     # 0x78fa8
callq 0x6120
movq %rax, -0x820(%rbp)
jmp 0x34f93
movq -0x820(%rbp), %rdi
leaq 0x24806(%rip), %rsi     # 0x597a7
callq 0x6520
movq %rax, -0x828(%rbp)
jmp 0x34faf
movq -0x828(%rbp), %rdi
movq 0x43fd3(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x34fc4
movq -0x10(%rbp), %rsi
leaq -0x638(%rbp), %rdi
callq 0x6230
jmp 0x34fd6
movl -0x84(%rbp), %ecx
leaq -0x618(%rbp), %rdi
leaq -0x638(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0xc810
movl %eax, -0x82c(%rbp)
jmp 0x34ffe
leaq -0x638(%rbp), %rdi
callq 0x6a08
movl -0x82c(%rbp), %eax
cmpl $0x0, %eax
je 0x3505c
movl $0x1, -0x4(%rbp)
movl $0x1, -0xb0(%rbp)
jmp 0x35086
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x35094
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x638(%rbp), %rdi
callq 0x6a08
jmp 0x35094
movq -0x28(%rbp), %rax
movq %rax, -0x640(%rbp)
movq -0x640(%rbp), %rdi
callq 0xa8f0
jmp 0x35075
movl $0x0, -0x4(%rbp)
movl $0x1, -0xb0(%rbp)
leaq -0x618(%rbp), %rdi
callq 0x1ae90
jmp 0x350a2
leaq -0x618(%rbp), %rdi
callq 0x1ae90
jmp 0x350d4
leaq -0x3f8(%rbp), %rdi
callq 0x6140
leaq -0x1e8(%rbp), %rdi
callq 0xfe90
leaq -0xf8(%rbp), %rdi
callq 0xfe90
leaq -0xd8(%rbp), %rdi
callq 0xf720
jmp 0x35106
leaq -0x3f8(%rbp), %rdi
callq 0x6140
leaq -0x1e8(%rbp), %rdi
callq 0xfe90
leaq -0xf8(%rbp), %rdi
callq 0xfe90
leaq -0xd8(%rbp), %rdi
callq 0xf720
jmp 0x3512c
leaq -0xa0(%rbp), %rdi
callq 0xfe90
leaq -0x80(%rbp), %rdi
callq 0x1aa00
leaq -0x68(%rbp), %rdi
callq 0x35280
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
leaq -0xa0(%rbp), %rdi
callq 0xfe90
leaq -0x80(%rbp), %rdi
callq 0x1aa00
leaq -0x68(%rbp), %rdi
callq 0x35280
movq -0xa8(%rbp), %rdi
callq 0x6900
nopw %cs:(%rax,%rax)