// File: /workspace/github_c_makefile_star2_O0/OpenGene[P]pecheck/src/read.cpp
// Function: ReadPair::fastMerge()
Read* ReadPair::fastMerge(){
	Read* rcRight = mRight->reverseComplement();
	int len1 = mLeft->length();
	int len2 = rcRight->length();
	// use the pointer directly for speed
	const char* str1 = mLeft->mSeq.mStr.c_str();
	const char* str2 = rcRight->mSeq.mStr.c_str();
	const char* qual1 = mLeft->mQuality.c_str();
	const char* qual2 = rcRight->mQuality.c_str();

	// we require at least 30 bp overlapping to merge a pair
	const int MIN_OVERLAP = 30;
	bool overlapped = false;
	int olen = MIN_OVERLAP;
	int diff = 0;
	// the diff count for 1 high qual + 1 low qual
	int lowQualDiff = 0;

	while(olen <= min(len1, len2)){
		diff = 0;
		lowQualDiff = 0;
		bool ok = true;
		int offset = len1 - olen;
		for(int i=0;i<olen;i++){
			if(str1[offset+i] != str2[i]){
				diff++;
				// one is >= Q30 and the other is <= Q15
				if((qual1[offset+i]>='?' && qual2[i]<='0') || (qual1[offset+i]<='0' && qual2[i]>='?')){
					lowQualDiff++;
				}
				// we disallow high quality diff, and only allow up to 3 low qual diff
				if(diff>lowQualDiff || lowQualDiff>=3){
					ok = false;
					break;
				}
			}
		}
		if(ok){
			overlapped = true;
			break;
		}
		olen++;
	}

	if(overlapped){
		int offset = len1 - olen;
		stringstream ss;
		ss << mLeft->mName << " merged offset:" << offset << " overlap:" << olen << " diff:" << diff;
		string mergedName = ss.str();
		string mergedSeq = mLeft->mSeq.mStr.substr(0, offset) + rcRight->mSeq.mStr;
		string mergedQual = mLeft->mQuality.substr(0, offset) + rcRight->mQuality;
		// quality adjuction and correction for low qual diff
		for(int i=0;i<olen;i++){
			if(str1[offset+i] != str2[i]){
				if(qual1[offset+i]>='?' && qual2[i]<='0'){
					mergedSeq[offset+i] = str1[offset+i];
					mergedQual[offset+i] = qual1[offset+i];
				} else {
					mergedSeq[offset+i] = str2[i];
					mergedQual[offset+i] = qual2[i];
				}
			} else {
				// add the quality of the pair to make a high qual
				mergedQual[offset+i] =  qual1[offset+i] + qual2[i] - 33;
			}
		}
		delete rcRight;
		return new Read(mergedName, mergedSeq, "+", mergedQual);
	}

	delete rcRight;
	return NULL;
}

// Assembly:
subq $0x3e8, %rsp            # imm = 0x3E8
movq %rdi, 0x3d8(%rsp)
movq 0x3d8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x8(%rax), %rdi
callq 0x12760
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movq %rcx, 0x3d0(%rsp)
movq (%rax), %rdi
callq 0x12cf0
movl %eax, 0x3cc(%rsp)
movq 0x3d0(%rsp), %rdi
callq 0x12cf0
movl %eax, %ecx
movq 0xa8(%rsp), %rax
movl %ecx, 0x3c8(%rsp)
movq (%rax), %rdi
addq $0x20, %rdi
callq 0x4170
movq %rax, 0x3c0(%rsp)
movq 0x3d0(%rsp), %rdi
addq $0x20, %rdi
callq 0x4170
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movq %rcx, 0x3b8(%rsp)
movq (%rax), %rdi
addq $0x60, %rdi
callq 0x4170
movq %rax, 0x3b0(%rsp)
movq 0x3d0(%rsp), %rdi
addq $0x60, %rdi
callq 0x4170
movq %rax, 0x3a8(%rsp)
movl $0x1e, 0x3a4(%rsp)
movb $0x0, 0x3a3(%rsp)
movl $0x1e, 0x39c(%rsp)
movl $0x0, 0x398(%rsp)
movl $0x0, 0x394(%rsp)
movl 0x39c(%rsp), %eax
movl %eax, 0xa4(%rsp)
leaq 0x3cc(%rsp), %rdi
leaq 0x3c8(%rsp), %rsi
callq 0x149b0
movq %rax, %rcx
movl 0xa4(%rsp), %eax
cmpl (%rcx), %eax
jg 0x13b01
movl $0x0, 0x398(%rsp)
movl $0x0, 0x394(%rsp)
movb $0x1, 0x393(%rsp)
movl 0x3cc(%rsp), %eax
subl 0x39c(%rsp), %eax
movl %eax, 0x38c(%rsp)
movl $0x0, 0x388(%rsp)
movl 0x388(%rsp), %eax
cmpl 0x39c(%rsp), %eax
jge 0x13ad7
movq 0x3c0(%rsp), %rax
movl 0x38c(%rsp), %ecx
addl 0x388(%rsp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movq 0x3b8(%rsp), %rcx
movslq 0x388(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x13abf
movl 0x398(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x398(%rsp)
movq 0x3b0(%rsp), %rax
movl 0x38c(%rsp), %ecx
addl 0x388(%rsp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3f, %eax
jl 0x13a4d
movq 0x3a8(%rsp), %rax
movslq 0x388(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
jle 0x13a88
movq 0x3b0(%rsp), %rax
movl 0x38c(%rsp), %ecx
addl 0x388(%rsp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
jg 0x13a99
movq 0x3a8(%rsp), %rax
movslq 0x388(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3f, %eax
jl 0x13a99
movl 0x394(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x394(%rsp)
movl 0x398(%rsp), %eax
cmpl 0x394(%rsp), %eax
jg 0x13ab3
cmpl $0x3, 0x394(%rsp)
jl 0x13abd
movb $0x0, 0x393(%rsp)
jmp 0x13ad7
jmp 0x13abf
jmp 0x13ac1
movl 0x388(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x388(%rsp)
jmp 0x139b4
testb $0x1, 0x393(%rsp)
je 0x13aeb
movb $0x1, 0x3a3(%rsp)
jmp 0x13b01
movl 0x39c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x39c(%rsp)
jmp 0x13941
testb $0x1, 0x3a3(%rsp)
je 0x14201
movl 0x3cc(%rsp), %eax
movl 0x39c(%rsp), %ecx
subl %ecx, %eax
movl %eax, 0x384(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x4260
movq 0xa8(%rsp), %rax
leaq 0x208(%rsp), %rdi
movq (%rax), %rsi
callq 0x42f0
movq %rax, 0x98(%rsp)
jmp 0x13b55
movq 0x98(%rsp), %rdi
leaq 0x2ddc(%rip), %rsi      # 0x16940
callq 0x4340
movq %rax, 0x90(%rsp)
jmp 0x13b73
movq 0x90(%rsp), %rdi
movl 0x384(%rsp), %esi
callq 0x4670
movq %rax, 0x88(%rsp)
jmp 0x13b91
movq 0x88(%rsp), %rdi
leaq 0x2db0(%rip), %rsi      # 0x16950
callq 0x4340
movq %rax, 0x80(%rsp)
jmp 0x13baf
movq 0x80(%rsp), %rdi
movl 0x39c(%rsp), %esi
callq 0x4670
movq %rax, 0x78(%rsp)
jmp 0x13bca
movq 0x78(%rsp), %rdi
leaq 0x2d84(%rip), %rsi      # 0x1695a
callq 0x4340
movq %rax, 0x70(%rsp)
jmp 0x13be2
movq 0x70(%rsp), %rdi
movl 0x398(%rsp), %esi
callq 0x4670
jmp 0x13bf5
leaq 0x1c8(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x4330
jmp 0x13c0c
movq 0xa8(%rsp), %rax
movq (%rax), %rsi
addq $0x20, %rsi
movslq 0x384(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq 0x188(%rsp), %rdi
callq 0x4390
jmp 0x13c36
movq 0x3d0(%rsp), %rdx
addq $0x20, %rdx
leaq 0x1a8(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0xf270
jmp 0x13c59
leaq 0x188(%rsp), %rdi
callq 0x4758
movq 0xa8(%rsp), %rax
movq (%rax), %rsi
addq $0x60, %rsi
movslq 0x384(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq 0x148(%rsp), %rdi
callq 0x4390
jmp 0x13c90
movq 0x3d0(%rsp), %rdx
addq $0x60, %rdx
leaq 0x168(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0xf270
jmp 0x13cb3
leaq 0x148(%rsp), %rdi
callq 0x4758
movl $0x0, 0x144(%rsp)
movl 0x144(%rsp), %eax
cmpl 0x39c(%rsp), %eax
jge 0x13f89
movq 0x3c0(%rsp), %rax
movl 0x384(%rsp), %ecx
addl 0x144(%rsp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movq 0x3b8(%rsp), %rcx
movslq 0x144(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x13f1c
movq 0x3b0(%rsp), %rax
movl 0x384(%rsp), %ecx
addl 0x144(%rsp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3f, %eax
jl 0x13e92
movq 0x3a8(%rsp), %rax
movslq 0x144(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
jg 0x13e92
movq 0x3c0(%rsp), %rax
movl 0x384(%rsp), %ecx
movl 0x144(%rsp), %edx
addl %edx, %ecx
movslq %ecx, %rsi
movb (%rax,%rsi), %al
movb %al, 0x67(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x4740
movq %rax, 0x68(%rsp)
jmp 0x13d91
movq 0x68(%rsp), %rax
movb 0x67(%rsp), %cl
movb %cl, (%rax)
movq 0x3b0(%rsp), %rax
movl 0x384(%rsp), %ecx
movl 0x144(%rsp), %edx
addl %edx, %ecx
movslq %ecx, %rsi
movb (%rax,%rsi), %al
movb %al, 0x57(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x4740
movq %rax, 0x58(%rsp)
jmp 0x13dd2
movq 0x58(%rsp), %rax
movb 0x57(%rsp), %cl
movb %cl, (%rax)
jmp 0x13f1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x141f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x141e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x4758
jmp 0x141e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x141d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x4758
jmp 0x141d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x141cb
movq 0x3b8(%rsp), %rax
movslq 0x144(%rsp), %rdx
movl %edx, %ecx
movb (%rax,%rdx), %al
movb %al, 0x47(%rsp)
movl 0x384(%rsp), %eax
addl %ecx, %eax
movslq %eax, %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x4740
movq %rax, 0x48(%rsp)
jmp 0x13ecb
movq 0x48(%rsp), %rax
movb 0x47(%rsp), %cl
movb %cl, (%rax)
movq 0x3a8(%rsp), %rax
movslq 0x144(%rsp), %rdx
movl %edx, %ecx
movb (%rax,%rdx), %al
movb %al, 0x37(%rsp)
movl 0x384(%rsp), %eax
addl %ecx, %eax
movslq %eax, %rsi
leaq 0x168(%rsp), %rdi
callq 0x4740
movq %rax, 0x38(%rsp)
jmp 0x13f0f
movq 0x38(%rsp), %rax
movb 0x37(%rsp), %cl
movb %cl, (%rax)
jmp 0x13f71
movq 0x3b0(%rsp), %rax
movl 0x384(%rsp), %ecx
movslq 0x144(%rsp), %rdx
movl %edx, %esi
addl %esi, %ecx
movslq %ecx, %rsi
movzbl (%rax,%rsi), %eax
movq 0x3a8(%rsp), %rcx
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
addb $-0x21, %al
movb %al, 0x27(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x4740
movq %rax, 0x28(%rsp)
jmp 0x13f66
movq 0x28(%rsp), %rax
movb 0x27(%rsp), %cl
movb %cl, (%rax)
jmp 0x13f73
movl 0x144(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x144(%rsp)
jmp 0x13ccb
movq 0x3d0(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x13fb5
movq 0x18(%rsp), %rdi
callq 0x6b10
movq 0x18(%rsp), %rdi
movl $0x88, %esi
callq 0x4370
movl $0x88, %edi
callq 0x4360
movq %rax, 0x10(%rsp)
jmp 0x13fc6
movb $0x1, 0xb7(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x4180
jmp 0x13fe5
leaq 0x100(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x4180
jmp 0x13ffc
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x46b0
movq 0x8(%rsp), %rdx
leaq 0x27b2(%rip), %rsi      # 0x167cc
leaq 0xe0(%rsp), %rdi
callq 0x67f0
jmp 0x14029
leaq 0xb8(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x4180
jmp 0x14040
movq 0x10(%rsp), %rdi
leaq 0x120(%rsp), %rsi
leaq 0x100(%rsp), %rdx
leaq 0xe0(%rsp), %rcx
leaq 0xb8(%rsp), %r8
xorl %r9d, %r9d
callq 0x11e30
jmp 0x1406f
movq 0x10(%rsp), %rax
movb $0x0, 0xb7(%rsp)
movq %rax, 0x3e0(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x4758
leaq 0xe0(%rsp), %rdi
callq 0x4758
leaq 0xdf(%rsp), %rdi
callq 0x43e0
leaq 0x100(%rsp), %rdi
callq 0x4758
leaq 0x120(%rsp), %rdi
callq 0x4758
leaq 0x168(%rsp), %rdi
callq 0x4758
leaq 0x1a8(%rsp), %rdi
callq 0x4758
leaq 0x1c8(%rsp), %rdi
callq 0x4758
leaq 0x1f8(%rsp), %rdi
callq 0x4290
jmp 0x14236
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x141ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x141a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x14187
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x1417a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x4758
leaq 0xe0(%rsp), %rdi
callq 0x4758
leaq 0xdf(%rsp), %rdi
callq 0x43e0
leaq 0x100(%rsp), %rdi
callq 0x4758
leaq 0x120(%rsp), %rdi
callq 0x4758
testb $0x1, 0xb7(%rsp)
jne 0x141ba
jmp 0x141c9
movq 0x10(%rsp), %rdi
movl $0x88, %esi
callq 0x4370
jmp 0x141cb
leaq 0x168(%rsp), %rdi
callq 0x4758
leaq 0x1a8(%rsp), %rdi
callq 0x4758
leaq 0x1c8(%rsp), %rdi
callq 0x4758
leaq 0x1f8(%rsp), %rdi
callq 0x4290
jmp 0x14246
movq 0x3d0(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x1422a
movq (%rsp), %rdi
callq 0x6b10
movq (%rsp), %rdi
movl $0x88, %esi
callq 0x4370
movq $0x0, 0x3e0(%rsp)
movq 0x3e0(%rsp), %rax
addq $0x3e8, %rsp            # imm = 0x3E8
retq
movq 0x1f0(%rsp), %rdi
callq 0x46a0
nopw %cs:(%rax,%rax)