// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
movq %r8, 0x58(%rsp)
movq %rcx, %rbx
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, 0x38(%rsp)
movl 0xa8(%rsp), %r12d
cmpl $0x2, 0x78(%rcx)
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
jl 0x26969
movq 0x2d6d4(%rip), %r14     # 0x53fe8
leaq 0x1eb12(%rip), %rsi     # 0x4542d
movl $0xb, %edx
movq %r14, %rdi
callq 0x7340
movq 0x8(%r15), %rsi
subq (%r15), %rsi
sarq $0x2, %rsi
imulq %r13, %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 (%r15), %rax
movq 0x8(%r15), %rdx
cmpq %rax, %rdx
setne %sil
movq 0xa0(%rsp), %rcx
movl (%rcx), %ecx
cmpl %r12d, %ecx
setl %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0x26c01
movl $0x2, %ebp
xorl %r8d, %r8d
movq %rbx, 0x50(%rsp)
movl $0xc, %ebx
movq %r15, 0x20(%rsp)
leaq 0x1(%r8), %rsi
movq %rsi, 0x18(%rsp)
leaq (%r8,%r8,2), %r9
movslq 0x4(%rax,%r9,4), %rsi
cmpb $0x1, (%rax,%r9,4)
movq %rbp, 0x48(%rsp)
movq %rbx, 0x40(%rsp)
jne 0x269d6
movq 0x8(%rsp), %rdi
jmp 0x269db
movq 0x10(%rsp), %rdi
movq 0xb0(%rdi), %rdi
movq (%rdi,%rsi,8), %rsi
testb $0x1, 0x40(%rsi)
jne 0x26bcc
movq %rdx, %rsi
subq %rax, %rsi
sarq $0x2, %rsi
imulq %r13, %rsi
cmpq %rsi, 0x18(%rsp)
jae 0x26bcc
cmpl %r12d, %ecx
jge 0x26bcc
movq %r8, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movb (%rax,%r9,4), %dl
cmpb (%rax,%rbx), %dl
je 0x26ba2
leaq -0x1(%rbp), %rcx
testb %dl, %dl
movq %rcx, %rdx
cmovneq %r8, %rdx
cmoveq %r8, %rcx
leaq (%rdx,%rdx,2), %rdx
movslq 0x4(%rax,%rdx,4), %rdx
leaq (%rcx,%rcx,2), %rcx
movslq 0x4(%rax,%rcx,4), %r13
movq 0x8(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rdx, 0x60(%rsp)
movq (%rax,%rdx,8), %r12
movq %r12, %rdi
movq 0x38(%rsp), %r14
movq %r14, %rsi
callq 0x2b7b8
movq 0x10(%rsp), %rax
movq 0xb0(%rax), %rax
movq %r13, %r15
movq (%rax,%r13,8), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x2b7b8
movq 0x50(%rsp), %r14
movl 0x78(%r14), %ecx
movq %r12, %rdi
movq %r13, %rsi
movq 0x58(%rsp), %rdx
callq 0x25429
testb %al, %al
je 0x26b77
cmpl $0x4, 0x78(%r14)
movq 0x60(%rsp), %r13
jl 0x26b47
movl $0x1e, %edx
movq 0x2d51c(%rip), %r14     # 0x53fe8
movq %r14, %rdi
leaq 0x1e963(%rip), %rsi     # 0x45439
callq 0x7340
movq %r14, %rdi
movl %r13d, %esi
callq 0x75d0
movq %rax, %r12
movl $0x13, %edx
movq %rax, %rdi
leaq 0x1e960(%rip), %rsi     # 0x45458
callq 0x7340
movq %r12, %rdi
movl %r15d, %esi
callq 0x75d0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0x1e952(%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
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %r13d, %ecx
movl %r15d, %r8d
movl $0x1, %r9d
callq 0x25907
movq 0xa0(%rsp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
jmp 0x26b81
movq 0xa0(%rsp), %rax
movl (%rax), %ecx
movq 0x20(%rsp), %r15
movl 0xa8(%rsp), %r12d
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
movq (%r15), %rax
movq 0x8(%r15), %rdx
movq %rdx, %rsi
subq %rax, %rsi
sarq $0x2, %rsi
imulq %r13, %rsi
cmpq %rsi, %rbp
jae 0x26bcc
incq %rbp
addq $0xc, %rbx
cmpl %r12d, %ecx
jl 0x26a1c
movq %rdx, %rsi
subq %rax, %rsi
sarq $0x2, %rsi
imulq %r13, %rsi
movq 0x18(%rsp), %rdi
cmpq %rsi, %rdi
movq 0x48(%rsp), %rbp
movq 0x40(%rsp), %rbx
jae 0x26c01
incq %rbp
addq $0xc, %rbx
movq %rdi, %r8
cmpl %r12d, %ecx
jl 0x269ac
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq