// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x28e6(%rip), %r14      # 0x520f
leaq 0x5900(%rip), %r15      # 0x8230
movq 0x5681(%rip), %r12      # 0x7fb8
leaq 0x5af2(%rip), %r13      # 0x8430
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2080
cmpl $0x6c, %eax
jle 0x295f
cmpl $0x6f, %eax
je 0x2976
cmpl $0x6d, %eax
jne 0x293e
movq %r13, %rdi
jmp 0x297d
movq %r15, %rdi
cmpl $0x69, %eax
je 0x297d
cmpl $-0x1, %eax
je 0x2988
cmpl $0x3f, %eax
jne 0x293e
jmp 0x3391
leaq 0x59b3(%rip), %rdi      # 0x8330
movq (%r12), %rsi
callq 0x21d0
jmp 0x293e
cmpb $0x0, 0x58a1(%rip)      # 0x8230
je 0x3391
cmpb $0x0, 0x5a94(%rip)      # 0x8430
je 0x3391
cmpb $0x0, 0x5987(%rip)      # 0x8330
je 0x3391
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
callq 0x430c
leaq 0x586d(%rip), %rsi      # 0x8230
movq %rbx, %rdi
callq 0x425e
testb %al, %al
je 0x34dc
leaq 0x238(%rsp), %rdi
callq 0x2350
leaq 0x5949(%rip), %rsi      # 0x8330
leaq 0x238(%rsp), %rbx
movq %rbx, %rdi
movl $0x10, %edx
callq 0x2050
leaq 0x5a2d(%rip), %rdi      # 0x8430
callq 0x259c
movb 0x5b21(%rip), %bpl      # 0x8530
leaq 0x228(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2616(%rip), %rsi      # 0x5038
leaq 0x2610(%rip), %rdx      # 0x5039
leaq 0x218(%rsp), %rdi
callq 0x398a
movzbl %bpl, %esi
leaq 0x60(%rsp), %rdi
leaq 0x218(%rsp), %rdx
callq 0x4340
movq 0x218(%rsp), %rdi
cmpq %r14, %rdi
je 0x2a69
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x2210
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x208(%rsp), %r15
leaq 0x1c8(%rsp), %r12
leaq 0x60(%rsp), %rdi
callq 0x432c
testb %al, %al
jne 0x32f9
movq 0x60(%rsp), %r13
movq (%r13), %rax
movzbl (%rax), %eax
cmpl $0x40, %eax
je 0x2ab4
cmpl $0x23, %eax
jne 0x2b02
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %rbx, %rdi
callq 0x2250
leaq 0x2565(%rip), %r13      # 0x5038
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
jmp 0x3299
movq 0x20(%r13), %rdi
callq 0x2300
movl %eax, 0xc(%rsp)
testb $0x4, %al
je 0x2b35
movq 0x88(%r13), %rdx
subq $-0x80, %r13
movl $0x1, %r8d
movq %r13, %rdi
xorl %esi, %esi
leaq 0x26cd(%rip), %rcx      # 0x51fd
callq 0x22f0
movq 0x60(%rsp), %rax
leaq 0x1a0(%rsp), %rcx
movq %rcx, 0x190(%rsp)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq 0x190(%rsp), %r14
movq %r14, %rdi
callq 0x38fa
leaq 0x1f8(%rsp), %r12
movq 0x60(%rsp), %rax
movq %r15, 0x1f8(%rsp)
movq 0x60(%rax), %rsi
movq 0x68(%rax), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x38fa
leaq 0x24a4(%rip), %r13      # 0x5038
movzbl 0x565d(%rip), %ecx      # 0x81f8
leaq 0xc0(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3f60
movq 0x1f8(%rsp), %rdi
cmpq %r15, %rdi
leaq 0x30(%rsp), %r12
je 0x2bd0
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x2210
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x2bf5
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x2210
movq 0x60(%rsp), %rax
movl 0x128(%rax), %eax
movl %eax, 0x592e(%rip)      # 0x8534
leaq 0xc0(%rsp), %rdi
callq 0x2866
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rax
subq %rsi, %rax
movl $0x0, 0x8(%rsp)
cmpq $0x1a1, %rax            # imm = 0x1A1
jb 0x2c76
addq $0x1a0, %rsi            # imm = 0x1A0
movl $0x5, %edx
movq %r12, %rdi
movq $-0x1, %rcx
callq 0x2230
movq 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x2300
movl %eax, 0x8(%rsp)
leaq 0x40(%rsp), %rax
cmpq %rax, %r15
je 0x2c76
movq 0x40(%rsp), %rsi
incq %rsi
movq %r15, %rdi
callq 0x2210
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r14, %r15
je 0x2cba
leaq 0x10(%r14), %r12
movq -0x10(%r12), %rdi
cmpq %rdi, %r12
je 0x2c9f
movq (%r12), %rsi
incq %rsi
callq 0x2210
leaq 0x20(%r12), %rax
addq $0x10, %r12
cmpq %r15, %r12
movq %rax, %r12
jne 0x2c89
movq %r14, 0x18(%rsp)
leaq 0x30(%rsp), %r12
movq 0x68(%rsp), %rsi
addq $-0x20, %rsi
movl $0x5, %ecx
movq %r12, %rdi
xorl %edx, %edx
callq 0x2230
movq %r12, %rdi
leaq 0x2523(%rip), %rsi      # 0x51ff
callq 0x20b0
movl %eax, %ebp
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
leaq 0x100(%rsp), %r12
je 0x2d07
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2210
testl %ebp, %ebp
jne 0x3164
movq 0x68(%rsp), %rsi
addq $-0x20, %rsi
movl $0x5, %edx
leaq 0x1d8(%rsp), %rdi
movq $-0x1, %rcx
callq 0x2230
leaq 0x180(%rsp), %rax
movq %rax, 0x170(%rsp)
leaq 0x170(%rsp), %r14
movq %r14, %rdi
leaq 0x24b2(%rip), %rsi      # 0x5205
leaq 0x24ac(%rip), %rdx      # 0x5206
callq 0x398a
leaq 0x60(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
movq %r14, %rdx
leaq 0x10(%rsp), %rcx
callq 0x4128
movq 0x170(%rsp), %rdi
leaq 0x180(%rsp), %rax
cmpq %rax, %rdi
je 0x2d9e
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x2210
movq 0x1d8(%rsp), %rdi
leaq 0x1e8(%rsp), %rax
cmpq %rax, %rdi
je 0x2dc3
movq 0x1e8(%rsp), %rsi
incq %rsi
callq 0x2210
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
testl %ecx, %ecx
jle 0x30ff
xorl %r14d, %r14d
movslq %r14d, %rbp
shlq $0x5, %rbp
leaq (%rax,%rbp), %rsi
cmpq $0x0, 0x8(%rax,%rbp)
je 0x2ff7
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
movq %r12, 0xf0(%rsp)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
leaq 0xf0(%rsp), %rdi
movq %rax, %rsi
callq 0x38fa
leaq 0x160(%rsp), %rax
movq %rax, 0x150(%rsp)
leaq 0x150(%rsp), %r15
movq %r15, %rdi
leaq 0x23b6(%rip), %rsi      # 0x5207
leaq 0x23b0(%rip), %rdx      # 0x5208
callq 0x398a
leaq 0x60(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
movq %r15, %rdx
leaq 0xa0(%rsp), %rcx
callq 0x4128
movq 0x150(%rsp), %rdi
leaq 0x160(%rsp), %rax
cmpq %rax, %rdi
je 0x2e9f
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x2210
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
je 0x2ebc
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2210
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %r15
subq %rax, %r15
cmpq $0x60, %r15
jbe 0x30c8
movq %r15, 0x1b0(%rsp)
movq %rbx, %r13
leaq 0x140(%rsp), %rcx
movq %rcx, 0x130(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x130(%rsp), %r12
movq %r12, %rdi
callq 0x38fa
movq 0xa0(%rsp), %rax
leaq 0x120(%rsp), %rcx
movq %rcx, 0x110(%rsp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq 0x110(%rsp), %rbx
movq %rbx, %rdi
callq 0x38fa
leaq 0x30(%rsp), %r15
movzbl 0x52ab(%rip), %ecx      # 0x81f8
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3f60
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
movq %r13, %rbx
je 0x2f83
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x2210
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
movl 0x8(%rsp), %r13d
je 0x2fad
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x2210
movq %r15, %rdi
callq 0x2866
movq 0xa0(%rsp), %r15
movq 0x60(%r15), %rdi
callq 0x2300
movl %eax, %r12d
cmpl $0x0, 0x54(%rsp)
je 0x300c
movq 0x20(%r15), %rdi
callq 0x2300
movl %eax, %r15d
negl %r15d
cmovsl %eax, %r15d
subl 0x554a(%rip), %r15d     # 0x8534
testl %r15d, %r15d
jg 0x2ff2
xorl %r15d, %r15d
addl %r12d, %r15d
jmp 0x300f
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %rdi
callq 0x3ee6
jmp 0x30e2
movl %r12d, %r15d
movq 0xc8(%rsp), %rdx
cmpq 0x38(%rsp), %rdx
leaq 0x100(%rsp), %r12
jne 0x304e
testq %rdx, %rdx
je 0x3041
movq 0x30(%rsp), %rsi
movq 0xc0(%rsp), %rdi
callq 0x2220
testl %eax, %eax
jne 0x304e
movl 0xe0(%rsp), %eax
cmpl 0x50(%rsp), %eax
je 0x3053
cmpl %r13d, %r15d
je 0x309f
cmpl %r13d, %r15d
jge 0x3087
leaq 0xc0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2120
leaq 0x40(%rsp), %rcx
movl 0x18(%rcx), %eax
leaq 0xe0(%rsp), %rdx
movl %eax, 0x8(%rdx)
movq 0x10(%rcx), %rax
movq %rax, (%rdx)
movl %r15d, %r13d
addq 0x10(%rsp), %rbp
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x3ee6
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x30bb
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2210
movl %r13d, 0x8(%rsp)
movq 0x1b0(%rsp), %r15
leaq 0xa0(%rsp), %rdi
callq 0x381c
cmpq $0x61, %r15
leaq 0x1f58(%rip), %r13      # 0x5038
jb 0x30ff
incl %r14d
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
cmpl %ecx, %r14d
jl 0x2ddf
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
jne 0x3164
movl 0x8(%rsp), %eax
cltd
idivl 0x541e(%rip)            # 0x8534
movq 0x60(%rsp), %rcx
leaq 0x80(%rcx), %rdi
testl %eax, %eax
movq 0x88(%rcx), %rdx
leaq 0x20da(%rip), %rcx      # 0x520c
leaq 0x20d0(%rip), %rax      # 0x5209
cmovleq %rax, %rcx
movl $0x2, %r8d
xorl %esi, %esi
callq 0x22f0
movl 0xc(%rsp), %ecx
andl $-0x5, %ecx
movl 0xe8(%rsp), %eax
shrl $0x1b, %eax
andl $-0x10, %eax
orl %eax, %ecx
movl %ecx, 0xc(%rsp)
movq 0x60(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2250
movl 0xc(%rsp), %esi
movq %r15, %rdi
callq 0x2130
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2250
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq %r14, %rdi
callq 0x2250
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2250
movl 0xe0(%rsp), %esi
movq %r14, %rdi
callq 0x2360
movq 0x68(%rsp), %r14
subq 0x60(%rsp), %r14
shrq $0x5, %r14
cmpl $0x5, %r14d
jl 0x3238
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
addq $-0x4, %r14
movl $0x88, %r15d
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2250
movq 0x60(%rsp), %rax
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq %rbx, %rdi
callq 0x2250
addq $0x20, %r15
decq %r14
jne 0x3209
movq 0x238(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x3289
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2210
leaq 0x208(%rsp), %r15
leaq 0x1c8(%rsp), %r12
movb 0x5290(%rip), %bpl      # 0x8530
movq %r12, 0x1b8(%rsp)
leaq 0x1b8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
leaq 0x1d7c(%rip), %rdx      # 0x5039
callq 0x398a
movzbl %bpl, %esi
leaq 0x60(%rsp), %rdi
movq %r14, %rdx
callq 0x4340
movq 0x1b8(%rsp), %rdi
cmpq %r12, %rdi
je 0x2a8c
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x2210
jmp 0x2a8c
movq 0x78(%rsp), %rdi
callq 0x2070
leaq 0x238(%rsp), %rdi
callq 0x22b0
leaq 0x10(%rsp), %rdi
callq 0x381c
movq 0x4ca7(%rip), %rax      # 0x7fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x240(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x238(%rsp,%rcx)
callq 0x21b0
leaq 0x330(%rsp), %rdi
callq 0x20c0
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3373
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2210
leaq 0x60(%rsp), %rdi
callq 0x381c
xorl %eax, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4c58(%rip), %r14      # 0x7ff0
leaq 0x1c9b(%rip), %rsi      # 0x503a
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
leaq 0x1c94(%rip), %rsi      # 0x504a
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
leaq 0x1c98(%rip), %rsi      # 0x506d
movq %r14, %rdi
callq 0x21f0
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x21f0
leaq 0x1c86(%rip), %rsi      # 0x5075
movq %rax, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
leaq 0x1c8d(%rip), %rsi      # 0x509b
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
leaq 0x1cc4(%rip), %rsi      # 0x50e9
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
leaq 0x1cf1(%rip), %rsi      # 0x5135
movq %r14, %rdi
callq 0x21f0
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x21f0
leaq 0x1ce1(%rip), %rsi      # 0x513f
movq %rax, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
leaq 0x1cf3(%rip), %rsi      # 0x5170
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
leaq 0x1cf5(%rip), %rsi      # 0x5189
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
leaq 0x1cf4(%rip), %rsi      # 0x519f
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
leaq 0x1d0d(%rip), %rsi      # 0x51cf
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2100
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2270
movq 0x4b0d(%rip), %rdi      # 0x7ff0
leaq 0x1cfb(%rip), %rsi      # 0x51e5
movl $0x17, %edx
callq 0x2250
leaq 0x4d35(%rip), %rbx      # 0x8230
movq %rbx, %rdi
callq 0x20f0
movq 0x4ae6(%rip), %rdi      # 0x7ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2250
movq 0x4ad4(%rip), %rdi      # 0x7ff0
callq 0x2100
jmp 0x34d2
movq %rax, %rbx
movq 0x218(%rsp), %rdi
cmpq %r14, %rdi
je 0x3755
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x2210
jmp 0x3755
jmp 0x355d
jmp 0x3550
movq %rax, %rbx
jmp 0x3762
jmp 0x371e
movq %rax, %rbx
jmp 0x3755
jmp 0x367c
movq %rax, %rbx
movq 0x170(%rsp), %rdi
leaq 0x180(%rsp), %rax
cmpq %rax, %rdi
je 0x3597
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x2210
jmp 0x3597
movq %rax, %rbx
movq 0x1d8(%rsp), %rdi
leaq 0x1e8(%rsp), %rax
cmpq %rax, %rdi
je 0x3726
movq 0x1e8(%rsp), %rsi
incq %rsi
callq 0x2210
jmp 0x3726
jmp 0x371e
jmp 0x3723
jmp 0x367c
jmp 0x3723
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
cmpq %r15, %rdi
je 0x35fe
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x2210
jmp 0x35fe
movq %rax, %rbx
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x374b
movq 0x1a0(%rsp), %rsi
jmp 0x3743
jmp 0x371e
jmp 0x3723
jmp 0x369a
movq %rax, %rbx
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x365d
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x2210
jmp 0x365d
movq %rax, %rbx
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x36f1
movq 0x140(%rsp), %rsi
jmp 0x36e9
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x36f1
movq 0x40(%rsp), %rsi
jmp 0x36e9
jmp 0x3723
movq %rax, %rbx
jmp 0x36f1
movq %rax, %rbx
jmp 0x36cc
movq %rax, %rbx
movq 0x150(%rsp), %rdi
leaq 0x160(%rsp), %rax
cmpq %rax, %rdi
je 0x36cc
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x2210
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x36f1
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2210
leaq 0xa0(%rsp), %rdi
callq 0x381c
jmp 0x3726
jmp 0x371e
movq %rax, %rbx
movq 0x1b8(%rsp), %rdi
cmpq %r12, %rdi
je 0x374b
movq 0x1c8(%rsp), %rsi
jmp 0x3743
jmp 0x3723
movq %rax, %rbx
jmp 0x374b
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x374b
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2210
leaq 0x10(%rsp), %rdi
callq 0x381c
leaq 0x238(%rsp), %rdi
callq 0x22d0
leaq 0x60(%rsp), %rdi
callq 0x37f6
movq %rbx, %rdi
callq 0x2380