// File: readmapping[P]alfalfa/src/mapper.cpp
// Function: pairedMatch6(sparseSA const&, read_t&, read_t&, align_opt const&, paired_opt const&)
void pairedMatch6(const sparseSA& sa, read_t & mate1, read_t & mate2, const align_opt & alnOptions, const paired_opt & pairedOpt){
    int editDist1 = (int)(alnOptions.errorPercent*mate1.sequence.length())+1;
    int editDist2 = (int)(alnOptions.errorPercent*mate2.sequence.length())+1;
    //FIND CANDIDATE REGIONS FOR BOTH MATES
    vector<lis_t>  lisIntervals1;
    vector<lis_t>  lisIntervals2;
    if(alnOptions.print >= 3) cerr << "calculate LIS of both mates"  << endl;
    calculateCandRegions(sa, mate1, alnOptions, lisIntervals1, alnOptions.errorPercent);
    calculateCandRegions(sa, mate2, alnOptions, lisIntervals2, alnOptions.errorPercent);
    //FILTER LIS: ONLY THOSE THAT PAIR : PUT IN LIST OF LISCOUPLE 
    vector<LIScouple_t>  lisIntervalsFiltered;
    if(alnOptions.print >= 3) cerr << "filter LIS of both mates using pairing"  << endl;
    for(size_t i = 0; i < lisIntervals1.size(); i++){
        for(size_t j = 0; j < lisIntervals2.size(); j++){
            if(!(lisIntervals1[i].extended && lisIntervals2[j].extended) && isConcordantLIS(lisIntervals1[i], lisIntervals2[j], editDist1, editDist2, pairedOpt, alnOptions.print))
                lisIntervalsFiltered.push_back(LIScouple_t(i,j,lisIntervals1[i].score+lisIntervals2[j].score));
        }
    }
    if(alnOptions.print >= 3) cerr << "number of paired LIS in filtered list " << lisIntervalsFiltered.size()  << endl;
    //RESCUE IF NO PAIRED LIS WERE FOUND
    if(lisIntervalsFiltered.empty()){
        if(alnOptions.print >= 2) cerr << "#EMPTYFILTEREDLIST"  << endl;
        pairedMatch1(sa, mate1, mate2, alnOptions, pairedOpt);
    }
    else{
        sort(lisIntervalsFiltered.begin(),lisIntervalsFiltered.end(),compLIScouple);
        //FIND ALIGNMENTS FOR FILTERED LIST OF ALIGNMENTS
        //BE NICE AND GIVE THE OPTION OF LOWER MINSCORE
        int minScore1 = (int) (mate1.sequence.length()*alnOptions.match + (alnOptions.mismatch-alnOptions.match)*(editDist1*1.5));
        int minScore2 = (int) (mate2.sequence.length()*alnOptions.match + (alnOptions.mismatch-alnOptions.match)*(editDist2*1.5));
        processLisIntervalsSimultaneous(sa, mate1, mate2, alnOptions, pairedOpt, lisIntervals1, lisIntervals2, lisIntervalsFiltered, 
                alnOptions.maxAlnCount, 0, minScore1, minScore2);
        if(alnOptions.print >= 3) cerr << "first  mate resulted in " << mate1.alignments.size() << " alignments" << endl;
        if(alnOptions.print >= 3) cerr << "second mate resulted in " << mate2.alignments.size() << " alignments" << endl;
        //FIND DISCORDANT ALIGNMENTS AMONGST HIGHEST SCORING UNPAIRED ALIGNMENTS
        int maxPairedAlignments = alnOptions.alignmentCount+1;
        int pairedAlignments = mate1.pairedAlignmentCount;
        if(alnOptions.print >= 2) cerr << "#CONCORDANTCOUNT " << pairedAlignments << endl;
        if(pairedOpt.discordant && pairedAlignments < maxPairedAlignments){
            if(alnOptions.print >= 3) cerr << "search discordant alignments" << endl;
            calculateDiscordantAlignments(sa, mate1, mate2);
        }
        if(alnOptions.print >= 2) cerr << "#DISCORDANTCOUNT " << mate1.pairedAlignmentCount-pairedAlignments << endl;
    }
}

// Assembly:
subq $0x208, %rsp            # imm = 0x208
movq %rdi, 0x200(%rsp)
movq %rsi, 0x1f8(%rsp)
movq %rdx, 0x1f0(%rsp)
movq %rcx, 0x1e8(%rsp)
movq %r8, 0x1e0(%rsp)
movq 0x1e8(%rsp), %rax
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x108(%rsp)
movq 0x1f8(%rsp), %rdi
addq $0x20, %rdi
callq 0x8630
movsd 0x108(%rsp), %xmm0
movq %rax, %xmm1
movaps 0x36795(%rip), %xmm2    # 0x7db70
movaps %xmm2, 0x110(%rsp)
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x36791(%rip), %xmm2    # 0x7db80
movaps %xmm2, 0x120(%rsp)
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
incl %eax
movl %eax, 0x1dc(%rsp)
movq 0x1e8(%rsp), %rax
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x138(%rsp)
movq 0x1f0(%rsp), %rdi
addq $0x20, %rdi
callq 0x8630
movaps 0x110(%rsp), %xmm3
movaps 0x120(%rsp), %xmm2
movsd 0x138(%rsp), %xmm0
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl $0x1, %eax
movl %eax, 0x1d8(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x4e460
leaq 0x1a8(%rsp), %rdi
callq 0x4e460
movq 0x1e8(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x474f7
movq 0x4fb40(%rip), %rdi     # 0x96ff0
leaq 0x36f72(%rip), %rsi     # 0x7e429
callq 0x8360
movq %rax, 0x100(%rsp)
jmp 0x474c6
movq 0x100(%rsp), %rdi
movq 0x4fadb(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x474dc
jmp 0x474f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x47d0f
movq 0x200(%rsp), %rdi
movq 0x1f8(%rsp), %rsi
movq 0x1e8(%rsp), %rdx
movsd 0x30(%rdx), %xmm0
leaq 0x1c0(%rsp), %rcx
callq 0x429c0
jmp 0x47523
movq 0x200(%rsp), %rdi
movq 0x1f0(%rsp), %rsi
movq 0x1e8(%rsp), %rdx
movsd 0x30(%rdx), %xmm0
leaq 0x1a8(%rsp), %rcx
callq 0x429c0
jmp 0x4754f
leaq 0x180(%rsp), %rdi
callq 0x4e940
movq 0x1e8(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x475c5
movq 0x4fa7f(%rip), %rdi     # 0x96ff0
leaq 0x36ecd(%rip), %rsi     # 0x7e445
callq 0x8360
movq %rax, 0xf8(%rsp)
jmp 0x47587
movq 0xf8(%rsp), %rdi
movq 0x4fa1a(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4759d
jmp 0x475c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x4fb90
jmp 0x47d0f
movq $0x0, 0x178(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0xf0(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x4c4b0
movq %rax, %rcx
movq 0xf0(%rsp), %rax
cmpq %rcx, %rax
jae 0x477b7
movq $0x0, 0x170(%rsp)
movq 0x170(%rsp), %rax
movq %rax, 0xe8(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x4c4b0
movq %rax, %rcx
movq 0xe8(%rsp), %rax
cmpq %rcx, %rax
jae 0x4779c
movq 0x178(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0x4c850
testb $0x1, 0x18(%rax)
je 0x47679
movq 0x170(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x4c850
testb $0x1, 0x18(%rax)
jne 0x47781
movq 0x178(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0x4c850
movq %rax, 0xd8(%rsp)
movq 0x170(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x4c850
movq 0xd8(%rsp), %rdi
movq %rax, %rsi
movl 0x1dc(%rsp), %edx
movl 0x1d8(%rsp), %ecx
movq 0x1e0(%rsp), %r8
movq 0x1e8(%rsp), %rax
movl 0x78(%rax), %r9d
callq 0x45c70
movb %al, 0xe7(%rsp)
jmp 0x476e6
movb 0xe7(%rsp), %al
testb $0x1, %al
jne 0x476f6
jmp 0x47781
movq 0x178(%rsp), %rsi
movl %esi, %eax
movl %eax, 0xd0(%rsp)
movl 0x170(%rsp), %eax
movl %eax, 0xd4(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x4c850
movl (%rax), %eax
movl %eax, 0xcc(%rsp)
movq 0x170(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x4c850
movl 0xcc(%rsp), %ecx
movl 0xd0(%rsp), %esi
movl 0xd4(%rsp), %edx
movl (%rax), %eax
addl %eax, %ecx
leaq 0x164(%rsp), %rdi
callq 0x4e980
jmp 0x47768
leaq 0x180(%rsp), %rdi
leaq 0x164(%rsp), %rsi
callq 0x4e950
jmp 0x4777f
jmp 0x47781
jmp 0x47783
movq 0x170(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x170(%rsp)
jmp 0x4760e
jmp 0x4779e
movq 0x178(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x178(%rsp)
jmp 0x475d1
movq 0x1e8(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x47821
movq 0x4f824(%rip), %rdi     # 0x96ff0
leaq 0x36d3d(%rip), %rsi     # 0x7e510
callq 0x8360
movq %rax, 0xc0(%rsp)
jmp 0x477e2
leaq 0x180(%rsp), %rdi
callq 0x4e9b0
movq 0xc0(%rsp), %rdi
movq %rax, %rsi
callq 0x8100
movq %rax, 0xb8(%rsp)
jmp 0x47809
movq 0xb8(%rsp), %rdi
movq 0x4f798(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4781f
jmp 0x47821
leaq 0x180(%rsp), %rdi
callq 0x4e9d0
testb $0x1, %al
jne 0x47834
jmp 0x478ab
movq 0x1e8(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x47877
movq 0x4f7a7(%rip), %rdi     # 0x96ff0
leaq 0x36c5a(%rip), %rsi     # 0x7e4aa
callq 0x8360
movq %rax, 0xb0(%rsp)
jmp 0x4785f
movq 0xb0(%rsp), %rdi
movq 0x4f742(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x47875
jmp 0x47877
movq 0x200(%rsp), %rdi
movq 0x1f8(%rsp), %rsi
movq 0x1f0(%rsp), %rdx
movq 0x1e8(%rsp), %rcx
movq 0x1e0(%rsp), %r8
callq 0x45380
jmp 0x478a6
jmp 0x47ce0
leaq 0x180(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x4ea70
movq 0xa8(%rsp), %rdi
movq %rax, 0x158(%rsp)
callq 0x4eaa0
movq %rax, 0x150(%rsp)
movq 0x158(%rsp), %rdi
movq 0x150(%rsp), %rsi
leaq -0x5a4(%rip), %rdx      # 0x47350
callq 0x4ea20
jmp 0x478fb
movq 0x1f8(%rsp), %rdi
addq $0x20, %rdi
callq 0x8630
movq %rax, %rdx
movq 0x1e8(%rsp), %rax
movslq (%rax), %rsi
movl %esi, %ecx
imulq %rsi, %rdx
movq %rdx, %xmm1
movaps 0x36244(%rip), %xmm0    # 0x7db70
movaps %xmm0, 0x80(%rsp)
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x36240(%rip), %xmm0    # 0x7db80
movaps %xmm0, 0x90(%rsp)
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movl 0x4(%rax), %eax
subl %ecx, %eax
cvtsi2sd %eax, %xmm0
cvtsi2sdl 0x1dc(%rsp), %xmm2
movsd 0x361ef(%rip), %xmm3    # 0x7db60
movsd %xmm3, 0xa0(%rsp)
mulsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x14c(%rsp)
movq 0x1f0(%rsp), %rdi
addq $0x20, %rdi
callq 0x8630
movaps 0x80(%rsp), %xmm2
movaps 0x90(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm3
movq %rax, %rdx
movq 0x1e8(%rsp), %rax
movslq (%rax), %rsi
movl %esi, %ecx
imulq %rsi, %rdx
movq %rdx, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movl 0x4(%rax), %eax
subl %ecx, %eax
cvtsi2sd %eax, %xmm0
cvtsi2sdl 0x1d8(%rsp), %xmm2
mulsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x148(%rsp)
movq 0x200(%rsp), %rdi
movq 0x1f8(%rsp), %rsi
movq 0x1f0(%rsp), %rdx
movq 0x1e8(%rsp), %rcx
movq 0x1e0(%rsp), %r8
movl 0x60(%rcx), %r9d
movl 0x14c(%rsp), %r10d
movl 0x148(%rsp), %r11d
movq %rsp, %rax
movl %r11d, 0x20(%rax)
movl %r10d, 0x18(%rax)
movl %r9d, 0x10(%rax)
leaq 0x180(%rsp), %r9
movq %r9, 0x8(%rax)
leaq 0x1a8(%rsp), %r9
movq %r9, (%rax)
leaq 0x1c0(%rsp), %r9
xorps %xmm0, %xmm0
callq 0x4ead0
jmp 0x47a84
movq 0x1e8(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x47b01
movq 0x4f557(%rip), %rdi     # 0x96ff0
leaq 0x36a1d(%rip), %rsi     # 0x7e4bd
callq 0x8360
movq %rax, 0x78(%rsp)
jmp 0x47aac
movq 0x1f8(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movq 0x78(%rsp), %rdi
movq %rax, %rsi
callq 0x8100
movq %rax, 0x70(%rsp)
jmp 0x47ad4
movq 0x70(%rsp), %rdi
leaq 0x36a07(%rip), %rsi     # 0x7e4e7
callq 0x8360
movq %rax, 0x68(%rsp)
jmp 0x47aec
movq 0x68(%rsp), %rdi
movq 0x4f4b8(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x47aff
jmp 0x47b01
movq 0x1e8(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x47b7e
movq 0x4f4da(%rip), %rdi     # 0x96ff0
leaq 0x36803(%rip), %rsi     # 0x7e320
callq 0x8360
movq %rax, 0x60(%rsp)
jmp 0x47b29
movq 0x1f0(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x8100
movq %rax, 0x58(%rsp)
jmp 0x47b51
movq 0x58(%rsp), %rdi
leaq 0x3698a(%rip), %rsi     # 0x7e4e7
callq 0x8360
movq %rax, 0x50(%rsp)
jmp 0x47b69
movq 0x50(%rsp), %rdi
movq 0x4f43b(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x47b7c
jmp 0x47b7e
movq 0x1e8(%rsp), %rax
movl 0x50(%rax), %eax
addl $0x1, %eax
movl %eax, 0x144(%rsp)
movq 0x1f8(%rsp), %rax
movl 0xc8(%rax), %eax
movl %eax, 0x140(%rsp)
movq 0x1e8(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x47bfd
movq 0x4f433(%rip), %rdi     # 0x96ff0
leaq 0x367fd(%rip), %rsi     # 0x7e3c1
callq 0x8360
movq %rax, 0x48(%rsp)
jmp 0x47bd0
movq 0x48(%rsp), %rdi
movl 0x140(%rsp), %esi
callq 0x8710
movq %rax, 0x40(%rsp)
jmp 0x47be8
movq 0x40(%rsp), %rdi
movq 0x4f3bc(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x47bfb
jmp 0x47bfd
movq 0x1e0(%rsp), %rax
testb $0x1, 0x9(%rax)
je 0x47c79
movl 0x140(%rsp), %eax
cmpl 0x144(%rsp), %eax
jge 0x47c79
movq 0x1e8(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x47c58
movq 0x4f3c0(%rip), %rdi     # 0x96ff0
leaq 0x368bc(%rip), %rsi     # 0x7e4f3
callq 0x8360
movq %rax, 0x38(%rsp)
jmp 0x47c43
movq 0x38(%rsp), %rdi
movq 0x4f361(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x47c56
jmp 0x47c58
movq 0x200(%rsp), %rdi
movq 0x1f8(%rsp), %rsi
movq 0x1f0(%rsp), %rdx
callq 0x43d30
jmp 0x47c77
jmp 0x47c79
movq 0x1e8(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x47cde
movq 0x4f362(%rip), %rdi     # 0x96ff0
leaq 0x3673e(%rip), %rsi     # 0x7e3d3
callq 0x8360
movq %rax, 0x30(%rsp)
jmp 0x47ca1
movq 0x30(%rsp), %rdi
movq 0x1f8(%rsp), %rax
movl 0xc8(%rax), %esi
movl 0x140(%rsp), %eax
subl %eax, %esi
callq 0x8710
movq %rax, 0x28(%rsp)
jmp 0x47cc9
movq 0x28(%rsp), %rdi
movq 0x4f2db(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x47cdc
jmp 0x47cde
jmp 0x47ce0
leaq 0x180(%rsp), %rdi
callq 0x4fb90
leaq 0x1a8(%rsp), %rdi
callq 0x4e4e0
leaq 0x1c0(%rsp), %rdi
callq 0x4e4e0
addq $0x208, %rsp            # imm = 0x208
retq
leaq 0x1a8(%rsp), %rdi
callq 0x4e4e0
leaq 0x1c0(%rsp), %rdi
callq 0x4e4e0
movq 0x1a0(%rsp), %rdi
callq 0x8730
nopw %cs:(%rax,%rax)