// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/mapper.cpp
// Function: pairedMatch2(sparseSA const&, read_t&, read_t&, align_opt const&, paired_opt const&)
void pairedMatch2(const sparseSA& sa, read_t & mate1, read_t & mate2, const align_opt & alnOptions, const paired_opt & pairedOpt){
    //ASSYMETRIC ALIGNMENT STRATEGY: ALIGN 1 MATE + RESCUE
    if(alnOptions.print >= 3) cerr << "matching first mate ..." << endl;
    unpairedMatch(sa, mate1, alnOptions);
    if(alnOptions.print >= 3) cerr << "first mate resulted in " << mate1.alignments.size() << " alignments" << endl;
    sort(mate1.alignments.begin(),mate1.alignments.end(), compAlignments);
    int alnCount = 0;
    int maxPairedAlignments = alnOptions.alignmentCount+1;
    //TRAVERSE ALIGNMENTS FOUND FOR MATE 1 AND FIND CONCORDANT ALIGNMENTS IN WINDOW
    vector<alnScoreInfo_t> mate1Alns;
    for(int j = 0; j < (int) mate1.alignments.size(); j++)
        mate1Alns.push_back(alnScoreInfo_t(true, j, mate1.alignments[j]->alignmentScore));
    sort(mate1Alns.begin(),mate1Alns.end(), compAlnScorePaired);
    vector<alnScoreInfo_t> mate2Alns;
    pairAlignmentToWindow(sa, mate1, mate2, alnOptions, pairedOpt, mate1Alns, mate2Alns, alnCount, maxPairedAlignments);
    if(alnOptions.print >= 3) cerr << "part one has resulted in " << alnCount << " concordant alignments" << endl;
    //OTHER DIRECTION STARTING FROM MATE 2
    if(alnCount < maxPairedAlignments){
        //FILTERED UNPAIRED MATCHING OF MATE 2
        if(alnOptions.print >= 3) cerr << "matching second mate ..." << endl;
        unpairedMatch(sa, mate2, alnOptions);
        if(alnOptions.print >= 3) cerr << "second mate resulted in " << mate2.alignments.size() << " alignments" << endl;
        //TRAVERSE ALIGNMENTS FOUND FOR MATE 2 AND FIND CONCORDANT ALIGNMENTS IN WINDOW
        mate2Alns.clear();
        for(int j = 0; j < (int) mate2.alignments.size(); j++)
            if(!mate2.alignments[j]->paired())
                mate2Alns.push_back(alnScoreInfo_t(false, j, mate2.alignments[j]->alignmentScore));
        sort(mate2Alns.begin(),mate2Alns.end(), compAlnScorePaired);
        pairAlignmentToWindow(sa, mate1, mate2, alnOptions, pairedOpt, mate2Alns, mate1Alns, alnCount, maxPairedAlignments);
        if(alnOptions.print >= 3) cerr << "part two has resulted in " << alnCount << " concordant alignments" << endl;
    }
    //RESCUE: PAIR UNPAIRED ALIGNMENTS
    if(pairedOpt.pairedRescue && alnCount < maxPairedAlignments && 
            max((int)mate1.alignments.size(),(int)mate2.alignments.size())>0){
        if(alnOptions.print >= 2) cerr << "#PAIREDRESCUE" << endl;
        vector<alnScoreInfo_t> pairedOrder;
        for(size_t i = 0; i < mate1.alignments.size(); i++)
            pairedOrder.push_back(alnScoreInfo_t(true, i,mate1.alignments[i]->alignmentScore ));
        for(size_t i = 0; i < mate2.alignments.size(); i++)
            pairedOrder.push_back(alnScoreInfo_t(false, i,mate2.alignments[i]->alignmentScore ));
        sort(pairedOrder.begin(),pairedOrder.end(),compAlnScorePaired);
        pairAlignmentsOrdered(sa, mate1, mate2, alnOptions, pairedOpt, pairedOrder, alnCount, maxPairedAlignments);
    }
    //INCLUDE DISCORDANT ALIGNMENTS
    int pairedAlignments = mate1.pairedAlignmentCount;
    if(alnOptions.print >= 2) cerr << "#CONCORDANTCOUNT " << pairedAlignments << endl;
    if(pairedOpt.discordant && alnCount < maxPairedAlignments)
        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 $0x88, %rsp
movq %r8, %r13
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
cmpl $0x3, 0x78(%rcx)
jl 0x210bf
movq 0x28f3d(%rip), %rdi     # 0x49fe8
leaq 0x16385(%rip), %rsi     # 0x37437
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq %r13, 0x38(%rsp)
movq %r12, 0x40(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1d52e
cmpl $0x3, 0x78(%r14)
jl 0x21122
movq 0x28f03(%rip), %rdi     # 0x49fe8
leaq 0x16363(%rip), %rsi     # 0x3744f
callq 0x72b0
movq 0xb8(%rbx), %rsi
subq 0xb0(%rbx), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x71d0
leaq 0x16535(%rip), %rsi     # 0x37647
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq 0xb0(%rbx), %rdi
movq 0xb8(%rbx), %rsi
leaq -0x6eb6(%rip), %rdx     # 0x1a281
callq 0x255ff
andl $0x0, (%rsp)
movl 0x50(%r14), %eax
movq %rax, 0x48(%rsp)
incl %eax
movq %rax, 0x30(%rsp)
leaq 0x70(%rsp), %r12
andq $0x0, 0x10(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, (%r12)
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbp
movq 0xb0(%rbx), %rax
movq 0xb8(%rbx), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jge 0x211ad
movq (%rax,%r13,8), %rax
movl 0x70(%rax), %eax
movb $0x1, 0x10(%rsp)
movl %r13d, 0x14(%rsp)
movl %eax, 0x18(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x279ba
incq %r13
jmp 0x2116b
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
leaq -0x3224(%rip), %rdx     # 0x1df9a
callq 0x27b9d
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
subq $0x8, %rsp
leaq 0x8(%rsp), %rax
leaq 0x78(%rsp), %r9
movq 0x48(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq 0x40(%rsp), %r13
movq %r13, %r8
pushq 0x38(%rsp)
pushq %rax
pushq %rbp
callq 0x1e084
addq $0x20, %rsp
cmpl $0x2, 0x78(%r14)
jle 0x21247
movq 0x28dd3(%rip), %rdi     # 0x49fe8
leaq 0x164b1(%rip), %rsi     # 0x376cd
callq 0x72b0
movl (%rsp), %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x75c0
leaq 0x16407(%rip), %rsi     # 0x3763c
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
jmp 0x2124a
movl (%rsp), %ebp
cmpl 0x48(%rsp), %ebp
jg 0x213da
cmpl $0x3, 0x78(%r14)
jl 0x21276
movq 0x28d86(%rip), %rdi     # 0x49fe8
leaq 0x161fe(%rip), %rsi     # 0x37467
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1d52e
cmpl $0x3, 0x78(%r14)
jl 0x212cf
movq 0x28d56(%rip), %rdi     # 0x49fe8
leaq 0x161e7(%rip), %rsi     # 0x37480
callq 0x72b0
movq 0xb8(%r15), %rsi
subq 0xb0(%r15), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x71d0
leaq 0x16388(%rip), %rsi     # 0x37647
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x212e0
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbp
leaq 0x50(%rsp), %r12
movq 0xb0(%r15), %rax
movq 0xb8(%r15), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jge 0x21343
movq (%rax,%r13,8), %rdi
callq 0xa166
testb %al, %al
jne 0x2133e
movq 0xb0(%r15), %rax
movq (%rax,%r13,8), %rax
movl 0x70(%rax), %eax
movb $0x0, 0x50(%rsp)
movl %r13d, 0x54(%rsp)
movl %eax, 0x58(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x279ba
incq %r13
jmp 0x212ed
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq -0x33ba(%rip), %rdx     # 0x1df9a
callq 0x27b9d
movq 0x40(%rsp), %r12
movq 0x38(%rsp), %r13
subq $0x8, %rsp
leaq 0x18(%rsp), %r9
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %r13, %r8
pushq 0x38(%rsp)
leaq 0x10(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x1e084
addq $0x20, %rsp
cmpl $0x2, 0x78(%r14)
jle 0x213d7
movq 0x28c43(%rip), %rdi     # 0x49fe8
leaq 0x1633b(%rip), %rsi     # 0x376e7
callq 0x72b0
movl (%rsp), %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x75c0
leaq 0x16277(%rip), %rsi     # 0x3763c
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
jmp 0x213da
movl (%rsp), %ebp
cmpb $0x1, 0x14(%r13)
jne 0x21537
cmpl 0x48(%rsp), %ebp
jg 0x21537
movq 0xb8(%rbx), %rax
subq 0xb0(%rbx), %rax
shrq $0x3, %rax
movq 0xb8(%r15), %rcx
subq 0xb0(%r15), %rcx
shrq $0x3, %rcx
cmpl %ecx, %eax
cmovgl %eax, %ecx
testl %ecx, %ecx
jle 0x21537
cmpl $0x2, 0x78(%r14)
jl 0x21442
movq 0x28bba(%rip), %rdi     # 0x49fe8
leaq 0x1608c(%rip), %rsi     # 0x374c1
callq 0x72b0
movq %rax, %rdi
callq 0x7160
leaq 0x50(%rsp), %r12
andq $0x0, 0x10(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, (%r12)
xorl %r13d, %r13d
leaq 0x4(%rsp), %rbp
movq 0xb0(%rbx), %rax
movq 0xb8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r13
jae 0x2149c
movq (%rax,%r13,8), %rax
movl 0x70(%rax), %eax
movb $0x1, 0x4(%rsp)
movl %r13d, 0x8(%rsp)
movl %eax, 0xc(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x279ba
incq %r13
jmp 0x2145d
xorl %r13d, %r13d
leaq 0x50(%rsp), %r12
leaq 0x4(%rsp), %rbp
movq 0xb0(%r15), %rax
movq 0xb8(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r13
jae 0x214e8
movq (%rax,%r13,8), %rax
movl 0x70(%rax), %eax
movb $0x0, 0x4(%rsp)
movl %r13d, 0x8(%rsp)
movl %eax, 0xc(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x279ba
incq %r13
jmp 0x214a9
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
leaq -0x355f(%rip), %rdx     # 0x1df9a
callq 0x27b9d
movq 0x40(%rsp), %r12
movq 0x38(%rsp), %r13
leaq 0x50(%rsp), %r9
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %r13, %r8
pushq 0x30(%rsp)
leaq 0x8(%rsp), %rax
pushq %rax
callq 0x1e6da
popq %rax
popq %rcx
leaq 0x50(%rsp), %rdi
callq 0x27b78
movl 0xc8(%rbx), %ebp
cmpl $0x2, 0x78(%r14)
jl 0x21569
movq 0x28a9d(%rip), %rdi     # 0x49fe8
leaq 0x15fcf(%rip), %rsi     # 0x37521
callq 0x72b0
movq %rax, %rdi
movl %ebp, %esi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
cmpb $0x1, 0x9(%r13)
jne 0x21588
movq 0x48(%rsp), %rax
cmpl %eax, (%rsp)
jg 0x21588
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x1dd6b
cmpl $0x2, 0x78(%r14)
jl 0x215ba
movq 0x28a52(%rip), %rdi     # 0x49fe8
leaq 0x15f96(%rip), %rsi     # 0x37533
callq 0x72b0
movl 0xc8(%rbx), %esi
subl %ebp, %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
leaq 0x10(%rsp), %rdi
callq 0x27b78
leaq 0x70(%rsp), %rdi
callq 0x27b78
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x215ec
jmp 0x2160a
jmp 0x215fb
jmp 0x215fb
jmp 0x215fb
jmp 0x215ec
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x27b78
jmp 0x215fe
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x27b78
jmp 0x2160d
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x27b78
movq %rbx, %rdi
callq 0x75e0