// File: superyuan[P]refeditor/DiploidConstructor.cpp
// Function: extendFromDiploid(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
static int extendFromDiploid(string chrNameDi)
{
	assert(chrNameDi[chrNameDi.length()-1] == 'b');
	string stuffing = STUFFING;
	string valueDi = chrMap[chrNameDi];
	string chrNameHa = chrNameDi.substr(0, chrNameDi.length()-1);
	string valueHa = chrMap[chrNameHa];
	int miniCount = 0;
	int gappedReadLength = readLength+maxDeletion;
	for (int i=0, chrLength=valueDi.length(); i<chrLength; i++) {
		
		if (valueDi[i] != valueHa[i]) {
			int start; // 0-based
			vector<string> miniChrome;
			vector<int> readStart; // corresponds to the items in miniChrome, 1-based
			start = max(i-gappedReadLength+1, 0);
			// the first half we just use the string from reference allele and non-ref allele
			miniChrome.push_back(valueHa.substr(start, i-start));
			readStart.push_back(start+1);
			miniChrome[0] += valueDi[i]; // i is the first non-ref allele covered by reads.
			for (int j=i+1; j<i+gappedReadLength&& j<chrLength; j++) {
				miniCount = miniChrome.size();
				if (valueDi[j] != valueHa[j]) {
					// another difference between ha and di doubles the possible combinations.
					for (int k=0; k<miniCount; k++) {
						int new_start=max((int)(miniChrome[k].length())-gappedReadLength+1, 0);						
						miniChrome.push_back(miniChrome[k].substr(new_start)); // the read covers the new met SNP, right shifting start position.
						readStart.push_back(readStart[k]+new_start);
						miniChrome[k] = miniChrome[k] + valueHa[j]; // append the base from ref allele
						miniChrome[k+miniCount] = miniChrome[k+miniCount] + valueDi[j];  // append the base from non-ref allele
					}
				} else {
					// no SNP, just append it to all mini chromosomes.
					for (int k=0; k<miniCount; k++) {
						miniChrome[k] = miniChrome[k] + valueHa[j]; // append the base from ref allele
					}
				}
			}
			miniCount = miniChrome.size();
			// start from 0 because it covers the first non-ref allele
			for (int j=0; j<miniCount; j++) {				
				dipmapFile << chrNameHa << "\t" << chrMap[chrNameHa].length()+1 << "\t" << miniChrome[j].length() << "\t";
				chrMap[chrNameHa] += miniChrome[j];
				chrMap[chrNameHa] += stuffing;
				dipmapFile << readStart[j] << endl;
			}
		}

	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x1c8(%rbp)
movq %rdi, -0x8(%rbp)
callq 0x33c0
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x34f0
movsbl (%rax), %eax
cmpl $0x62, %eax
jne 0x4bb8
jmp 0x4bd7
leaq 0x77b5(%rip), %rdi      # 0xc374
leaq 0x77d5(%rip), %rsi      # 0xc39b
movl $0x59, %edx
leaq 0x77e0(%rip), %rcx      # 0xc3b2
callq 0x3180
leaq -0x29(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x3460
movq -0x1d0(%rbp), %rdx
leaq 0x77db(%rip), %rsi      # 0xc3d0
leaq -0x28(%rbp), %rdi
callq 0x5810
jmp 0x4c00
leaq -0x29(%rbp), %rdi
callq 0x32d0
movq -0x1c8(%rbp), %rsi
leaq 0xdec9(%rip), %rdi      # 0x12ae0
callq 0x5970
movq %rax, -0x1d8(%rbp)
jmp 0x4c25
movq -0x1d8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3110
jmp 0x4c37
movq -0x1c8(%rbp), %rdi
callq 0x33c0
movq -0x1c8(%rbp), %rsi
movq %rax, %rcx
decq %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x3280
jmp 0x4c5f
leaq 0xde7a(%rip), %rdi      # 0x12ae0
leaq -0x80(%rbp), %rsi
callq 0x5970
movq %rax, -0x1e0(%rbp)
jmp 0x4c78
movq -0x1e0(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x3110
jmp 0x4c8d
movl $0x0, -0xa4(%rbp)
movl 0xda33(%rip), %eax      # 0x126d0
addl 0xda31(%rip), %eax      # 0x126d4
movl %eax, -0xa8(%rbp)
movl $0x0, -0xac(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x33c0
movl %eax, -0xb0(%rbp)
movl -0xac(%rbp), %eax
cmpl -0xb0(%rbp), %eax
jge 0x54e1
movslq -0xac(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x34f0
movq %rax, -0x1e8(%rbp)
jmp 0x4ced
movq -0x1e8(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x1f4(%rbp)
movslq -0xac(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x34f0
movq %rax, -0x1f0(%rbp)
jmp 0x4d19
movl -0x1f4(%rbp), %eax
movq -0x1f0(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x54cb
leaq -0xd0(%rbp), %rdi
callq 0x5790
leaq -0xe8(%rbp), %rdi
callq 0x6070
movl -0xac(%rbp), %eax
movl -0xa8(%rbp), %ecx
subl %ecx, %eax
incl %eax
movl %eax, -0xec(%rbp)
movl $0x0, -0xf0(%rbp)
leaq -0xec(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x6090
movq %rax, -0x200(%rbp)
jmp 0x4d85
movq -0x200(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xb4(%rbp)
movslq -0xb4(%rbp), %rdx
movl %edx, %ecx
movl -0xac(%rbp), %eax
subl %ecx, %eax
movslq %eax, %rcx
leaq -0x110(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3280
jmp 0x4dbd
leaq -0xd0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x60d0
jmp 0x4dd2
leaq -0x110(%rbp), %rdi
callq 0x3518
movl -0xb4(%rbp), %eax
incl %eax
movl %eax, -0x114(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x114(%rbp), %rsi
callq 0x6100
jmp 0x4e01
movslq -0xac(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x34f0
movq %rax, -0x208(%rbp)
jmp 0x4e1a
movq -0x208(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x20c(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0xd0(%rbp), %rdi
callq 0x5ae0
movl -0x20c(%rbp), %esi
movq %rax, %rdi
callq 0x3150
jmp 0x4e4a
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
movl -0x118(%rbp), %ecx
movl -0xac(%rbp), %edx
addl -0xa8(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x20d(%rbp)
jge 0x4e8c
movl -0x118(%rbp), %eax
cmpl -0xb0(%rbp), %eax
setl %al
movb %al, -0x20d(%rbp)
movb -0x20d(%rbp), %al
testb $0x1, %al
jne 0x4e9b
jmp 0x52c8
leaq -0xd0(%rbp), %rdi
callq 0x5ac0
movl %eax, -0xa4(%rbp)
movslq -0x118(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x34f0
movq %rax, -0x218(%rbp)
jmp 0x4ec6
movq -0x218(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x224(%rbp)
movslq -0x118(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x34f0
movq %rax, -0x220(%rbp)
jmp 0x4ef2
movl -0x224(%rbp), %eax
movq -0x220(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x51fd
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jge 0x51f8
movslq -0x11c(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x5ae0
movq %rax, %rdi
callq 0x33c0
movl -0xa8(%rbp), %ecx
subl %ecx, %eax
incl %eax
movl %eax, -0x124(%rbp)
movl $0x0, -0x128(%rbp)
leaq -0x124(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x6090
movq %rax, -0x230(%rbp)
jmp 0x4f77
movq -0x230(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x120(%rbp)
movslq -0x11c(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x5ae0
movq %rax, %rsi
movslq -0x120(%rbp), %rdx
leaq -0x148(%rbp), %rdi
movq $-0x1, %rcx
callq 0x3280
jmp 0x4fb8
leaq -0xd0(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x60d0
jmp 0x4fcd
leaq -0x148(%rbp), %rdi
callq 0x3518
movslq -0x11c(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x6130
movq -0x238(%rbp), %rdi
movl (%rax), %eax
movl -0x120(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x14c(%rbp)
leaq -0x14c(%rbp), %rsi
callq 0x6100
jmp 0x5018
movslq -0x11c(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x5ae0
movq %rax, -0x248(%rbp)
movslq -0x118(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x34f0
movq %rax, -0x240(%rbp)
jmp 0x504e
movq -0x248(%rbp), %rsi
movq -0x240(%rbp), %rax
movsbl (%rax), %edx
leaq -0x170(%rbp), %rdi
callq 0x6150
jmp 0x506d
movslq -0x11c(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x5ae0
movq %rax, %rdi
leaq -0x170(%rbp), %rsi
movq %rsi, -0x268(%rbp)
callq 0x3320
movq -0x268(%rbp), %rdi
callq 0x3518
movq -0x260(%rbp), %rdi
movl -0x11c(%rbp), %eax
movl -0xa4(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x5ae0
movq %rax, -0x258(%rbp)
movslq -0x118(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x34f0
movq %rax, -0x250(%rbp)
jmp 0x50e6
movq -0x258(%rbp), %rsi
movq -0x250(%rbp), %rax
movsbl (%rax), %edx
leaq -0x190(%rbp), %rdi
callq 0x6150
jmp 0x5105
movl -0x11c(%rbp), %eax
addl -0xa4(%rbp), %eax
movslq %eax, %rsi
leaq -0xd0(%rbp), %rdi
callq 0x5ae0
movq %rax, %rdi
leaq -0x190(%rbp), %rsi
callq 0x3320
leaq -0x190(%rbp), %rdi
callq 0x3518
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x4f14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x32d0
jmp 0x553a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5531
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5528
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x551f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5513
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x54b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x3518
jmp 0x54b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x3518
jmp 0x54b1
jmp 0x52b2
movl $0x0, -0x194(%rbp)
movl -0x194(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jge 0x52b0
movslq -0x194(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x5ae0
movq %rax, -0x278(%rbp)
movslq -0x118(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x34f0
movq %rax, -0x270(%rbp)
jmp 0x524f
movq -0x278(%rbp), %rsi
movq -0x270(%rbp), %rax
movsbl (%rax), %edx
leaq -0x1b8(%rbp), %rdi
callq 0x6150
jmp 0x526e
movslq -0x194(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x5ae0
movq %rax, %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x3320
leaq -0x1b8(%rbp), %rdi
callq 0x3518
movl -0x194(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x194(%rbp)
jmp 0x5207
jmp 0x52b2
jmp 0x52b4
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x4e59
leaq -0xd0(%rbp), %rdi
callq 0x5ac0
movl %eax, -0xa4(%rbp)
movl $0x0, -0x1bc(%rbp)
movl -0x1bc(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jge 0x5497
leaq 0xd3db(%rip), %rdi      # 0x126d8
leaq -0x80(%rbp), %rsi
callq 0x3220
movq %rax, -0x280(%rbp)
jmp 0x530f
movq -0x280(%rbp), %rdi
leaq 0x7010(%rip), %rsi      # 0xc32d
callq 0x3250
movq %rax, -0x288(%rbp)
jmp 0x532b
leaq 0xd7ae(%rip), %rdi      # 0x12ae0
leaq -0x80(%rbp), %rsi
callq 0x5970
movq %rax, -0x290(%rbp)
jmp 0x5344
movq -0x290(%rbp), %rdi
callq 0x33c0
movq -0x288(%rbp), %rdi
movq %rax, %rsi
incq %rsi
callq 0x30b0
movq %rax, -0x298(%rbp)
jmp 0x536b
movq -0x298(%rbp), %rdi
leaq 0x6fb4(%rip), %rsi      # 0xc32d
callq 0x3250
movq %rax, -0x2a0(%rbp)
jmp 0x5387
movslq -0x1bc(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x5ae0
movq %rax, %rdi
callq 0x33c0
movq -0x2a0(%rbp), %rdi
movq %rax, %rsi
callq 0x30b0
movq %rax, -0x2a8(%rbp)
jmp 0x53ba
movq -0x2a8(%rbp), %rdi
leaq 0x6f65(%rip), %rsi      # 0xc32d
callq 0x3250
jmp 0x53cf
movslq -0x1bc(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x5ae0
movq %rax, -0x2b8(%rbp)
leaq 0xd6f0(%rip), %rdi      # 0x12ae0
leaq -0x80(%rbp), %rsi
callq 0x5970
movq %rax, -0x2b0(%rbp)
jmp 0x5402
movq -0x2b8(%rbp), %rsi
movq -0x2b0(%rbp), %rdi
callq 0x3350
jmp 0x5417
leaq 0xd6c2(%rip), %rdi      # 0x12ae0
leaq -0x80(%rbp), %rsi
callq 0x5970
movq %rax, -0x2c0(%rbp)
jmp 0x5430
movq -0x2c0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x3350
jmp 0x5442
movslq -0x1bc(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x6130
movl (%rax), %esi
leaq 0xd27a(%rip), %rdi      # 0x126d8
callq 0x3440
movq %rax, -0x2c8(%rbp)
jmp 0x546c
movq -0x2c8(%rbp), %rdi
movq 0xcb2e(%rip), %rsi      # 0x11fa8
callq 0x32a0
jmp 0x5481
jmp 0x5483
movl -0x1bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1bc(%rbp)
jmp 0x52e4
leaq -0xe8(%rbp), %rdi
callq 0x61d0
leaq -0xd0(%rbp), %rdi
callq 0x57b0
jmp 0x54cb
leaq -0xe8(%rbp), %rdi
callq 0x61d0
leaq -0xd0(%rbp), %rdi
callq 0x57b0
jmp 0x5513
jmp 0x54cd
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x4cc2
leaq -0xa0(%rbp), %rdi
callq 0x3518
leaq -0x80(%rbp), %rdi
callq 0x3518
leaq -0x60(%rbp), %rdi
callq 0x3518
leaq -0x28(%rbp), %rdi
callq 0x3518
xorl %eax, %eax
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
leaq -0xa0(%rbp), %rdi
callq 0x3518
leaq -0x80(%rbp), %rdi
callq 0x3518
leaq -0x60(%rbp), %rdi
callq 0x3518
leaq -0x28(%rbp), %rdi
callq 0x3518
movq -0x38(%rbp), %rdi
callq 0x3450
nopw %cs:(%rax,%rax)