// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/mapper.cpp
// Function: pairAlignmentsOrdered(sparseSA const&, read_t&, read_t&, align_opt const&, paired_opt const&, std::vector<alnScoreInfo_t, std::allocator<alnScoreInfo_t>> const&, int&, int)
void pairAlignmentsOrdered(const sparseSA& sa, read_t & mate1, read_t & mate2, 
        const align_opt & alnOptions, const paired_opt & pairedOpt, 
        const vector<alnScoreInfo_t> & pairedOrder, int & alnCount, int maxPairedAlignments){
    if(alnOptions.print >= 2) cerr << "#COUPLEALN " << pairedOrder.size() << endl;
    size_t i = 0;
    //TRY AND PAIR THE ALIGNMENTS
    while(i < pairedOrder.size() && alnCount < maxPairedAlignments){
        size_t j = i+1;
        bool paired = pairedOrder[i].firstMate ? mate1.alignments[pairedOrder[i].position]->paired() : mate2.alignments[pairedOrder[i].position]->paired();
        if(!paired){
            while(j < pairedOrder.size() && alnCount < maxPairedAlignments){
                if(pairedOrder[i].firstMate != pairedOrder[j].firstMate){
                    int mate1Index = pairedOrder[i].firstMate ? pairedOrder[i].position : pairedOrder[j].position;
                    int mate2Index = pairedOrder[i].firstMate ? pairedOrder[j].position : pairedOrder[i].position;
                    alignment_t * aln1 = mate1.alignments[mate1Index];
                    aln1->setLocalPos(sa);
                    alignment_t * aln2 = mate2.alignments[mate2Index];
                    aln2->setLocalPos(sa);
                    if(isConcordant(aln1, aln2, pairedOpt, alnOptions.print)){
                        if(alnOptions.print >= 4) cerr << "found concordancy between aln " << mate1Index << " of mate 1 and aln " << mate2Index << " of mate 2" << endl;
                        setPaired(sa, mate1, mate2,mate1Index,mate2Index, true);
                        alnCount++;
                    }
                }
                j++;
            }
        }
        i++;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %r12
movq %r8, 0x48(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
cmpl $0x2, 0x78(%rcx)
jl 0x1e741
movq 0x2b8d7(%rip), %rdi     # 0x49fe8
leaq 0x18cd5(%rip), %rsi     # 0x373ed
callq 0x72b0
movq %rax, %rdi
movq 0x8(%r12), %rax
subq (%r12), %rax
pushq $0xc
popq %rcx
cqto
idivq %rcx
movq %rax, %rsi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
movl 0x98(%rsp), %r14d
movq 0x90(%rsp), %r15
pushq $0xc
popq %r13
movq $0x0, (%rsp)
movq %r13, 0x20(%rsp)
movq (%rsp), %rsi
movq (%r12), %rcx
movq 0x8(%r12), %rax
subq %rcx, %rax
cqto
idivq %r13
movq %rsi, 0x18(%rsp)
cmpq %rax, %rsi
jae 0x1e943
cmpl %r14d, (%r15)
jge 0x1e943
movq 0x18(%rsp), %rax
leaq 0x1(%rax), %rdx
movq %rdx, (%rsp)
imulq $0xc, %rax, %rdx
movslq 0x4(%rcx,%rdx), %rax
movq %rdx, 0x50(%rsp)
cmpb $0x1, (%rcx,%rdx)
jne 0x1e7b6
movq 0x8(%rsp), %rcx
jmp 0x1e7bb
movq 0x10(%rsp), %rcx
movq 0xb0(%rcx), %rcx
movq (%rcx,%rax,8), %rdi
callq 0xa166
testb %al, %al
je 0x1e7d7
addq $0xc, 0x20(%rsp)
jmp 0x1e762
movq 0x20(%rsp), %rbp
movq (%rsp), %rbx
movq (%r12), %rcx
movq 0x8(%r12), %rax
subq %rcx, %rax
cqto
idivq %r13
cmpq %rax, %rbx
jae 0x1e7cf
cmpl %r14d, (%r15)
jge 0x1e7cf
movq 0x50(%rsp), %rax
movb (%rcx,%rax), %sil
cmpb (%rcx,%rbp), %sil
je 0x1e937
movq %r12, %r14
movq 0x18(%rsp), %rax
movq %rbx, %rdx
testb %sil, %sil
jne 0x1e826
movq %rbx, %rax
movq 0x18(%rsp), %rdx
imulq $0xc, %rax, %rax
movslq 0x4(%rcx,%rax), %rsi
imulq $0xc, %rdx, %rax
movslq 0x4(%rcx,%rax), %r13
movq 0x8(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rsi, 0x40(%rsp)
movq (%rax,%rsi,8), %r12
movq %r12, %rdi
movq 0x28(%rsp), %r15
movq %r15, %rsi
callq 0x21f20
movq 0x10(%rsp), %rax
movq 0xb0(%rax), %rax
movq %r13, 0x38(%rsp)
movq (%rax,%r13,8), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x21f20
movq 0x30(%rsp), %rax
movl 0x78(%rax), %ecx
movq %r12, %rdi
movq %r13, %rsi
movq 0x48(%rsp), %rdx
callq 0x1d78a
testb %al, %al
movq %r14, %r12
movl 0x98(%rsp), %r14d
movq 0x90(%rsp), %r15
pushq $0xc
popq %r13
je 0x1e937
movq 0x30(%rsp), %rax
cmpl $0x4, 0x78(%rax)
jl 0x1e912
movq 0x2b722(%rip), %rdi     # 0x49fe8
leaq 0x18b2c(%rip), %rsi     # 0x373f9
callq 0x72b0
movq %rax, %rdi
movq 0x40(%rsp), %rsi
callq 0x75c0
movq %rax, %rdi
leaq 0x18b2f(%rip), %rsi     # 0x37418
callq 0x72b0
movq %rax, %rdi
movq 0x38(%rsp), %rsi
callq 0x75c0
movq %rax, %rdi
leaq 0x18b27(%rip), %rsi     # 0x3742c
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r8
pushq $0x1
popq %r9
callq 0x1dc1e
incl (%r15)
incq %rbx
addq $0xc, %rbp
jmp 0x1e7e0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq