// File: superyuan[P]refeditor/MappingConvertor.cpp
// Function: main
int main(int argc, char *argv[])
{
	if (parseParameters (argc, argv) == false) 	{
		cerr << "Version: 1.0-r7" << endl;
		cerr << "Contact: shuaiyuan.emory@gmail.com" << endl << endl;	
		cerr << "Usage: " << argv[0] <<" -i input.sam -m dipmap -o output.sam" << endl << endl;
		cerr << "Convert the sam file created from being mapped to a diploid reference genome " << endl;
		cerr << "  to being mapped to a haploid reference genome according to a dipmap file." << endl << endl;
		cerr << "Example: " << argv[0] << " -i input.sam -m hg19.di.fa.dipmap -o output.sam" << endl << endl;
		cerr << "Parameters (mandatory): " << endl;
		cerr << "  -i\t\tinput SAM file " << endl;
		cerr << "  -m\t\tdipmap file created by DiploidConstructor" << endl;
		cerr << "  -o\t\toutput SAM file" << endl;
		exit(-1);
	}

	CLineFields inputSamFile;
	if (inputSamFile.openFile(inputSamFileName)==false) {
		cerr << "Can not open sam file: " << inputSamFileName << endl;
		exit (-1);
	}
	
	ofstream outputSamFile;
	outputSamFile.open(outputSamFileName);

	// process the map file
	readMapFile(dipmapFileName);
	
	// process sam file
	inputSamFile.readline(removeHeader);
	vector<string> locations;
	while (inputSamFile.endofFile()==false) {
		if (inputSamFile.field[0][0]=='@' || inputSamFile.field[0][0]=='#') {// it is the header
			outputSamFile << inputSamFile.line << endl;
		} else {
			unsigned int flag = atoi(inputSamFile.field[1].c_str());
			if (flag & 4) {
				// the flag indicates unmapped read, so we set mapping quality to zero.
				inputSamFile.field[4] = "0";
			}
			// convert  (chr3b.300, 2)  to (chr3, 301)
			GenomePosition gp = GenomeLib::toRef(inputSamFile.field[2], inputSamFile.field[3], removeB);
			readLength = inputSamFile.field[9].length();
			// map from the extended reference allele minichromes to the real position on reference allelel.
            mapExtendedChrome(gp);
			int mm = 0;
			if (inputSamFile.field.size()>=14)
				mm = atoi(inputSamFile.field[13].substr(5).c_str());

			locations.clear();
			if (inputSamFile.field[inputSamFile.field.size()-1].substr(0,5)=="XA:Z:") { 
				// mapping quality==0 and we have chance to fix it                
    			inputSamFile.divide(inputSamFile.field[inputSamFile.field.size()-1].substr(5),";",locations);

				for (int i=0; i<(int)locations.size(); i++) {
					if(locations[i].length()==0) {
						locations.erase(locations.begin()+i);
						i=-1;//invalidate the for loop.
						continue;
					}
					vector<string> f;
					inputSamFile.divide(locations[i],",",f);
					if (f.size()<4)
						break; //skip reads with positions like:  chr3;.28387,+24,36M,2

					GenomePosition gp2 = GenomeLib::toRef(f[0], f[1], removeB);
					
					// map from the extended reference allele minichromes to the real position on reference allelel.
					mapExtendedChrome(gp2);					

					int new_mis = atoi(f[3].c_str());
					if (gp2.allele != 0) { // on non-ref alleles, maybe only partially cover the allele.
						int more_mis = abs(atoi(f[1].c_str()))-readLength;
						if (more_mis>0)
							new_mis += more_mis;  // the tail of the read is outside of the mini-chromosome.
					}
					if ((gp.chrName==gp2.chrName && gp.pos==gp2.pos) || new_mis != mm) {
						// eg. the read is mapped to both (chr1, 201) and (chr1b.200, 2).
						// or the mismatch != the first hit
						if (new_mis < mm) {
							// this hit is better than the first hit, use this to replace the first hit.
							gp = gp2;
							mm=new_mis;
						}
						locations.erase(locations.begin()+i);
						i=-1;//invalidate the for loop.
					}						
				}
				if (locations.empty()) {
					if (mm/readLength < 0.06)
						inputSamFile.field[4]="37"; // make up the mapping quality
					else
						inputSamFile.field[4]="25"; // make up the mapping quality
					flag &= ~4; //clear the "unmapped read bit"
					if (gp.strand<0)
						flag |= 16; //negtive strand;
				}
			}
			outputSamFile << inputSamFile.field[0] << "\t" << flag << "\t" << gp.chrName << "\t" << gp.pos;
			for (int i=4, size=inputSamFile.field.size(); i<size; i++) {
				outputSamFile << "\t" << inputSamFile.field[i];
			}
			outputSamFile << endl;
		}
		inputSamFile.readline(removeHeader);
	}
	inputSamFile.fp->close();
	outputSamFile.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5e0, %rsp            # imm = 0x5E0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x4ac0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3d39
movq 0xc486(%rip), %rdi      # 0xfff0
leaq 0x74b9(%rip), %rsi      # 0xb02a
callq 0x3230
movq %rax, %rdi
movq 0xc438(%rip), %rsi      # 0xffb8
callq 0x3280
movq 0xc464(%rip), %rdi      # 0xfff0
leaq 0x74a7(%rip), %rsi      # 0xb03a
callq 0x3230
movq %rax, %rdi
movq 0xc416(%rip), %rsi      # 0xffb8
callq 0x3280
movq %rax, %rdi
movq 0xc407(%rip), %rsi      # 0xffb8
callq 0x3280
movq 0xc433(%rip), %rdi      # 0xfff0
leaq 0x7499(%rip), %rsi      # 0xb05d
callq 0x3230
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3230
movq %rax, %rdi
leaq 0x7483(%rip), %rsi      # 0xb065
callq 0x3230
movq %rax, %rdi
movq 0xc3c7(%rip), %rsi      # 0xffb8
callq 0x3280
movq %rax, %rdi
movq 0xc3b8(%rip), %rsi      # 0xffb8
callq 0x3280
movq 0xc3e4(%rip), %rdi      # 0xfff0
leaq 0x7478(%rip), %rsi      # 0xb08b
callq 0x3230
movq %rax, %rdi
movq 0xc396(%rip), %rsi      # 0xffb8
callq 0x3280
movq 0xc3c2(%rip), %rdi      # 0xfff0
leaq 0x74a4(%rip), %rsi      # 0xb0d9
callq 0x3230
movq %rax, %rdi
movq 0xc374(%rip), %rsi      # 0xffb8
callq 0x3280
movq %rax, %rdi
movq 0xc365(%rip), %rsi      # 0xffb8
callq 0x3280
movq 0xc391(%rip), %rdi      # 0xfff0
leaq 0x74bf(%rip), %rsi      # 0xb125
callq 0x3230
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3230
movq %rax, %rdi
leaq 0x74ab(%rip), %rsi      # 0xb12f
callq 0x3230
movq %rax, %rdi
movq 0xc325(%rip), %rsi      # 0xffb8
callq 0x3280
movq %rax, %rdi
movq 0xc316(%rip), %rsi      # 0xffb8
callq 0x3280
movq 0xc342(%rip), %rdi      # 0xfff0
leaq 0x74ab(%rip), %rsi      # 0xb160
callq 0x3230
movq %rax, %rdi
movq 0xc2f4(%rip), %rsi      # 0xffb8
callq 0x3280
movq 0xc320(%rip), %rdi      # 0xfff0
leaq 0x74a2(%rip), %rsi      # 0xb179
callq 0x3230
movq %rax, %rdi
movq 0xc2d2(%rip), %rsi      # 0xffb8
callq 0x3280
movq 0xc2fe(%rip), %rdi      # 0xfff0
leaq 0x7496(%rip), %rsi      # 0xb18f
callq 0x3230
movq %rax, %rdi
movq 0xc2b0(%rip), %rsi      # 0xffb8
callq 0x3280
movq 0xc2dc(%rip), %rdi      # 0xfff0
leaq 0x74a4(%rip), %rsi      # 0xb1bf
callq 0x3230
movq %rax, %rdi
movq 0xc28e(%rip), %rsi      # 0xffb8
callq 0x3280
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x32e0
leaq -0x50(%rbp), %rdi
movq %rdi, -0x4f8(%rbp)
callq 0x8060
movq -0x4f8(%rbp), %rdi
leaq 0xc559(%rip), %rsi      # 0x102b0
callq 0x7f20
movb %al, -0x4ea(%rbp)
jmp 0x3d64
movb -0x4ea(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3ddc
movq 0xc275(%rip), %rdi      # 0xfff0
leaq 0x7453(%rip), %rsi      # 0xb1d5
callq 0x3230
movq %rax, -0x500(%rbp)
jmp 0x3d90
movq -0x500(%rbp), %rdi
leaq 0xc512(%rip), %rsi      # 0x102b0
callq 0x3230
movq %rax, -0x508(%rbp)
jmp 0x3dac
movq -0x508(%rbp), %rdi
movq 0xc1fe(%rip), %rsi      # 0xffb8
callq 0x3280
jmp 0x3dc1
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x32e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4aa7
leaq -0x260(%rbp), %rdi
callq 0x3410
jmp 0x3dea
leaq 0xc5bf(%rip), %rsi      # 0x103b0
leaq -0x260(%rbp), %rdi
movl $0x10, %edx
callq 0x3050
jmp 0x3e04
leaq 0xc6a5(%rip), %rdi      # 0x104b0
callq 0x3670
jmp 0x3e12
movb 0xc798(%rip), %al       # 0x105b0
movb %al, -0x511(%rbp)
leaq -0x281(%rbp), %rdi
movq %rdi, -0x510(%rbp)
callq 0x3440
movq -0x510(%rbp), %rdx
leaq 0x71e9(%rip), %rsi      # 0xb028
leaq -0x280(%rbp), %rdi
callq 0x4c00
jmp 0x3e4d
movb -0x511(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x50(%rbp), %rdi
leaq -0x280(%rbp), %rdx
callq 0x80d0
jmp 0x3e6b
leaq -0x280(%rbp), %rdi
callq 0x3150
leaq -0x281(%rbp), %rdi
callq 0x32a0
leaq -0x2a0(%rbp), %rdi
callq 0x4ec0
leaq -0x50(%rbp), %rdi
callq 0x80a0
movb %al, -0x512(%rbp)
jmp 0x3ea0
movb -0x512(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x4a49
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x528(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4cb0
movq -0x528(%rbp), %rsi
movq %rax, %rdi
callq 0x34a0
movq %rax, -0x520(%rbp)
jmp 0x3ee0
movq -0x520(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x40, %eax
je 0x3f2e
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x538(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4cb0
movq -0x538(%rbp), %rsi
movq %rax, %rdi
callq 0x34a0
movq %rax, -0x530(%rbp)
jmp 0x3f1b
movq -0x530(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x3fba
leaq -0x30(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x3200
movq %rax, -0x540(%rbp)
jmp 0x3f47
movq -0x540(%rbp), %rdi
movq 0xc063(%rip), %rsi      # 0xffb8
callq 0x3280
jmp 0x3f5c
jmp 0x499f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4a9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3f98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x3150
leaq -0x281(%rbp), %rdi
callq 0x32a0
jmp 0x4a9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4a8f
leaq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x4cb0
movq %rax, %rdi
callq 0x30f0
movq %rax, %rdi
callq 0x33c0
movl %eax, -0x2a4(%rbp)
movl -0x2a4(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x400d
leaq -0x50(%rbp), %rdi
movl $0x4, %esi
callq 0x4cb0
movq %rax, %rdi
leaq 0x71e9(%rip), %rsi      # 0xb1ed
callq 0x3350
jmp 0x400b
jmp 0x400d
leaq -0x50(%rbp), %rdi
movl $0x2, %esi
callq 0x4cb0
movq %rax, %rsi
leaq -0x2f8(%rbp), %rdi
callq 0x3100
jmp 0x402c
leaq -0x50(%rbp), %rdi
movl $0x3, %esi
callq 0x4cb0
movq %rax, %rsi
leaq -0x318(%rbp), %rdi
callq 0x3100
jmp 0x404b
movzbl 0xc21e(%rip), %ecx      # 0x10270
andl $0x1, %ecx
leaq -0x2d8(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
leaq -0x318(%rbp), %rdx
callq 0x7a80
jmp 0x4071
leaq -0x318(%rbp), %rdi
callq 0x3150
leaq -0x2f8(%rbp), %rdi
callq 0x3150
leaq -0x50(%rbp), %rdi
movl $0x9, %esi
callq 0x4cb0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0xc50f(%rip)      # 0x105b4
leaq -0x2d8(%rbp), %rdi
callq 0x3a00
jmp 0x40b3
movl $0x0, -0x31c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4ee0
cmpq $0xe, %rax
jb 0x416b
leaq -0x50(%rbp), %rdi
movl $0xd, %esi
callq 0x4cb0
movq %rax, %rsi
leaq -0x340(%rbp), %rdi
movl $0x5, %edx
movq $-0x1, %rcx
callq 0x3260
jmp 0x40fb
leaq -0x340(%rbp), %rdi
callq 0x30f0
movq %rax, %rdi
callq 0x33c0
movl %eax, -0x31c(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x3150
jmp 0x416b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4149
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x318(%rbp), %rdi
callq 0x3150
leaq -0x2f8(%rbp), %rdi
callq 0x3150
jmp 0x4a8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x498e
leaq -0x2a0(%rbp), %rdi
callq 0x4f00
leaq -0x50(%rbp), %rdi
movq %rdi, -0x548(%rbp)
callq 0x4ee0
movq -0x548(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x4cb0
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x360(%rbp), %rdi
movl $0x5, %ecx
callq 0x3260
jmp 0x41b3
leaq 0x7035(%rip), %rsi      # 0xb1ef
leaq -0x360(%rbp), %rdi
callq 0x4f20
movb %al, -0x549(%rbp)
jmp 0x41ce
leaq -0x360(%rbp), %rdi
callq 0x3150
movb -0x549(%rbp), %al
testb $0x1, %al
jne 0x41e9
jmp 0x4830
leaq -0x50(%rbp), %rdi
movq %rdi, -0x558(%rbp)
callq 0x4ee0
movq -0x558(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x4cb0
movq %rax, %rsi
leaq -0x380(%rbp), %rdi
movl $0x5, %edx
movq $-0x1, %rcx
callq 0x3260
jmp 0x4228
leaq -0x3a1(%rbp), %rdi
movq %rdi, -0x560(%rbp)
callq 0x3440
movq -0x560(%rbp), %rdx
leaq 0x6fac(%rip), %rsi      # 0xb1f5
leaq -0x3a0(%rbp), %rdi
callq 0x4c00
jmp 0x4257
leaq -0x50(%rbp), %rdi
leaq -0x380(%rbp), %rsi
leaq -0x3a0(%rbp), %rdx
leaq -0x2a0(%rbp), %rcx
callq 0x7d70
jmp 0x4277
leaq -0x3a0(%rbp), %rdi
callq 0x3150
leaq -0x3a1(%rbp), %rdi
callq 0x32a0
leaq -0x380(%rbp), %rdi
callq 0x3150
movl $0x0, -0x3a8(%rbp)
movl -0x3a8(%rbp), %eax
movl %eax, -0x564(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x4ee0
movq %rax, %rcx
movl -0x564(%rbp), %eax
cmpl %ecx, %eax
jge 0x478f
movslq -0x3a8(%rbp), %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x4cb0
movq %rax, %rdi
callq 0x33a0
cmpq $0x0, %rax
jne 0x43d3
leaq -0x2a0(%rbp), %rdi
movq %rdi, -0x578(%rbp)
callq 0x4fc0
movq %rax, -0x3c0(%rbp)
movslq -0x3a8(%rbp), %rsi
leaq -0x3c0(%rbp), %rdi
callq 0x4ff0
movq %rax, -0x3b8(%rbp)
leaq -0x3b0(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0x5030
movq -0x578(%rbp), %rdi
movq -0x3b0(%rbp), %rsi
callq 0x4f50
movq %rax, -0x570(%rbp)
jmp 0x4356
movq -0x570(%rbp), %rax
movq %rax, -0x3c8(%rbp)
movl $0xffffffff, -0x3a8(%rbp) # imm = 0xFFFFFFFF
jmp 0x476a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x360(%rbp), %rdi
callq 0x3150
jmp 0x498e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x43b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x3a0(%rbp), %rdi
callq 0x3150
leaq -0x3a1(%rbp), %rdi
callq 0x32a0
leaq -0x380(%rbp), %rdi
callq 0x3150
jmp 0x498e
leaq -0x3e0(%rbp), %rdi
callq 0x4ec0
movslq -0x3a8(%rbp), %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x4cb0
movq %rax, %rsi
leaq -0x400(%rbp), %rdi
callq 0x3100
jmp 0x4403
leaq -0x421(%rbp), %rdi
movq %rdi, -0x580(%rbp)
callq 0x3440
movq -0x580(%rbp), %rdx
leaq 0x6dd3(%rip), %rsi      # 0xb1f7
leaq -0x420(%rbp), %rdi
callq 0x4c00
jmp 0x4432
leaq -0x50(%rbp), %rdi
leaq -0x400(%rbp), %rsi
leaq -0x420(%rbp), %rdx
leaq -0x3e0(%rbp), %rcx
callq 0x7d70
jmp 0x4452
leaq -0x420(%rbp), %rdi
callq 0x3150
leaq -0x421(%rbp), %rdi
callq 0x32a0
leaq -0x400(%rbp), %rdi
callq 0x3150
leaq -0x3e0(%rbp), %rdi
callq 0x4ee0
cmpq $0x4, %rax
jae 0x44eb
movl $0x4, -0x428(%rbp)
jmp 0x474e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x477e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x44ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x3150
leaq -0x421(%rbp), %rdi
callq 0x32a0
leaq -0x400(%rbp), %rdi
callq 0x3150
jmp 0x477e
xorl %eax, %eax
movl %eax, %esi
leaq -0x3e0(%rbp), %rdi
callq 0x4cb0
movq %rax, %rsi
leaq -0x478(%rbp), %rdi
callq 0x3100
jmp 0x450c
leaq -0x3e0(%rbp), %rdi
movl $0x1, %esi
callq 0x4cb0
movq %rax, %rsi
leaq -0x498(%rbp), %rdi
callq 0x3100
jmp 0x452e
movzbl 0xbd3b(%rip), %ecx      # 0x10270
andl $0x1, %ecx
leaq -0x458(%rbp), %rdi
leaq -0x478(%rbp), %rsi
leaq -0x498(%rbp), %rdx
callq 0x7a80
jmp 0x4554
leaq -0x498(%rbp), %rdi
callq 0x3150
leaq -0x478(%rbp), %rdi
callq 0x3150
leaq -0x458(%rbp), %rdi
callq 0x3a00
jmp 0x457a
leaq -0x3e0(%rbp), %rdi
movl $0x3, %esi
callq 0x4cb0
movq %rax, %rdi
callq 0x30f0
movq %rax, %rdi
callq 0x33c0
movl %eax, -0x49c(%rbp)
cmpl $0x0, -0x434(%rbp)
je 0x4655
leaq -0x3e0(%rbp), %rdi
movl $0x1, %esi
callq 0x4cb0
movq %rax, %rdi
callq 0x30f0
movq %rax, %rdi
callq 0x33c0
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
subl 0xbfd8(%rip), %eax      # 0x105b4
movl %eax, -0x4a0(%rbp)
cmpl $0x0, -0x4a0(%rbp)
jle 0x4653
movl -0x4a0(%rbp), %eax
addl -0x49c(%rbp), %eax
movl %eax, -0x49c(%rbp)
jmp 0x4653
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4625
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x498(%rbp), %rdi
callq 0x3150
leaq -0x478(%rbp), %rdi
callq 0x3150
jmp 0x477e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x458(%rbp), %rdi
callq 0x5140
jmp 0x477e
jmp 0x4655
leaq -0x2d8(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x5070
testb $0x1, %al
jne 0x466e
jmp 0x467c
movl -0x2b8(%rbp), %eax
cmpl -0x438(%rbp), %eax
je 0x468e
movl -0x49c(%rbp), %eax
cmpl -0x31c(%rbp), %eax
je 0x4738
movl -0x49c(%rbp), %eax
cmpl -0x31c(%rbp), %eax
jge 0x46bd
leaq -0x2d8(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x5100
jmp 0x46b1
movl -0x49c(%rbp), %eax
movl %eax, -0x31c(%rbp)
leaq -0x2a0(%rbp), %rdi
movq %rdi, -0x590(%rbp)
callq 0x4fc0
movq %rax, -0x4b8(%rbp)
movslq -0x3a8(%rbp), %rsi
leaq -0x4b8(%rbp), %rdi
callq 0x4ff0
movq %rax, -0x4b0(%rbp)
leaq -0x4a8(%rbp), %rdi
leaq -0x4b0(%rbp), %rsi
callq 0x5030
movq -0x590(%rbp), %rdi
movq -0x4a8(%rbp), %rsi
callq 0x4f50
movq %rax, -0x588(%rbp)
jmp 0x4720
movq -0x588(%rbp), %rax
movq %rax, -0x4c0(%rbp)
movl $0xffffffff, -0x3a8(%rbp) # imm = 0xFFFFFFFF
leaq -0x458(%rbp), %rdi
callq 0x5140
movl $0x0, -0x428(%rbp)
leaq -0x3e0(%rbp), %rdi
callq 0x5160
movl -0x428(%rbp), %eax
testl %eax, %eax
je 0x4768
jmp 0x4766
jmp 0x478f
jmp 0x476a
movl -0x3a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3a8(%rbp)
jmp 0x42a5
leaq -0x3e0(%rbp), %rdi
callq 0x5160
jmp 0x498e
leaq -0x2a0(%rbp), %rdi
callq 0x51c0
testb $0x1, %al
jne 0x47a4
jmp 0x482e
movl -0x31c(%rbp), %eax
cltd
idivl 0xbe03(%rip)            # 0x105b4
cvtsi2sd %eax, %xmm1
movsd 0x684b(%rip), %xmm0     # 0xb008
ucomisd %xmm1, %xmm0
jbe 0x47e4
leaq -0x50(%rbp), %rdi
movl $0x4, %esi
callq 0x4cb0
movq %rax, %rdi
leaq 0x6a1e(%rip), %rsi      # 0xb1f9
callq 0x3350
jmp 0x47e2
jmp 0x4805
leaq -0x50(%rbp), %rdi
movl $0x4, %esi
callq 0x4cb0
movq %rax, %rdi
leaq 0x6a00(%rip), %rsi      # 0xb1fc
callq 0x3350
jmp 0x4803
jmp 0x4805
movl -0x2a4(%rbp), %eax
andl $-0x5, %eax
movl %eax, -0x2a4(%rbp)
cmpl $0x0, -0x2b0(%rbp)
jge 0x482c
movl -0x2a4(%rbp), %eax
orl $0x10, %eax
movl %eax, -0x2a4(%rbp)
jmp 0x482e
jmp 0x4830
xorl %eax, %eax
movl %eax, %esi
leaq -0x50(%rbp), %rdi
callq 0x4cb0
movq %rax, %rsi
leaq -0x260(%rbp), %rdi
callq 0x3200
movq %rax, -0x598(%rbp)
jmp 0x4855
movq -0x598(%rbp), %rdi
leaq 0x67c5(%rip), %rsi      # 0xb028
callq 0x3230
movq %rax, -0x5a0(%rbp)
jmp 0x4871
movq -0x5a0(%rbp), %rdi
movl -0x2a4(%rbp), %esi
callq 0x3340
movq %rax, -0x5a8(%rbp)
jmp 0x488c
movq -0x5a8(%rbp), %rdi
leaq 0x678e(%rip), %rsi      # 0xb028
callq 0x3230
movq %rax, -0x5b0(%rbp)
jmp 0x48a8
movq -0x5b0(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x3200
movq %rax, -0x5b8(%rbp)
jmp 0x48c4
movq -0x5b8(%rbp), %rdi
leaq 0x6756(%rip), %rsi      # 0xb028
callq 0x3230
movq %rax, -0x5c0(%rbp)
jmp 0x48e0
movq -0x5c0(%rbp), %rdi
movl -0x2b8(%rbp), %esi
callq 0x3420
jmp 0x48f4
movl $0x4, -0x4c4(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4ee0
movl %eax, -0x4c8(%rbp)
movl -0x4c4(%rbp), %eax
cmpl -0x4c8(%rbp), %eax
jge 0x496b
leaq 0x6706(%rip), %rsi      # 0xb028
leaq -0x260(%rbp), %rdi
callq 0x3230
movq %rax, -0x5c8(%rbp)
jmp 0x4937
movslq -0x4c4(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x4cb0
movq -0x5c8(%rbp), %rdi
movq %rax, %rsi
callq 0x3200
jmp 0x4958
jmp 0x495a
movl -0x4c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c4(%rbp)
jmp 0x490d
movq 0xb646(%rip), %rsi      # 0xffb8
leaq -0x260(%rbp), %rdi
callq 0x3280
jmp 0x4980
leaq -0x2d8(%rbp), %rdi
callq 0x5140
jmp 0x499f
leaq -0x2d8(%rbp), %rdi
callq 0x5140
jmp 0x4a8f
movb 0xbc0b(%rip), %al       # 0x105b0
movb %al, -0x5d1(%rbp)
leaq -0x4e9(%rbp), %rdi
movq %rdi, -0x5d0(%rbp)
callq 0x3440
movq -0x5d0(%rbp), %rdx
leaq 0x665c(%rip), %rsi      # 0xb028
leaq -0x4e8(%rbp), %rdi
callq 0x4c00
jmp 0x49da
movb -0x5d1(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x50(%rbp), %rdi
leaq -0x4e8(%rbp), %rdx
callq 0x80d0
jmp 0x49f8
leaq -0x4e8(%rbp), %rdi
callq 0x3150
leaq -0x4e9(%rbp), %rdi
callq 0x32a0
jmp 0x3e8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4a3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x4e8(%rbp), %rdi
callq 0x3150
leaq -0x4e9(%rbp), %rdi
callq 0x32a0
jmp 0x4a8f
movq -0x38(%rbp), %rdi
callq 0x3090
jmp 0x4a54
leaq -0x260(%rbp), %rdi
callq 0x3370
jmp 0x4a62
leaq -0x2a0(%rbp), %rdi
callq 0x5160
leaq -0x260(%rbp), %rdi
callq 0x3390
leaq -0x50(%rbp), %rdi
callq 0x4e40
movl -0x4(%rbp), %eax
addq $0x5e0, %rsp            # imm = 0x5E0
popq %rbp
retq
leaq -0x2a0(%rbp), %rdi
callq 0x5160
leaq -0x260(%rbp), %rdi
callq 0x3390
leaq -0x50(%rbp), %rdi
callq 0x4e40
movq -0x58(%rbp), %rdi
callq 0x3430
nopl (%rax)