// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r8, 0x18(%rsp)
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
movsd 0x30(%rcx), %xmm1
movsd 0x28(%rsi), %xmm0
movaps %xmm0, 0xa0(%rsp)
movsd 0x28(%rdx), %xmm0
movaps %xmm0, 0xb0(%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
cmpl $0x3, 0x78(%rcx)
movsd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
jl 0x1fada
movq 0x2a528(%rip), %rdi     # 0x49fe8
leaq 0x17ac2(%rip), %rsi     # 0x37589
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movsd 0x30(%r14), %xmm0
leaq 0x50(%rsp), %rcx
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1d2c7
movsd 0x30(%r14), %xmm0
leaq 0x70(%rsp), %rcx
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1d2c7
movq %r12, 0x20(%rsp)
movq %r15, 0x28(%rsp)
andq $0x0, 0x40(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq %r14, 0x8(%rsp)
cmpl $0x3, 0x78(%r14)
jl 0x1fb47
movq 0x2a4b5(%rip), %rdi     # 0x49fe8
leaq 0x17a6b(%rip), %rsi     # 0x375a5
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq %rbx, 0x98(%rsp)
movsd 0x17059(%rip), %xmm1    # 0x36bb0
movapd 0xa0(%rsp), %xmm3
unpcklps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
movapd 0x17055(%rip), %xmm2    # 0x36bc0
subpd %xmm2, %xmm3
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
addsd %xmm3, %xmm0
movsd 0x10(%rsp), %xmm3
mulsd %xmm3, %xmm0
cvttsd2si %xmm0, %r15d
incl %r15d
movapd 0xb0(%rsp), %xmm4
unpcklps %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
subpd %xmm2, %xmm4
movapd %xmm4, %xmm0
unpckhpd %xmm4, %xmm0            # xmm0 = xmm0[1],xmm4[1]
addsd %xmm4, %xmm0
mulsd %xmm3, %xmm0
cvttsd2si %xmm0, %eax
incl %eax
movl %eax, 0x10(%rsp)
xorl %ebp, %ebp
pushq $0x38
popq %r14
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
cqto
idivq %r14
cmpq %rax, %rbp
jae 0x1fc7a
imulq $0x38, %rbp, %r13
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rax
subq %rsi, %rax
cqto
idivq %r14
cmpq %rax, %r12
jae 0x1fc72
movq 0x50(%rsp), %rdi
cmpb $0x1, 0x18(%rdi,%r13)
jne 0x1fc09
cmpb $0x0, 0x18(%rsi,%rbx)
jne 0x1fc66
addq %r13, %rdi
addq %rbx, %rsi
movq 0x8(%rsp), %rax
movl 0x78(%rax), %r9d
movl %r15d, %edx
movl 0x10(%rsp), %ecx
movq 0x18(%rsp), %r8
callq 0x1ee45
testb %al, %al
je 0x1fc66
movq 0x50(%rsp), %rax
movq 0x70(%rsp), %rcx
movl (%rcx,%rbx), %ecx
addl (%rax,%r13), %ecx
movl %ebp, 0x8c(%rsp)
movl %r12d, 0x90(%rsp)
movl %ecx, 0x94(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x8c(%rsp), %rsi
callq 0x28406
incq %r12
addq $0x38, %rbx
jmp 0x1fbde
incq %rbp
jmp 0x1fbbd
movq 0x8(%rsp), %rax
cmpl $0x2, 0x78(%rax)
movq 0x98(%rsp), %r14
jle 0x1fcc5
movq 0x2a354(%rip), %rdi     # 0x49fe8
leaq 0x179d5(%rip), %rsi     # 0x37670
callq 0x72b0
movq %rax, %rdi
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
pushq $0xc
popq %rcx
cqto
idivq %rcx
movq %rax, %rsi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
cmpq %rsi, %rdi
je 0x1ff15
leaq -0x29d(%rip), %rdx      # 0x1fa42
callq 0x285ad
movq 0x8(%rsp), %rbx
movslq (%rbx), %rcx
movq 0x28(%r14), %rax
imulq %rcx, %rax
movq %rax, %xmm0
movq 0x16eaf(%rip), %xmm4    # 0x36bb0
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
movapd 0x16eb3(%rip), %xmm5    # 0x36bc0
subpd %xmm5, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movl 0x4(%rbx), %eax
subl %ecx, %eax
cvtsi2sd %eax, %xmm0
cvtsi2sd %r15d, %xmm2
movsd 0x16e5d(%rip), %xmm3    # 0x36b90
mulsd %xmm3, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r10d
movl 0x60(%rbx), %eax
movq 0x28(%rsp), %r15
imulq 0x28(%r15), %rcx
movq %rcx, %xmm1
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
subpd %xmm5, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
cvtsi2sdl 0x10(%rsp), %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %r11d
subq $0x8, %rsp
leaq 0x58(%rsp), %r9
xorpd %xmm0, %xmm0
movq 0x28(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq 0x20(%rsp), %r8
pushq %r11
pushq %r10
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
leaq 0x98(%rsp), %rax
pushq %rax
callq 0x22cc2
addq $0x30, %rsp
movl 0x78(%rbx), %eax
cmpl $0x3, %eax
jl 0x1fe5d
movq 0x2a217(%rip), %rdi     # 0x49fe8
leaq 0x17845(%rip), %rsi     # 0x3761d
callq 0x72b0
movq 0xb8(%r14), %rsi
subq 0xb0(%r14), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x71d0
leaq 0x17849(%rip), %rsi     # 0x37647
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movl 0x78(%rbx), %eax
cmpl $0x3, %eax
jl 0x1fe5d
movq 0x2a1cb(%rip), %rdi     # 0x49fe8
leaq 0x1765c(%rip), %rsi     # 0x37480
callq 0x72b0
movq 0xb8(%r15), %rsi
subq 0xb0(%r15), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x71d0
leaq 0x177fd(%rip), %rsi     # 0x37647
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movl 0x78(%rbx), %eax
movl 0x50(%rbx), %ebx
movl 0xc8(%r14), %ebp
cmpl $0x2, %eax
jl 0x1fe99
movq 0x2a175(%rip), %rdi     # 0x49fe8
leaq 0x176a7(%rip), %rsi     # 0x37521
callq 0x72b0
movq %rax, %rdi
movl %ebp, %esi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
movq 0x8(%rsp), %rax
movl 0x78(%rax), %eax
movq 0x18(%rsp), %rcx
cmpb $0x1, 0x9(%rcx)
jne 0x1fee2
cmpl %ebx, %ebp
jg 0x1fee2
cmpl $0x3, %eax
jl 0x1fec8
movq 0x2a134(%rip), %rdi     # 0x49fe8
leaq 0x17798(%rip), %rsi     # 0x37653
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movq 0x28(%rsp), %rdx
callq 0x1dd6b
movq 0x8(%rsp), %rax
movl 0x78(%rax), %eax
cmpl $0x2, %eax
jl 0x1ff57
movq 0x2a0fa(%rip), %rdi     # 0x49fe8
leaq 0x1763e(%rip), %rsi     # 0x37533
callq 0x72b0
movl 0xc8(%r14), %esi
subl %ebp, %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
jmp 0x1ff57
movq 0x8(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x1ff3b
movq 0x2a0c1(%rip), %rdi     # 0x49fe8
leaq 0x176dc(%rip), %rsi     # 0x3760a
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movq 0x28(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %r8
callq 0x1e952
leaq 0x30(%rsp), %rdi
callq 0x283ca
leaq 0x70(%rsp), %rdi
callq 0x22b92
leaq 0x50(%rsp), %rdi
callq 0x22b92
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1ff94
jmp 0x1ff94
movq %rax, %rbx
jmp 0x1ffa1
jmp 0x1ff94
jmp 0x1ff94
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x283ca
leaq 0x70(%rsp), %rdi
callq 0x22b92
leaq 0x50(%rsp), %rdi
callq 0x22b92
movq %rbx, %rdi
callq 0x75e0