// File: 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:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x220(%rsp)
movq %rsi, 0x218(%rsp)
movq %rdx, 0x210(%rsp)
movq %rcx, 0x208(%rsp)
movq %r8, 0x200(%rsp)
movq 0x208(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x49d6f
movq 0x4d29c(%rip), %rdi     # 0x96ff0
leaq 0x3457c(%rip), %rsi     # 0x7e2d7
callq 0x8360
movq %rax, %rdi
movq 0x4d246(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0x220(%rsp), %rdi
movq 0x218(%rsp), %rsi
movq 0x208(%rsp), %rdx
callq 0x42e50
movq 0x208(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x49df7
movq 0x4d24f(%rip), %rdi     # 0x96ff0
leaq 0x34547(%rip), %rsi     # 0x7e2ef
callq 0x8360
movq %rax, 0xf8(%rsp)
movq 0x218(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movq 0xf8(%rsp), %rdi
movq %rax, %rsi
callq 0x8100
movq %rax, %rdi
leaq 0x34704(%rip), %rsi     # 0x7e4e7
callq 0x8360
movq %rax, %rdi
movq 0x4d1be(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0x218(%rsp), %rdi
addq $0xb0, %rdi
callq 0x4c270
movq %rax, 0x1f8(%rsp)
movq 0x218(%rsp), %rdi
addq $0xb0, %rdi
callq 0x4c2a0
movq %rax, 0x1f0(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x1f0(%rsp), %rsi
leaq -0xd8a6(%rip), %rdx     # 0x3c5a0
callq 0x4c220
movl $0x0, 0x1ec(%rsp)
movq 0x208(%rsp), %rax
movl 0x50(%rax), %eax
addl $0x1, %eax
movl %eax, 0x1e8(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x4e6a0
movl $0x0, 0x1cc(%rsp)
movl 0x1cc(%rsp), %eax
movl %eax, 0xf4(%rsp)
movq 0x218(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movq %rax, %rcx
movl 0xf4(%rsp), %eax
cmpl %ecx, %eax
jge 0x49f45
movl 0x1cc(%rsp), %eax
movl %eax, 0xf0(%rsp)
movq 0x218(%rsp), %rdi
addq $0xb0, %rdi
movslq %eax, %rsi
callq 0xdae0
movl 0xf0(%rsp), %edx
movq (%rax), %rax
movl 0x70(%rax), %ecx
leaq 0x1c0(%rsp), %rdi
movl $0x1, %esi
callq 0x4e660
jmp 0x49efd
leaq 0x1d0(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x4e630
jmp 0x49f14
jmp 0x49f16
movl 0x1cc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1cc(%rsp)
jmp 0x49e83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x4a814
leaq 0x1d0(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
callq 0x4e810
movq 0xe8(%rsp), %rdi
movq %rax, 0x1a8(%rsp)
callq 0x4e840
movq %rax, 0x1a0(%rsp)
movq 0x1a8(%rsp), %rdi
movq 0x1a0(%rsp), %rsi
leaq -0x5dbe(%rip), %rdx     # 0x441d0
callq 0x4e7c0
jmp 0x49f95
leaq 0x188(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
callq 0x4e6a0
movq 0xe0(%rsp), %r9
movq 0x220(%rsp), %rdi
movq 0x218(%rsp), %rsi
movq 0x210(%rsp), %rdx
movq 0x208(%rsp), %rcx
movq 0x200(%rsp), %r8
movl 0x1e8(%rsp), %r10d
movq %rsp, %rax
movl %r10d, 0x10(%rax)
leaq 0x1ec(%rsp), %r10
movq %r10, 0x8(%rax)
movq %r9, (%rax)
leaq 0x1d0(%rsp), %r9
callq 0x44370
jmp 0x4a007
movq 0x208(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x4a0a3
movq 0x4cfd0(%rip), %rdi     # 0x96ff0
leaq 0x34546(%rip), %rsi     # 0x7e56d
callq 0x8360
movq %rax, 0xd8(%rsp)
jmp 0x4a036
movq 0xd8(%rsp), %rdi
movl 0x1ec(%rsp), %esi
callq 0x8710
movq %rax, 0xd0(%rsp)
jmp 0x4a054
movq 0xd0(%rsp), %rdi
leaq 0x34479(%rip), %rsi     # 0x7e4dc
callq 0x8360
movq %rax, 0xc8(%rsp)
jmp 0x4a072
movq 0xc8(%rsp), %rdi
movq 0x4cf2f(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4a088
jmp 0x4a0a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x4a807
movl 0x1ec(%rsp), %eax
cmpl 0x1e8(%rsp), %eax
jge 0x4a3ce
movq 0x208(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x4a0fa
movq 0x4cf24(%rip), %rdi     # 0x96ff0
leaq 0x34234(%rip), %rsi     # 0x7e307
callq 0x8360
movq %rax, 0xc0(%rsp)
jmp 0x4a0e2
movq 0xc0(%rsp), %rdi
movq 0x4cebf(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4a0f8
jmp 0x4a0fa
movq 0x220(%rsp), %rdi
movq 0x210(%rsp), %rsi
movq 0x208(%rsp), %rdx
callq 0x42e50
jmp 0x4a119
movq 0x208(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x4a1ac
movq 0x4cebe(%rip), %rdi     # 0x96ff0
leaq 0x341e7(%rip), %rsi     # 0x7e320
callq 0x8360
movq %rax, 0xb8(%rsp)
jmp 0x4a148
movq 0x210(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movq 0xb8(%rsp), %rdi
movq %rax, %rsi
callq 0x8100
movq %rax, 0xb0(%rsp)
jmp 0x4a176
movq 0xb0(%rsp), %rdi
leaq 0x34362(%rip), %rsi     # 0x7e4e7
callq 0x8360
movq %rax, 0xa8(%rsp)
jmp 0x4a194
movq 0xa8(%rsp), %rdi
movq 0x4ce0d(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4a1aa
jmp 0x4a1ac
leaq 0x188(%rsp), %rdi
callq 0x509d0
movl $0x0, 0x184(%rsp)
movl 0x184(%rsp), %eax
movl %eax, 0xa4(%rsp)
movq 0x210(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movq %rax, %rcx
movl 0xa4(%rsp), %eax
cmpl %ecx, %eax
jge 0x4a2a6
movq 0x210(%rsp), %rdi
addq $0xb0, %rdi
movslq 0x184(%rsp), %rsi
callq 0xdae0
movq (%rax), %rdi
callq 0xe470
movb %al, 0xa3(%rsp)
jmp 0x4a225
movb 0xa3(%rsp), %al
testb $0x1, %al
jne 0x4a28e
jmp 0x4a232
movl 0x184(%rsp), %eax
movl %eax, 0x9c(%rsp)
movq 0x210(%rsp), %rdi
addq $0xb0, %rdi
movslq %eax, %rsi
callq 0xdae0
movl 0x9c(%rsp), %edx
movq (%rax), %rax
movl 0x70(%rax), %ecx
leaq 0x178(%rsp), %rdi
xorl %esi, %esi
callq 0x4e660
jmp 0x4a275
leaq 0x188(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x4e630
jmp 0x4a28c
jmp 0x4a28e
jmp 0x4a290
movl 0x184(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x184(%rsp)
jmp 0x4a1c4
leaq 0x188(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x4e810
movq 0x90(%rsp), %rdi
movq %rax, 0x170(%rsp)
callq 0x4e840
movq %rax, 0x168(%rsp)
movq 0x170(%rsp), %rdi
movq 0x168(%rsp), %rsi
leaq -0x611f(%rip), %rdx     # 0x441d0
callq 0x4e7c0
jmp 0x4a2f6
movq 0x220(%rsp), %rdi
movq 0x218(%rsp), %rsi
movq 0x210(%rsp), %rdx
movq 0x208(%rsp), %rcx
movq 0x200(%rsp), %r8
movl 0x1e8(%rsp), %r9d
movq %rsp, %rax
movl %r9d, 0x10(%rax)
leaq 0x1ec(%rsp), %r9
movq %r9, 0x8(%rax)
leaq 0x1d0(%rsp), %r9
movq %r9, (%rax)
leaq 0x188(%rsp), %r9
callq 0x44370
jmp 0x4a353
movq 0x208(%rsp), %rax
cmpl $0x3, 0x78(%rax)
jl 0x4a3cc
movq 0x4cc88(%rip), %rdi     # 0x96ff0
leaq 0x34218(%rip), %rsi     # 0x7e587
callq 0x8360
movq %rax, 0x88(%rsp)
jmp 0x4a37e
movq 0x88(%rsp), %rdi
movl 0x1ec(%rsp), %esi
callq 0x8710
movq %rax, 0x80(%rsp)
jmp 0x4a39c
movq 0x80(%rsp), %rdi
leaq 0x34131(%rip), %rsi     # 0x7e4dc
callq 0x8360
movq %rax, 0x78(%rsp)
jmp 0x4a3b7
movq 0x78(%rsp), %rdi
movq 0x4cbed(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4a3ca
jmp 0x4a3cc
jmp 0x4a3ce
movq 0x200(%rsp), %rcx
xorl %eax, %eax
testb $0x1, 0x14(%rcx)
movb %al, 0x77(%rsp)
je 0x4a459
movl 0x1ec(%rsp), %ecx
xorl %eax, %eax
cmpl 0x1e8(%rsp), %ecx
movb %al, 0x77(%rsp)
jge 0x4a459
movq 0x218(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movl %eax, 0x164(%rsp)
movq 0x210(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movl %eax, 0x160(%rsp)
leaq 0x164(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x14d40
movq %rax, 0x68(%rsp)
jmp 0x4a44a
movq 0x68(%rsp), %rax
cmpl $0x0, (%rax)
setg %al
movb %al, 0x77(%rsp)
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x4a466
jmp 0x4a6d7
movq 0x208(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x4a4a3
movq 0x4cb75(%rip), %rdi     # 0x96ff0
leaq 0x33edf(%rip), %rsi     # 0x7e361
callq 0x8360
movq %rax, 0x60(%rsp)
jmp 0x4a48e
movq 0x60(%rsp), %rdi
movq 0x4cb16(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4a4a1
jmp 0x4a4a3
leaq 0x148(%rsp), %rdi
callq 0x4e6a0
movq $0x0, 0x140(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x218(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movq %rax, %rcx
movq 0x58(%rsp), %rax
cmpq %rcx, %rax
jae 0x4a586
movq 0x140(%rsp), %rsi
movl %esi, %eax
movl %eax, 0x54(%rsp)
movq 0x218(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdae0
movl 0x54(%rsp), %edx
movq (%rax), %rax
movl 0x70(%rax), %ecx
leaq 0x134(%rsp), %rdi
movl $0x1, %esi
callq 0x4e660
jmp 0x4a52e
leaq 0x148(%rsp), %rdi
leaq 0x134(%rsp), %rsi
callq 0x4e630
jmp 0x4a545
jmp 0x4a547
movq 0x140(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x140(%rsp)
jmp 0x4a4bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x4e870
jmp 0x4a807
movq $0x0, 0x128(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x210(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdac0
movq %rax, %rcx
movq 0x48(%rsp), %rax
cmpq %rcx, %rax
jae 0x4a62f
movq 0x128(%rsp), %rsi
movl %esi, %eax
movl %eax, 0x44(%rsp)
movq 0x210(%rsp), %rdi
addq $0xb0, %rdi
callq 0xdae0
movl 0x44(%rsp), %edx
movq (%rax), %rax
movl 0x70(%rax), %ecx
leaq 0x11c(%rsp), %rdi
xorl %esi, %esi
callq 0x4e660
jmp 0x4a5fd
leaq 0x148(%rsp), %rdi
leaq 0x11c(%rsp), %rsi
callq 0x4e630
jmp 0x4a614
jmp 0x4a616
movq 0x128(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x128(%rsp)
jmp 0x4a592
leaq 0x148(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x4e810
movq 0x38(%rsp), %rdi
movq %rax, 0x110(%rsp)
callq 0x4e840
movq %rax, 0x108(%rsp)
movq 0x110(%rsp), %rdi
movq 0x108(%rsp), %rsi
leaq -0x64a2(%rip), %rdx     # 0x441d0
callq 0x4e7c0
jmp 0x4a679
movq 0x220(%rsp), %rdi
movq 0x218(%rsp), %rsi
movq 0x210(%rsp), %rdx
movq 0x208(%rsp), %rcx
movq 0x200(%rsp), %r8
movl 0x1e8(%rsp), %r9d
movq %rsp, %rax
movl %r9d, 0x8(%rax)
leaq 0x1ec(%rsp), %r9
movq %r9, (%rax)
leaq 0x148(%rsp), %r9
callq 0x44f10
jmp 0x4a6ca
leaq 0x148(%rsp), %rdi
callq 0x4e870
movq 0x218(%rsp), %rax
movl 0xc8(%rax), %eax
movl %eax, 0x104(%rsp)
movq 0x208(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x4a741
movq 0x4c8ef(%rip), %rdi     # 0x96ff0
leaq 0x33cb9(%rip), %rsi     # 0x7e3c1
callq 0x8360
movq %rax, 0x30(%rsp)
jmp 0x4a714
movq 0x30(%rsp), %rdi
movl 0x104(%rsp), %esi
callq 0x8710
movq %rax, 0x28(%rsp)
jmp 0x4a72c
movq 0x28(%rsp), %rdi
movq 0x4c878(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4a73f
jmp 0x4a741
movq 0x200(%rsp), %rax
testb $0x1, 0x9(%rax)
je 0x4a780
movl 0x1ec(%rsp), %eax
cmpl 0x1e8(%rsp), %eax
jge 0x4a780
movq 0x220(%rsp), %rdi
movq 0x218(%rsp), %rsi
movq 0x210(%rsp), %rdx
callq 0x43d30
jmp 0x4a77e
jmp 0x4a780
movq 0x208(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x4a7e5
movq 0x4c85b(%rip), %rdi     # 0x96ff0
leaq 0x33c37(%rip), %rsi     # 0x7e3d3
callq 0x8360
movq %rax, 0x20(%rsp)
jmp 0x4a7a8
movq 0x20(%rsp), %rdi
movq 0x218(%rsp), %rax
movl 0xc8(%rax), %esi
movl 0x104(%rsp), %eax
subl %eax, %esi
callq 0x8710
movq %rax, 0x18(%rsp)
jmp 0x4a7d0
movq 0x18(%rsp), %rdi
movq 0x4c7d4(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4a7e3
jmp 0x4a7e5
leaq 0x188(%rsp), %rdi
callq 0x4e870
leaq 0x1d0(%rsp), %rdi
callq 0x4e870
addq $0x228, %rsp            # imm = 0x228
retq
leaq 0x188(%rsp), %rdi
callq 0x4e870
leaq 0x1d0(%rsp), %rdi
callq 0x4e870
movq 0x1b8(%rsp), %rdi
callq 0x8730
nop