// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %r9, 0x8(%rsp)
movq %r8, 0x60(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
cmpl $0x2, 0x78(%rcx)
jl 0x2699f
movq 0x2d6ad(%rip), %r14     # 0x53fe8
leaq 0x1eaeb(%rip), %rsi     # 0x4542d
movl $0xb, %edx
movq %r14, %rdi
callq 0x7340
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x2, %rax
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rsi
movq %r14, %rdi
callq 0x71c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x26c39
movq 0xa0(%rsp), %r14
movl 0xa8(%rsp), %r15d
cmpl %r15d, (%r14)
jge 0x26c39
movl $0x2, %ecx
movq %rcx, 0x28(%rsp)
movl $0xc, %ecx
movq %rcx, 0x20(%rsp)
xorl %ecx, %ecx
leaq (%rcx,%rcx,2), %r12
incq %rcx
movq %rcx, 0x30(%rsp)
cmpb $0x0, (%rax,%r12,4)
movslq 0x4(%rax,%r12,4), %rax
movq 0x18(%rsp), %rcx
cmovneq 0x10(%rsp), %rcx
movq 0xb0(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testb $0x1, 0x40(%rax)
jne 0x26bf7
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq %rcx, 0x30(%rsp)
jae 0x26bf7
cmpl %r15d, (%r14)
jge 0x26bf7
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rbp
movq %r12, 0x38(%rsp)
movb (%rax,%r12,4), %cl
cmpb (%rax,%rbx), %cl
je 0x26bc1
leaq (%rax,%r12,4), %rdx
addq %rbx, %rax
testb %cl, %cl
movq %rax, %rcx
cmovneq %rdx, %rcx
cmoveq %rdx, %rax
movslq 0x4(%rcx), %rcx
movslq 0x4(%rax), %r13
movq 0x10(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rcx, 0x58(%rsp)
movq (%rax,%rcx,8), %r12
movq %r12, %rdi
movl %r15d, %r14d
movq 0x40(%rsp), %r15
movq %r15, %rsi
callq 0x2b8ec
movq 0x18(%rsp), %rax
movq 0xb0(%rax), %rax
movq %r13, 0x50(%rsp)
movq (%rax,%r13,8), %r13
movq %r13, %rdi
movq %r15, %rsi
movl %r14d, %r15d
callq 0x2b8ec
movq 0x48(%rsp), %rax
movl 0x78(%rax), %ecx
movq %r12, %rdi
movq 0x38(%rsp), %r12
movq %r13, %rsi
movq 0xa0(%rsp), %r14
movq 0x60(%rsp), %rdx
callq 0x2551e
testb %al, %al
je 0x26bc1
movq 0x48(%rsp), %rax
cmpl $0x4, 0x78(%rax)
jl 0x26b9a
movl $0x1e, %edx
movq 0x2d4d2(%rip), %r12     # 0x53fe8
movq %r12, %rdi
leaq 0x1e919(%rip), %rsi     # 0x45439
callq 0x7340
movq %r12, %rdi
movq 0x58(%rsp), %rsi
callq 0x75d0
movq %rax, %r12
movl $0x13, %edx
movq %rax, %rdi
leaq 0x1e914(%rip), %rsi     # 0x45458
callq 0x7340
movq %r12, %rdi
movq 0x50(%rsp), %rsi
callq 0x75d0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0x1e904(%rip), %rsi     # 0x4546c
callq 0x7340
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r12, %rdi
movq 0x38(%rsp), %r12
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %r8
movl $0x1, %r9d
callq 0x25a0b
incl (%r14)
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq %rcx, %rbp
jae 0x26bf7
incq %rbp
addq $0xc, %rbx
cmpl %r15d, (%r14)
jl 0x26a5a
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
movq 0x30(%rsp), %rdx
cmpq %rcx, %rdx
jae 0x26c39
movq %rdx, %rcx
incq 0x28(%rsp)
addq $0xc, 0x20(%rsp)
cmpl %r15d, (%r14)
jl 0x269e0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq