// File: giovannarosone[P]BCR_LCP_GSA/TransposeFasta.cpp
// Function: TransposeFasta::convertQS(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&, unsigned long)
bool TransposeFasta::convertQS( const string& input, const string& output, dataTypeNChar ram )
{
	FILE* ifile;
	cerr << "\nTrasposeFasta convertQS: file " << input << " !" << endl;
	
	ifile = fopen(input.c_str(), "rb");

    if( ifile == NULL ) { 
		cerr << "TrasposeFasta convertQS: could not open file " << input << " !" << endl; 
	}


	vector <FILE*> outputFiles_;
	outputFiles_.resize(lengthRead);    //One for each symbol of the read.
    // create output files   (cyc qs files)
    for(dataTypelenSeq i=0;i<lengthRead;i++ )
    {
        std::stringstream fn;
        fn << output << "qs." << (int)i << ".txt";
        outputFiles_[i] = fopen( fn.str().c_str(),"w" );
        if (outputFiles_[i] == NULL) {
                std::cerr << "TrasposeFasta: could not open file "  <<  fn.str().c_str() << std::endl;
				exit (EXIT_FAILURE);
		}
        fclose(outputFiles_[i]);
    }

	//TO DO: CHECK THE CASE OF charsBuffered >= SIZEBUFFERcycFiles
	//if (nSeq > SIZEBUFFERcycFiles) {
	//	cerr << "Warning: Number of sequences is: " << (unsigned long)nSeq << " and SIZEBUFFERcycFiles (in TransposeFasta.h) is " << SIZEBUFFERcycFiles << endl;
	//}
	
	ram = ram * nSeq;   //ram used in BCR for vector 
	
	SIZEBUFFERcycFiles = ram / lengthRead;
	
	if ( SIZEBUFFERcycFiles > nSeq )   //number of columns
		SIZEBUFFERcycFiles = nSeq;
	else if ( SIZEBUFFERcycFiles < 1048576 )
		SIZEBUFFERcycFiles = 1048576;
	
	
	std::cerr << "TrasposeFasta.convertQS: init buf_ of size " << (unsigned long) lengthRead << " * " << SIZEBUFFERcycFiles << std::endl;
	
	vector<vector<uchar> > buf_;
	buf_.resize(lengthRead);    //For each symbol/column of the read
	for (dataTypelenSeq x = 0 ; x < lengthRead; x++)         //For each symbol/column of the read
		buf_[x].resize(SIZEBUFFERcycFiles);
	for (dataTypelenSeq x = 0 ; x < lengthRead; x++)         //For each symbol/column of the read
		for (dataTypeNChar y = 0 ; y < SIZEBUFFERcycFiles; y++)         //For each buffered symbol of the read
			buf_[x][y]=TERMINATE_CHAR_LEN;

	//char buf[SIZEBUFFERcycFiles];
    //for(dataTypeNChar i=0;i<SIZEBUFFERcycFiles;i++ )
//		buf[i] = '\0';	
	//fgets ( buf, SIZEBUFFERcycFiles, ifile );			//it starts with '>', we can ignore it
	
	std::ifstream infile(input.c_str());
	string bufChar;
	
	dataTypeNChar charsBuffered = 0;
    // looping through the input file, add the characters to the buffer, print buffer when it's full
//    unsigned int num_read = 0;
    dataTypeNChar num_write = 0;
	dataTypelenSeq tmpLen = 0;
    nSeq = 0;
	dataTypelenSeq sumLenCum = 0;

    /*while( !feof(ifile) )
    {
        if( charsBuffered-1 == SIZEBUFFERcycFiles)   //it is linked to the number of sequences
        {
            // write buffers to the files, clear buffers
            for(dataTypelenSeq i=0;i<lengthRead;i++ )  {       //For each symbol/column of the read   (for each string)
                std::stringstream fn;
                fn << output << "qs." << (int)i << ".txt";
				outputFiles_[i] = fopen( fn.str().c_str(),"a" );
				num_write = fwrite ( &buf_[i][0],sizeof(char),charsBuffered-1,outputFiles_[i] );
				assert( num_write == charsBuffered-1 );
				for(dataTypeNChar x=0; x<charsBuffered-1; x++ ) {
					//For each buffered symbol of the read (a symbol for each string)
					if (buf_[i][x] != TERMINATE_CHAR_LEN) {
						//freq[(unsigned int)(buf_[i][x])]=1;
						buf_[i][x] = TERMINATE_CHAR_LEN;
					}
				}
				fclose(outputFiles_[i]);
            }
			
	        //for (dataTypelenSeq x = 0 ; x < lengthRead; x++)         //For each symbol/column of the read
		    //    for (dataTypeNChar y = 0 ; y < BUFFERSIZE; y++)         //For each buffered symbol of the read
			//        buf_[x][y]=TERMINATE_CHAR_LEN;
			
            charsBuffered=1;
        }

        // process the input
        if( buf[0] != '>' )
        {
			dataTypelenSeq posit = 0 + sumLenCum;
			for(dataTypelenSeq i=posit; i < posit + tmpLen;i++) {
				buf_[i][charsBuffered-1] = buf[i-posit];
			}

            sumLenCum += tmpLen;

			#if verboseEncode==1
				cerr << "Partial Buf_ " << endl;
				for(dataTypelenSeq i=0;i<lengthRead;i++ ) {
					cerr << (int)i << " " ;
					for(dataTypeNChar x=0; x<charsBuffered; x++ )
						cerr << buf_[i][x] ;
					cerr << endl;
				}
			#endif
        }
		else  {
			if (nSeq % SIZEBUFFERcycFiles == 0)
				cerr << "New QS sequence - " << "Sequence N. " << (int)nSeq << std::endl;

			sumLenCum = 0;
		    // increase the number of sequences
			nSeq++;
			// increase the counter of chars buffered
			charsBuffered++;
		}
		for(dataTypelenSeq i=0;i<lengthRead;i++ )
			buf[i] = '\0';
		fgets ( buf, SIZEBUFFERcycFiles, ifile );
        if ((buf[strlen(buf)-2] == '\r') || (buf[strlen(buf)-2] == '\n'))
            buf[strlen(buf)-2] = '\0';
        else if ((buf[strlen(buf)-1] == '\r') || (buf[strlen(buf)-1] == '\n'))
            buf[strlen(buf)-1] = '\0';

		tmpLen = strlen(buf);          //tmpLen = strlen(buf)-1;
    }
	*/
	
	while (getline(infile, bufChar))  {
		if ((bufChar[bufChar.length()-2] == '\r') || (bufChar[bufChar.length()-2] == '\n'))
            bufChar[bufChar.length()-2] = '\0';
        else if ((bufChar[bufChar.length()-1] == '\r') || (bufChar[bufChar.length()-1] == '\n'))
            bufChar[bufChar.length()-1] = '\0';		
		
		tmpLen = bufChar.length();          //tmpLen = strlen(buf)-1;
		
		if ( (charsBuffered > 0) && ( charsBuffered-1 == SIZEBUFFERcycFiles))   //it is linked to the number of sequences
        {
			// write buffers to the files, clear buffers
            for(dataTypelenSeq i=0;i<lengthRead;i++ )  {       //For each symbol/column of the read   (for each string)
                std::stringstream fn;
                fn << output << "qs." << (int)i << ".txt";
				outputFiles_[i] = fopen( fn.str().c_str(),"a" );
				num_write = fwrite ( &buf_[i][0],sizeof(char),charsBuffered-1,outputFiles_[i] );
				assert( num_write == charsBuffered-1 );
				for(dataTypeNChar x=0; x<charsBuffered-1; x++ ) {
					//For each buffered symbol of the read (a symbol for each string)
					if (buf_[i][x] != TERMINATE_CHAR_LEN) {
						//freq[(unsigned int)(buf_[i][x])]++;   //=1
						buf_[i][x] = TERMINATE_CHAR_LEN;
					}
				}
				fclose(outputFiles_[i]);
            }
            charsBuffered=1;
        }

        // process the input
        if( bufChar[0] != '{' )   //no title
        {
			
			dataTypelenSeq posit = 0 + sumLenCum;
			for(dataTypelenSeq i=posit; i < posit + tmpLen;i++) {
				buf_[i][charsBuffered-1] = bufChar[i-posit];
			}

            sumLenCum += tmpLen;
			//cerr << "it is not title"<< " tmpLen " << (int)tmpLen << " sumLenCum " << (unsigned int)sumLenCum << endl;
			
 			/*#if verboseEncode==1
				cerr << "Partial Buf_ " << endl;
				for(dataTypelenSeq i=0;i<lengthRead;i++ ) {
					cerr << (int)i << " " ;
					for(dataTypeNChar x=0; x<charsBuffered; x++ )
						cerr << buf_[i][x] ;
					cerr << endl;
				}
			#endif */
        }
		else  {        //it is a title
            sumLenCum = 0;
		    // increase the number of sequences
			nSeq++;
			//cerr << "it is a title"<< nSeq << endl;
			// increase the counter of chars buffered
			charsBuffered++;
		}
		//for(dataTypelenSeq i=0;i<lengthRead;i++ )
		//	buf[i] = '\0';
		//fgets ( buf, BUFFER_SIZELEN, ifile );
        //if ((buf[strlen(buf)-2] == '\r') || (buf[strlen(buf)-2] == '\n'))
         //   buf[strlen(buf)-2] = '\0';
        //else if ((buf[strlen(buf)-1] == '\r') || (buf[strlen(buf)-1] == '\n'))
        //    buf[strlen(buf)-1] = '\0';

//        cerr << "buf: " << buf << "." << endl;
		
    }  //end-while
	
	

	/* 	#if verboseEncode==1
		cerr << "The last Buf_ " << endl;
		cerr << "Buf_ " << endl;
		for(dataTypelenSeq i=0;i<lengthRead;i++ ) {
			for(dataTypeNChar x=0; x<charsBuffered; x++ )
				cerr << buf_[i][x] ;
			cerr << endl;
		}
	#endif */

    // write the rest
    for(dataTypelenSeq i=0;i<lengthRead;i++ )
    {
        std::stringstream fn;
        fn << output << "qs." << (int)i << ".txt";
        outputFiles_[i] = fopen( fn.str().c_str(),"a" );
		num_write = fwrite ( &buf_[i][0],sizeof(char),charsBuffered,outputFiles_[i] );
		assert( num_write == charsBuffered );
		for(dataTypeNChar x=0; x<charsBuffered; x++ ) {
			if (buf_[i][x] != TERMINATE_CHAR_LEN) {
				//freq[(unsigned int)(buf_[i][x])]=1;
				buf_[i][x] = TERMINATE_CHAR_LEN;
			}
		}
        fclose( outputFiles_[i]);
    }

	cerr << "Number of quality score sequences reading/writing: " << nSeq << "\n";
	//cerr << "Number of characters reading/writing: " << lengthTexts << "\n";

    return true;
}

// Assembly:
subq $0x968, %rsp            # imm = 0x968
movq %rdi, 0x960(%rsp)
movq %rsi, 0x958(%rsp)
movq %rdx, 0x950(%rsp)
movq %rcx, 0x948(%rsp)
movq 0x960(%rsp), %rax
movq %rax, 0x178(%rsp)
movq 0xecc2(%rip), %rdi      # 0x1fff0
leaq 0x8253(%rip), %rsi      # 0x19588
callq 0x3260
movq %rax, %rdi
movq 0x958(%rsp), %rsi
callq 0x3220
movq %rax, %rdi
leaq 0x8254(%rip), %rsi      # 0x195a8
callq 0x3260
movq %rax, %rdi
movq 0xec5d(%rip), %rsi      # 0x1ffc0
callq 0x32a0
movq 0x958(%rsp), %rdi
callq 0x3100
movq %rax, %rdi
leaq 0x75df(%rip), %rsi      # 0x1895e
callq 0x32e0
movq %rax, 0x940(%rsp)
cmpq $0x0, 0x940(%rsp)
jne 0x113d8
movq 0xec52(%rip), %rdi      # 0x1fff0
leaq 0x8206(%rip), %rsi      # 0x195ab
callq 0x3260
movq %rax, %rdi
movq 0x958(%rsp), %rsi
callq 0x3220
movq %rax, %rdi
leaq 0x81e4(%rip), %rsi      # 0x195a8
callq 0x3260
movq %rax, %rdi
movq 0xebed(%rip), %rsi      # 0x1ffc0
callq 0x32a0
leaq 0x928(%rsp), %rdi
movq %rdi, 0x170(%rsp)
callq 0x12be0
movq 0x178(%rsp), %rax
movq 0x170(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, %esi
callq 0x12bf0
jmp 0x11409
movb $0x0, 0x91b(%rsp)
movq 0x178(%rsp), %rcx
movzbl 0x91b(%rsp), %eax
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x1168f
leaq 0x790(%rsp), %rdi
callq 0x31c0
jmp 0x1143b
leaq 0x7a0(%rsp), %rdi
movq 0x950(%rsp), %rsi
callq 0x3220
movq %rax, 0x168(%rsp)
jmp 0x1145a
movq 0x168(%rsp), %rdi
leaq 0x8170(%rip), %rsi      # 0x195d9
callq 0x3260
movq %rax, 0x160(%rsp)
jmp 0x11478
movq 0x160(%rsp), %rdi
movzbl 0x91b(%rsp), %esi
callq 0x3480
movq %rax, 0x158(%rsp)
jmp 0x11497
movq 0x158(%rsp), %rdi
leaq 0x74b3(%rip), %rsi      # 0x18959
callq 0x3260
jmp 0x114ad
leaq 0x770(%rsp), %rdi
leaq 0x790(%rsp), %rsi
callq 0x3250
jmp 0x114c4
leaq 0x770(%rsp), %rdi
callq 0x3100
movq %rax, %rdi
leaq 0x7b9a(%rip), %rsi      # 0x19075
callq 0x32e0
movq %rax, 0x150(%rsp)
jmp 0x114ea
movzbl 0x91b(%rsp), %eax
movl %eax, %esi
leaq 0x928(%rsp), %rdi
callq 0x12c90
movq 0x150(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x770(%rsp), %rdi
callq 0x3180
movzbl 0x91b(%rsp), %eax
movl %eax, %esi
leaq 0x928(%rsp), %rdi
callq 0x12c90
cmpq $0x0, (%rax)
jne 0x1163a
movq 0xeaaf(%rip), %rdi      # 0x1fff0
leaq 0x7e49(%rip), %rsi      # 0x19391
callq 0x3260
movq %rax, 0x148(%rsp)
jmp 0x11557
leaq 0x750(%rsp), %rdi
leaq 0x790(%rsp), %rsi
callq 0x3250
jmp 0x1156e
leaq 0x750(%rsp), %rdi
callq 0x3100
movq 0x148(%rsp), %rdi
movq %rax, %rsi
callq 0x3260
movq %rax, 0x140(%rsp)
jmp 0x11595
movq 0x140(%rsp), %rdi
movq 0xea1c(%rip), %rsi      # 0x1ffc0
callq 0x32a0
jmp 0x115ab
leaq 0x750(%rsp), %rdi
callq 0x3180
movl $0x1, %edi
callq 0x3300
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
jmp 0x12346
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
jmp 0x1167d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
leaq 0x770(%rsp), %rdi
callq 0x3180
jmp 0x1167d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
leaq 0x750(%rsp), %rdi
callq 0x3180
jmp 0x1167d
movzbl 0x91b(%rsp), %eax
movl %eax, %esi
leaq 0x928(%rsp), %rdi
callq 0x12c90
movq (%rax), %rdi
callq 0x3270
jmp 0x1165b
leaq 0x790(%rsp), %rdi
callq 0x31e0
movb 0x91b(%rsp), %al
addb $0x1, %al
movb %al, 0x91b(%rsp)
jmp 0x11411
leaq 0x790(%rsp), %rdi
callq 0x31e0
jmp 0x12346
movq 0x178(%rsp), %rcx
movq 0x948(%rsp), %rax
movl 0x10(%rcx), %edx
imulq %rdx, %rax
movq %rax, 0x948(%rsp)
movq 0x948(%rsp), %rax
movzbl (%rcx), %edx
movl %edx, %esi
xorl %edx, %edx
divq %rsi
movq %rax, 0x820(%rcx)
movq 0x820(%rcx), %rax
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x116ea
movq 0x178(%rsp), %rax
movl 0x10(%rax), %ecx
movq %rcx, 0x820(%rax)
jmp 0x11714
movq 0x178(%rsp), %rax
cmpq $0x100000, 0x820(%rax) # imm = 0x100000
jae 0x11712
movq 0x178(%rsp), %rax
movq $0x100000, 0x820(%rax) # imm = 0x100000
jmp 0x11714
movq 0xe8d5(%rip), %rdi      # 0x1fff0
leaq 0x7ebb(%rip), %rsi      # 0x195dd
callq 0x3260
movq %rax, 0x138(%rsp)
jmp 0x11731
movq 0x138(%rsp), %rdi
movq 0x178(%rsp), %rax
movzbl (%rax), %eax
movl %eax, %esi
callq 0x3090
movq %rax, 0x130(%rsp)
jmp 0x11755
movq 0x130(%rsp), %rdi
leaq 0x70e3(%rip), %rsi      # 0x18847
callq 0x3260
movq %rax, 0x128(%rsp)
jmp 0x11773
movq 0x128(%rsp), %rdi
movq 0x178(%rsp), %rax
movq 0x820(%rax), %rsi
callq 0x3090
movq %rax, 0x120(%rsp)
jmp 0x11799
movq 0x120(%rsp), %rdi
movq 0xe818(%rip), %rsi      # 0x1ffc0
callq 0x32a0
jmp 0x117af
leaq 0x738(%rsp), %rdi
movq %rdi, 0x118(%rsp)
callq 0x12cb0
movq 0x178(%rsp), %rax
movq 0x118(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, %esi
callq 0x12cc0
jmp 0x117e0
movb $0x0, 0x737(%rsp)
movq 0x178(%rsp), %rcx
movzbl 0x737(%rsp), %eax
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x1185c
movzbl 0x737(%rsp), %eax
movl %eax, %esi
leaq 0x738(%rsp), %rdi
callq 0x12d60
movq %rax, %rdi
movq 0x178(%rsp), %rax
movq 0x820(%rax), %rsi
callq 0x12d80
jmp 0x1182f
jmp 0x11831
movb 0x737(%rsp), %al
addb $0x1, %al
movb %al, 0x737(%rsp)
jmp 0x117e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
jmp 0x12339
movb $0x0, 0x736(%rsp)
movq 0x178(%rsp), %rcx
movzbl 0x736(%rsp), %eax
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x118f7
movq $0x0, 0x728(%rsp)
movq 0x178(%rsp), %rcx
movq 0x728(%rsp), %rax
cmpq 0x820(%rcx), %rax
jae 0x118e0
movzbl 0x736(%rsp), %eax
movl %eax, %esi
leaq 0x738(%rsp), %rdi
callq 0x12d60
movq %rax, %rdi
movq 0x728(%rsp), %rsi
callq 0x12b20
movb $-0x1, (%rax)
movq 0x728(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x728(%rsp)
jmp 0x11887
jmp 0x118e2
movb 0x736(%rsp), %al
addb $0x1, %al
movb %al, 0x736(%rsp)
jmp 0x11864
movq 0x958(%rsp), %rdi
callq 0x3100
movq %rax, %rsi
leaq 0x520(%rsp), %rdi
movl $0x8, %edx
callq 0x34e0
jmp 0x1191b
leaq 0x500(%rsp), %rdi
callq 0x3380
movq 0x178(%rsp), %rax
movq $0x0, 0x4f8(%rsp)
movq $0x0, 0x4f0(%rsp)
movb $0x0, 0x4ef(%rsp)
movl $0x0, 0x10(%rax)
movb $0x0, 0x4ee(%rsp)
leaq 0x520(%rsp), %rdi
leaq 0x500(%rsp), %rsi
callq 0x3070
movq %rax, 0x110(%rsp)
jmp 0x1197e
movq 0x110(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3310
movb %al, 0x10f(%rsp)
jmp 0x1199e
movb 0x10f(%rsp), %al
testb $0x1, %al
jne 0x119ae
jmp 0x11fcc
leaq 0x500(%rsp), %rdi
movq %rdi, 0xf8(%rsp)
callq 0x33d0
movq 0xf8(%rsp), %rdi
movq %rax, %rsi
addq $-0x2, %rsi
callq 0x3520
movq %rax, 0x100(%rsp)
jmp 0x119e1
movq 0x100(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
je 0x11a34
leaq 0x500(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
callq 0x33d0
movq 0xe8(%rsp), %rdi
movq %rax, %rsi
addq $-0x2, %rsi
callq 0x3520
movq %rax, 0xf0(%rsp)
jmp 0x11a24
movq 0xf0(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x11a90
leaq 0x500(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0x33d0
movq 0xd8(%rsp), %rdi
movq %rax, %rsi
addq $-0x2, %rsi
callq 0x3520
movq %rax, 0xe0(%rsp)
jmp 0x11a67
movq 0xe0(%rsp), %rax
movb $0x0, (%rax)
jmp 0x11b53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
jmp 0x1231f
leaq 0x500(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x33d0
movq 0xc8(%rsp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3520
movq %rax, 0xd0(%rsp)
jmp 0x11ac2
movq 0xd0(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
je 0x11b14
leaq 0x500(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x33d0
movq 0xb8(%rsp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3520
movq %rax, 0xc0(%rsp)
jmp 0x11b04
movq 0xc0(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x11b51
leaq 0x500(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x33d0
movq 0xa8(%rsp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3520
movq %rax, 0xb0(%rsp)
jmp 0x11b46
movq 0xb0(%rsp), %rax
movb $0x0, (%rax)
jmp 0x11b53
leaq 0x500(%rsp), %rdi
callq 0x33d0
movb %al, 0x4ef(%rsp)
cmpq $0x0, 0x4f8(%rsp)
jbe 0x11e9e
movq 0x178(%rsp), %rcx
movq 0x4f8(%rsp), %rax
subq $0x1, %rax
cmpq 0x820(%rcx), %rax
jne 0x11e9e
movb $0x0, 0x4ed(%rsp)
movq 0x178(%rsp), %rcx
movzbl 0x4ed(%rsp), %eax
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x11e92
leaq 0x360(%rsp), %rdi
callq 0x31c0
jmp 0x11bc9
leaq 0x370(%rsp), %rdi
movq 0x950(%rsp), %rsi
callq 0x3220
movq %rax, 0xa0(%rsp)
jmp 0x11be8
movq 0xa0(%rsp), %rdi
leaq 0x79e2(%rip), %rsi      # 0x195d9
callq 0x3260
movq %rax, 0x98(%rsp)
jmp 0x11c06
movq 0x98(%rsp), %rdi
movzbl 0x4ed(%rsp), %esi
callq 0x3480
movq %rax, 0x90(%rsp)
jmp 0x11c25
movq 0x90(%rsp), %rdi
leaq 0x6d25(%rip), %rsi      # 0x18959
callq 0x3260
jmp 0x11c3b
leaq 0x340(%rsp), %rdi
leaq 0x360(%rsp), %rsi
callq 0x3250
jmp 0x11c52
leaq 0x340(%rsp), %rdi
callq 0x3100
movq %rax, %rdi
leaq 0x7778(%rip), %rsi      # 0x193e1
callq 0x32e0
movq %rax, 0x88(%rsp)
jmp 0x11c78
movzbl 0x4ed(%rsp), %eax
movl %eax, %esi
leaq 0x928(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x12c90
movq 0x88(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x340(%rsp), %rdi
callq 0x3180
movzbl 0x4ed(%rsp), %eax
movl %eax, %esi
leaq 0x738(%rsp), %rdi
callq 0x12d60
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12b20
movq 0x68(%rsp), %rdi
movq %rax, 0x70(%rsp)
movq 0x4f8(%rsp), %rax
decq %rax
movq %rax, 0x78(%rsp)
movzbl 0x4ed(%rsp), %eax
movl %eax, %esi
callq 0x12c90
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rdx
movq (%rax), %rcx
movl $0x1, %esi
callq 0x3510
movq %rax, 0x80(%rsp)
jmp 0x11d19
movq 0x80(%rsp), %rax
movq %rax, 0x4f0(%rsp)
movq 0x4f0(%rsp), %rax
movq 0x4f8(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x11d44
jmp 0x11da2
leaq 0x7698(%rip), %rdi      # 0x193e3
leaq 0x752e(%rip), %rsi      # 0x19280
movl $0x3b7, %edx            # imm = 0x3B7
leaq 0x78ab(%rip), %rcx      # 0x19609
callq 0x3190
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
jmp 0x11e80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
leaq 0x340(%rsp), %rdi
callq 0x3180
jmp 0x11e80
movq $0x0, 0x338(%rsp)
movq 0x338(%rsp), %rax
movq 0x4f8(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x11e3d
movzbl 0x4ed(%rsp), %eax
movl %eax, %esi
leaq 0x738(%rsp), %rdi
callq 0x12d60
movq %rax, %rdi
movq 0x338(%rsp), %rsi
callq 0x12b20
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0x11e22
movzbl 0x4ed(%rsp), %eax
movl %eax, %esi
leaq 0x738(%rsp), %rdi
callq 0x12d60
movq %rax, %rdi
movq 0x338(%rsp), %rsi
callq 0x12b20
movb $-0x1, (%rax)
jmp 0x11e24
movq 0x338(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x338(%rsp)
jmp 0x11dae
movzbl 0x4ed(%rsp), %eax
movl %eax, %esi
leaq 0x928(%rsp), %rdi
callq 0x12c90
movq (%rax), %rdi
callq 0x3270
jmp 0x11e5e
leaq 0x360(%rsp), %rdi
callq 0x31e0
movb 0x4ed(%rsp), %al
addb $0x1, %al
movb %al, 0x4ed(%rsp)
jmp 0x11b9f
leaq 0x360(%rsp), %rdi
callq 0x31e0
jmp 0x1231f
movq $0x1, 0x4f8(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x500(%rsp), %rdi
callq 0x3520
movq %rax, 0x60(%rsp)
jmp 0x11eb6
movq 0x60(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
je 0x11f9a
movzbl 0x4ee(%rsp), %eax
addl $0x0, %eax
movb %al, 0x337(%rsp)
movb 0x337(%rsp), %al
movb %al, 0x336(%rsp)
movzbl 0x336(%rsp), %eax
movzbl 0x337(%rsp), %ecx
movzbl 0x4ef(%rsp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x11f7f
movzbl 0x336(%rsp), %eax
movzbl 0x337(%rsp), %ecx
subl %ecx, %eax
movslq %eax, %rsi
leaq 0x500(%rsp), %rdi
callq 0x3520
movq %rax, 0x58(%rsp)
jmp 0x11f2e
movq 0x58(%rsp), %rax
movb (%rax), %al
movb %al, 0x57(%rsp)
movzbl 0x336(%rsp), %eax
movl %eax, %esi
leaq 0x738(%rsp), %rdi
callq 0x12d60
movq %rax, %rdi
movq 0x4f8(%rsp), %rsi
subq $0x1, %rsi
callq 0x12b20
movb 0x57(%rsp), %cl
movb %cl, (%rax)
movb 0x336(%rsp), %al
addb $0x1, %al
movb %al, 0x336(%rsp)
jmp 0x11ee7
movzbl 0x4ef(%rsp), %ecx
movzbl 0x4ee(%rsp), %eax
addl %ecx, %eax
movb %al, 0x4ee(%rsp)
jmp 0x11fc7
movq 0x178(%rsp), %rax
movb $0x0, 0x4ee(%rsp)
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq 0x4f8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x4f8(%rsp)
jmp 0x1195f
movb $0x0, 0x335(%rsp)
movq 0x178(%rsp), %rcx
movzbl 0x335(%rsp), %eax
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x12298
leaq 0x1a8(%rsp), %rdi
callq 0x31c0
jmp 0x11ffe
leaq 0x1b8(%rsp), %rdi
movq 0x950(%rsp), %rsi
callq 0x3220
movq %rax, 0x48(%rsp)
jmp 0x1201a
movq 0x48(%rsp), %rdi
leaq 0x75b3(%rip), %rsi      # 0x195d9
callq 0x3260
movq %rax, 0x40(%rsp)
jmp 0x12032
movq 0x40(%rsp), %rdi
movzbl 0x335(%rsp), %esi
callq 0x3480
movq %rax, 0x38(%rsp)
jmp 0x1204b
movq 0x38(%rsp), %rdi
leaq 0x6902(%rip), %rsi      # 0x18959
callq 0x3260
jmp 0x1205e
leaq 0x188(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x3250
jmp 0x12075
leaq 0x188(%rsp), %rdi
callq 0x3100
movq %rax, %rdi
leaq 0x7355(%rip), %rsi      # 0x193e1
callq 0x32e0
movq %rax, 0x30(%rsp)
jmp 0x12098
movzbl 0x335(%rsp), %eax
movl %eax, %esi
leaq 0x928(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x12c90
movq 0x30(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x188(%rsp), %rdi
callq 0x3180
movzbl 0x335(%rsp), %eax
movl %eax, %esi
leaq 0x738(%rsp), %rdi
callq 0x12d60
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12b20
movq 0x10(%rsp), %rdi
movq %rax, 0x18(%rsp)
movq 0x4f8(%rsp), %rax
movq %rax, 0x20(%rsp)
movzbl 0x335(%rsp), %eax
movl %eax, %esi
callq 0x12c90
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rdx
movq (%rax), %rcx
movl $0x1, %esi
callq 0x3510
movq %rax, 0x28(%rsp)
jmp 0x12130
movq 0x28(%rsp), %rax
movq %rax, 0x4f0(%rsp)
movq 0x4f0(%rsp), %rax
cmpq 0x4f8(%rsp), %rax
jne 0x12151
jmp 0x121af
leaq 0x7302(%rip), %rdi      # 0x1945a
leaq 0x7121(%rip), %rsi      # 0x19280
movl $0x401, %edx            # imm = 0x401
leaq 0x749e(%rip), %rcx      # 0x19609
callq 0x3190
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
jmp 0x12286
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x920(%rsp)
movl %eax, 0x91c(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x3180
jmp 0x12286
movq $0x0, 0x180(%rsp)
movq 0x180(%rsp), %rax
cmpq 0x4f8(%rsp), %rax
jae 0x12243
movzbl 0x335(%rsp), %eax
movl %eax, %esi
leaq 0x738(%rsp), %rdi
callq 0x12d60
movq %rax, %rdi
movq 0x180(%rsp), %rsi
callq 0x12b20
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0x12228
movzbl 0x335(%rsp), %eax
movl %eax, %esi
leaq 0x738(%rsp), %rdi
callq 0x12d60
movq %rax, %rdi
movq 0x180(%rsp), %rsi
callq 0x12b20
movb $-0x1, (%rax)
jmp 0x1222a
movq 0x180(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x180(%rsp)
jmp 0x121bb
movzbl 0x335(%rsp), %eax
movl %eax, %esi
leaq 0x928(%rsp), %rdi
callq 0x12c90
movq (%rax), %rdi
callq 0x3270
jmp 0x12264
leaq 0x1a8(%rsp), %rdi
callq 0x31e0
movb 0x335(%rsp), %al
addb $0x1, %al
movb %al, 0x335(%rsp)
jmp 0x11fd4
leaq 0x1a8(%rsp), %rdi
callq 0x31e0
jmp 0x1231f
movq 0xdd51(%rip), %rdi      # 0x1fff0
leaq 0x73a9(%rip), %rsi      # 0x1964f
callq 0x3260
movq %rax, 0x8(%rsp)
jmp 0x122b2
movq 0x8(%rsp), %rdi
movq 0x178(%rsp), %rax
movl 0x10(%rax), %esi
callq 0x3350
movq %rax, (%rsp)
jmp 0x122cd
movq (%rsp), %rdi
leaq 0x6878(%rip), %rsi      # 0x18b50
callq 0x3260
jmp 0x122df
leaq 0x500(%rsp), %rdi
callq 0x3180
leaq 0x520(%rsp), %rdi
callq 0x30a0
leaq 0x738(%rsp), %rdi
callq 0x12e90
leaq 0x928(%rsp), %rdi
callq 0x12ef0
movb $0x1, %al
andb $0x1, %al
addq $0x968, %rsp            # imm = 0x968
retq
leaq 0x500(%rsp), %rdi
callq 0x3180
leaq 0x520(%rsp), %rdi
callq 0x30a0
leaq 0x738(%rsp), %rdi
callq 0x12e90
leaq 0x928(%rsp), %rdi
callq 0x12ef0
movq 0x920(%rsp), %rdi
callq 0x34a0