// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/mapper.cpp
// Function: processLisIntervalsPaired(sparseSA const&, read_t&, read_t&, align_opt const&, std::vector<lis_t, std::allocator<lis_t>> const&, std::vector<lis_t, std::allocator<lis_t>> const&, std::vector<alnScoreInfo_t, std::allocator<alnScoreInfo_t>> const&, int, double, int, int)
inline void processLisIntervalsPaired(const sparseSA& sa, read_t & mate1, read_t & mate2, 
        const align_opt & alnOptions, const vector<lis_t> & lisIntervals1, 
        const vector<lis_t> & lisIntervals2, const vector<alnScoreInfo_t> & pairedOrder, 
        int maxAlnCount, double minCoveragePercent, int minScore1, int minScore2){
    int minCoverage1 = mate1.sequence.length()*minCoveragePercent;
    int minCoverage2 = mate2.sequence.length()*minCoveragePercent;
    int editDist1 = (int)(alnOptions.errorPercent*mate1.sequence.length())+1;
    int editDist2 = (int)(alnOptions.errorPercent*mate2.sequence.length())+1;
    //for every interval, try to align
    size_t lisIndex = 0;
    //trial parameter for performance reasons
    int trialF = 0;
    int trialR = 0;
    //////////////////////
    //MAIN ALIGNMENT LOOP
    //////////////////////
    //tree containing information for uniqueness option
    kbtree_t(qCov) *treeF;
    kbtree_t(qCov) *treeR;
    treeF = kb_init(qCov, KB_DEFAULT_SIZE);
    treeR = kb_init(qCov, KB_DEFAULT_SIZE);
    int maxAlnScore = 0;
    int alnCount = 0;
    while(alnCount < maxAlnCount && lisIndex < pairedOrder.size()){
        const lis_t & cluster = pairedOrder[lisIndex].firstMate ? lisIntervals1[pairedOrder[lisIndex].position] : lisIntervals2[pairedOrder[lisIndex].position];
        bool unique = hasUnique(cluster, cluster.fw ? treeF : treeR);
        bool extend = unique;
        int trial = cluster.fw ? trialF : trialR;
        bool highCoverage = pairedOrder[lisIndex].firstMate ? cluster.score >= minCoverage1 : cluster.score >= minCoverage2;
        bool extensionCriterium = (trial < alnOptions.maxTrial || extend) && (cluster.matches.size() > 1 || highCoverage);        
        if(alnOptions.print >=2 ){
            cerr << "#LISI " << lisIndex << endl;
            cerr << "#UNIQUE " << unique << endl;
            cerr << "#TRIAL " << trial << endl;
            cerr << "#EXTEND " << extensionCriterium << endl;
            cerr << "#LISMEMS " << cluster.matches.size() << endl;
            cerr << "#LISSCORE " << cluster.score << endl;
        }
        if(extensionCriterium){
            //sort matches in this interval according to query position
            const vector<match_t> & matchVector = cluster.matches;
            long chrStart, chrEnd;
            sa.getChromBounds(matchVector[0].ref, chrStart, chrEnd);
            int returnedAlnScore;
            if(alnOptions.print >=5) cerr << "try cluster " << lisIndex << " with " << matchVector.size() << " seeds on " << (cluster.fw ? "forward" : "reverse complemented") << " strand." << endl;
            if(pairedOrder[lisIndex].firstMate)
                returnedAlnScore = extendAlignmentChain(sa.S, cluster.fw ? mate1.sequence : mate1.rcSequence, matchVector, editDist1, minScore1, minCoverage1, alnOptions, chrStart, chrEnd, mate1, cluster.fw);
            else
                returnedAlnScore = extendAlignmentChain(sa.S, cluster.fw ? mate2.sequence : mate2.rcSequence, matchVector, editDist2, minScore2, minCoverage2, alnOptions, chrStart, chrEnd, mate2, cluster.fw);
            //deal with new alignments
            if(cluster.fw) trialF++;
            else trialR++;
            if(returnedAlnScore >= 0 && (!alnOptions.maxTrialBest || maxAlnScore < returnedAlnScore)){
                if(cluster.fw) trialF = 0;
                else trialR = 0;
            }
            alnCount = mate1.alignments.size() + mate2.alignments.size();
            maxAlnScore = max(maxAlnScore, returnedAlnScore);
        }
        lisIndex++;
    }  
    kb_destroy(qCov, treeF);
    kb_destroy(qCov, treeR);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq %rdi, %rbx
movq %rsi, 0x48(%rsp)
movsd 0x28(%rsi), %xmm1
movsd 0x135b3(%rip), %xmm2    # 0x36bb0
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x135b8(%rip), %xmm3    # 0x36bc0
subpd %xmm3, %xmm1
movapd %xmm1, %xmm4
unpckhpd %xmm1, %xmm4            # xmm4 = xmm4[1],xmm1[1]
addsd %xmm1, %xmm4
movapd %xmm4, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0x24(%rsp)
movq %rdx, 0x50(%rsp)
movsd 0x28(%rdx), %xmm1
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x20(%rsp)
movq %rcx, (%rsp)
movsd 0x30(%rcx), %xmm0
mulsd %xmm0, %xmm4
cvttsd2si %xmm4, %eax
incl %eax
movl %eax, 0x3c(%rsp)
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %eax
incl %eax
movl %eax, 0x38(%rsp)
movl $0x200, %edi            # imm = 0x200
callq 0x1c760
movq %rax, 0x18(%rsp)
movl $0x200, %edi            # imm = 0x200
callq 0x1c760
movq %rax, 0x28(%rsp)
movq %rbx, 0x58(%rsp)
leaq 0x50(%rbx), %rax
movq %rax, 0x40(%rsp)
xorl %r14d, %r14d
movl $0x0, 0x14(%rsp)
xorl %r13d, %r13d
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
xorl %r12d, %r12d
cmpl 0xc8(%rsp), %r13d
jge 0x23a69
movq 0xc0(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
cqto
pushq $0xc
popq %rsi
idivq %rsi
cmpq %rax, %r12
jae 0x23a69
movq %r12, 0x30(%rsp)
cmpb $0x0, (%rcx,%r14)
movslq 0x4(%rcx,%r14), %rax
movq 0x70(%rsp), %rcx
cmovneq 0x68(%rsp), %rcx
movq (%rcx), %rbx
imulq $0x38, %rax, %rbp
cmpb $0x0, 0x4(%rbx,%rbp)
leaq (%rbx,%rbp), %r15
movq 0x28(%rsp), %rsi
cmovneq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x1c7dd
movl %eax, %r12d
cmpb $0x0, 0x4(%rbx,%rbp)
movl 0x10(%rsp), %ebx
cmovnel 0xc(%rsp), %ebx
testb %al, %al
jne 0x23753
movq (%rsp), %rax
cmpl 0x54(%rax), %ebx
jl 0x23753
xorl %ebp, %ebp
jmp 0x23785
movq 0xc0(%rsp), %rax
movq (%rax), %rax
cmpb $0x0, (%rax,%r14)
movl 0x20(%rsp), %eax
cmovnel 0x24(%rsp), %eax
cmpl %eax, (%r15)
setge %al
movq 0x28(%r15), %rcx
subq 0x20(%r15), %rcx
cmpq $0x11, %rcx
setae %bpl
orb %al, %bpl
movq (%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x2387c
movq %r14, 0x60(%rsp)
movq 0x26849(%rip), %r14     # 0x49fe8
movq %r14, %rdi
leaq 0x138b6(%rip), %rsi     # 0x3705f
callq 0x72b0
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
leaq 0x13899(%rip), %rsi     # 0x37066
callq 0x72b0
movzbl %r12b, %esi
movq %rax, %rdi
callq 0x75a0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
leaq 0x1387f(%rip), %rsi     # 0x3706f
callq 0x72b0
movq %rax, %rdi
movl %ebx, %esi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
leaq 0x13866(%rip), %rsi     # 0x37077
callq 0x72b0
movzbl %bpl, %esi
movq %rax, %rdi
callq 0x75a0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
leaq 0x1384c(%rip), %rsi     # 0x37080
callq 0x72b0
movq 0x28(%r15), %rsi
subq 0x20(%r15), %rsi
sarq $0x4, %rsi
movq %rax, %rdi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
movq 0x60(%rsp), %r14
leaq 0x13826(%rip), %rsi     # 0x3708a
callq 0x72b0
movl (%r15), %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
testb %bpl, %bpl
je 0x23998
movq 0x20(%r15), %rax
movq (%rax), %rsi
movq 0x58(%rsp), %rdi
leaq 0x80(%rsp), %rdx
leaq 0x78(%rsp), %rcx
callq 0x22b12
movq (%rsp), %rax
cmpl $0x5, 0x78(%rax)
movq 0x30(%rsp), %r12
jl 0x2393c
movq 0x2672b(%rip), %rdi     # 0x49fe8
leaq 0x137d1(%rip), %rsi     # 0x37095
callq 0x72b0
movq %rax, %rdi
movq %r12, %rsi
callq 0x71d0
movq %rax, %rdi
leaq 0x135fe(%rip), %rsi     # 0x36edc
callq 0x72b0
movq 0x28(%r15), %rsi
subq 0x20(%r15), %rsi
sarq $0x4, %rsi
movq %rax, %rdi
callq 0x71d0
movq %rax, %rdi
leaq 0x137a1(%rip), %rsi     # 0x370a2
callq 0x72b0
cmpb $0x0, 0x4(%r15)
leaq 0x1379b(%rip), %rsi     # 0x370ad
leaq 0x105cc(%rip), %rcx     # 0x33ee5
cmovneq %rcx, %rsi
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
leaq 0x105f6(%rip), %rsi     # 0x33f25
callq 0x72b0
movq %rax, %rdi
callq 0x7160
leaq 0x20(%r15), %rdx
movq 0xc0(%rsp), %rax
movq (%rax), %rcx
movzbl 0x4(%r15), %eax
movzbl %al, %r11d
movl %eax, %esi
xorl $0x1, %esi
shll $0x6, %esi
orq $0x20, %rsi
movq 0x80(%rsp), %rax
movq 0x78(%rsp), %r10
cmpb $0x1, (%rcx,%r14)
jne 0x239a2
movq 0x48(%rsp), %rbx
addq %rbx, %rsi
subq $0x8, %rsp
movq 0x48(%rsp), %rdi
movl 0x44(%rsp), %ecx
movl 0xd8(%rsp), %r8d
movl 0x2c(%rsp), %r9d
jmp 0x239c4
movq 0x30(%rsp), %r12
jmp 0x23a5d
movq 0x50(%rsp), %rbx
addq %rbx, %rsi
subq $0x8, %rsp
movq 0x48(%rsp), %rdi
movl 0x40(%rsp), %ecx
movl 0xe0(%rsp), %r8d
movl 0x28(%rsp), %r9d
pushq %r11
pushq %rbx
pushq %r10
pushq %rax
pushq 0x28(%rsp)
callq 0x1b714
addq $0x30, %rsp
movzbl 0x4(%r15), %edx
movl %edx, %ecx
xorb $0x1, %cl
movzbl %cl, %ecx
addl 0x10(%rsp), %ecx
addl %edx, 0xc(%rsp)
testl %eax, %eax
js 0x23a1b
movq (%rsp), %rsi
cmpb $0x1, 0x5c(%rsi)
jne 0x23a00
cmpl %eax, 0x14(%rsp)
jge 0x23a1b
testb %dl, %dl
movl $0x0, %ecx
movl 0x10(%rsp), %esi
cmovel %ecx, %esi
movl 0xc(%rsp), %edx
cmovnel %ecx, %edx
movl %edx, 0xc(%rsp)
movl %esi, %ecx
movq 0x48(%rsp), %rsi
movq 0xb8(%rsi), %rdx
subq 0xb0(%rsi), %rdx
shrq $0x3, %rdx
movq 0x50(%rsp), %rsi
movq 0xb8(%rsi), %r13
subq 0xb0(%rsi), %r13
shrq $0x3, %r13
addl %edx, %r13d
movl 0x14(%rsp), %edx
cmpl %eax, %edx
cmovlel %eax, %edx
movl %edx, 0x14(%rsp)
movl %ecx, 0x10(%rsp)
incq %r12
addq $0xc, %r14
jmp 0x236c3
movq 0x18(%rsp), %r15
testq %r15, %r15
je 0x23b55
pushq $0x8
popq %rbx
pushq $0x8
popq %rdi
movq %rdi, %rsi
callq 0x71b0
movq %rax, %r13
movq (%r15), %rax
movq %rax, (%r13)
movq %r13, %r14
addq $0x8, %r14
addq $-0x8, %r14
leaq 0x8(%r14), %rax
cmpq %r13, %rax
je 0x23b58
movq (%r14), %r12
movl (%r12), %eax
testb $0x1, %al
jne 0x23abc
movq %r12, %rdi
callq 0x7360
jmp 0x23a96
movq %r13, (%rsp)
movq %r12, %r13
xorl %ebp, %ebp
movl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jg 0x23b3f
movq 0x18(%rsp), %rcx
movslq 0xc(%rcx), %rcx
movq (%r13,%rcx), %rcx
testq %rcx, %rcx
je 0x23b36
movq %r14, %rax
movq (%rsp), %rdi
subq %rdi, %rax
sarq $0x3, %rax
movslq %ebx, %rdx
cmpq %rdx, %rax
jne 0x23b2b
leal (%rbx,%rbx), %r15d
movslq %r15d, %rsi
shlq $0x3, %rsi
callq 0x7590
shlq $0x21, %rbx
sarq $0x21, %rbx
movq %rax, (%rsp)
leaq (%rax,%rbx,8), %r14
movq 0x18(%rsp), %rax
movslq 0xc(%rax), %rax
movq (%r13,%rax), %rcx
movl %r15d, %ebx
movq %rcx, (%r14)
addq $0x8, %r14
movl (%r12), %eax
incq %rbp
addq $0x8, %r13
jmp 0x23ac5
movq %r12, %rdi
callq 0x7360
movq 0x18(%rsp), %r15
movq (%rsp), %r13
jmp 0x23a96
xorl %r13d, %r13d
movq %r15, %rdi
callq 0x7360
movq %r13, %rdi
callq 0x7360
movq 0x28(%rsp), %r14
testq %r14, %r14
je 0x23c50
pushq $0x8
popq %rdi
movq %rdi, %rsi
callq 0x71b0
movq %rax, %r13
movq (%r14), %rax
movq %rax, (%r13)
movq %r13, %r12
addq $0x8, %r12
pushq $0x8
popq %rbx
addq $-0x8, %r12
leaq 0x8(%r12), %rax
cmpq %r13, %rax
je 0x23c53
movq (%r12), %r15
movl (%r15), %eax
testb $0x1, %al
jne 0x23bbc
movq %r15, %rdi
callq 0x7360
jmp 0x23b95
movq %r13, (%rsp)
movq %r15, %r13
xorl %ebp, %ebp
movl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jg 0x23c3f
movslq 0xc(%r14), %rcx
movq (%r13,%rcx), %rcx
testq %rcx, %rcx
je 0x23c36
movq %r12, %rax
movq (%rsp), %rdi
subq %rdi, %rax
sarq $0x3, %rax
movslq %ebx, %rdx
cmpq %rdx, %rax
jne 0x23c2b
leal (%rbx,%rbx), %r14d
movslq %r14d, %rsi
shlq $0x3, %rsi
callq 0x7590
shlq $0x21, %rbx
sarq $0x21, %rbx
movq %rax, (%rsp)
leaq (%rax,%rbx,8), %r12
movq 0x28(%rsp), %rax
movslq 0xc(%rax), %rax
movq (%r13,%rax), %rcx
movl %r14d, %ebx
movq 0x28(%rsp), %r14
movq %rcx, (%r12)
addq $0x8, %r12
movl (%r15), %eax
incq %rbp
addq $0x8, %r13
jmp 0x23bc5
movq %r15, %rdi
callq 0x7360
movq (%rsp), %r13
jmp 0x23b95
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x7360
movq %r13, %rdi
callq 0x7360
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq