// File: /workspace/github_cpp_makefile_star2_O1/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 $0xa8, %rsp
movsd %xmm0, 0x18(%rsp)
movq %r9, 0x90(%rsp)
movq %r8, 0x88(%rsp)
movq %rcx, %r13
movq %rdi, 0x58(%rsp)
movq %rsi, 0x60(%rsp)
movsd 0x28(%rsi), %xmm0
movaps %xmm0, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movsd 0x28(%rdx), %xmm0
movaps %xmm0, 0x40(%rsp)
movsd 0x30(%rcx), %xmm0
movsd %xmm0, 0x10(%rsp)
movl $0x200, %edi            # imm = 0x200
callq 0x2410b
movq %rax, 0x30(%rsp)
movl $0x200, %edi            # imm = 0x200
callq 0x2410b
cmpl $0x0, 0xe8(%rsp)
movq %rax, 0x8(%rsp)
jle 0x2da29
movq %rax, %rsi
movsd 0x17892(%rip), %xmm0    # 0x44d10
movapd 0x70(%rsp), %xmm3
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
movapd 0x17891(%rip), %xmm1    # 0x44d20
subpd %xmm1, %xmm3
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
addsd %xmm3, %xmm2
movsd 0x10(%rsp), %xmm5
movapd %xmm5, %xmm3
mulsd %xmm2, %xmm3
movsd 0x18(%rsp), %xmm4
mulsd %xmm4, %xmm2
cvttsd2si %xmm2, %eax
movl %eax, 0x28(%rsp)
movapd 0x40(%rsp), %xmm2
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
subpd %xmm1, %xmm2
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
addsd %xmm2, %xmm0
mulsd %xmm0, %xmm4
cvttsd2si %xmm4, %eax
movl %eax, 0x24(%rsp)
cvttsd2si %xmm3, %eax
incl %eax
movl %eax, 0x3c(%rsp)
mulsd %xmm5, %xmm0
cvttsd2si %xmm0, %eax
incl %eax
movl %eax, 0x38(%rsp)
movq 0x58(%rsp), %rax
addq $0x50, %rax
movq %rax, 0x50(%rsp)
xorl %r12d, %r12d
xorl %r14d, %r14d
movl $0x0, 0x40(%rsp)
movl $0x0, 0x10(%rsp)
xorl %r8d, %r8d
movl $0x0, 0x4(%rsp)
movq 0xe0(%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, %r14
jae 0x2da29
movq %r8, 0x70(%rsp)
movq %r14, 0x18(%rsp)
cmpb $0x0, (%rax,%r12)
movslq 0x4(%rax,%r12), %rax
movq 0x90(%rsp), %rcx
cmovneq 0x88(%rsp), %rcx
movq (%rcx), %rbx
movq %r13, %rbp
imulq $0x38, %rax, %r13
cmpb $0x0, 0x4(%rbx,%r13)
leaq (%rbx,%r13), %r15
cmovneq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x24196
movl %eax, %r14d
cmpb $0x0, 0x4(%rbx,%r13)
movq %rbp, %r13
movl 0x10(%rsp), %ebx
cmovnel 0x40(%rsp), %ebx
testb %al, %al
jne 0x2d5c2
cmpl 0x54(%r13), %ebx
jl 0x2d5c2
xorl %ecx, %ecx
jmp 0x2d5f2
movq 0xe0(%rsp), %rax
movq (%rax), %rax
cmpb $0x0, (%rax,%r12)
movl 0x24(%rsp), %eax
cmovnel 0x28(%rsp), %eax
cmpl %eax, (%r15)
setge %al
movq 0x28(%r15), %rcx
subq 0x20(%r15), %rcx
cmpq $0x11, %rcx
setae %cl
orb %al, %cl
cmpl $0x2, 0x78(%r13)
jl 0x2d7d9
movl $0x6, %edx
movq 0x269df(%rip), %r13     # 0x53fe8
movq %r13, %rdi
leaq 0x17a8c(%rip), %rsi     # 0x4509f
movl %ecx, 0x2c(%rsp)
callq 0x7340
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x71c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r13, %rdi
movq %rbp, %r13
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl $0x8, %edx
movq 0x26986(%rip), %rbp     # 0x53fe8
movq %rbp, %rdi
leaq 0x17a3a(%rip), %rsi     # 0x450a6
callq 0x7340
movzbl %r14b, %esi
movq %rbp, %rdi
callq 0x75a0
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
movl $0x7, %edx
movq %rbp, %rdi
leaq 0x179f9(%rip), %rsi     # 0x450af
callq 0x7340
movq %rbp, %rdi
movl %ebx, %esi
callq 0x75d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl $0x8, %edx
movq %rbp, %rdi
leaq 0x179b9(%rip), %rsi     # 0x450b7
callq 0x7340
movzbl 0x2c(%rsp), %esi
movq %rbp, %rdi
callq 0x75a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl $0x9, %edx
movq %rbp, %rdi
leaq 0x17977(%rip), %rsi     # 0x450c0
callq 0x7340
movq 0x28(%r15), %rsi
subq 0x20(%r15), %rsi
sarq $0x4, %rsi
movq %rbp, %rdi
callq 0x71c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl $0xa, %edx
movq %rbp, %rdi
leaq 0x1792f(%rip), %rsi     # 0x450ca
callq 0x7340
movl (%r15), %esi
movq %rbp, %rdi
callq 0x75d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl 0x2c(%rsp), %ecx
testb %cl, %cl
je 0x2d941
movq 0x20(%r15), %rax
movq (%rax), %rsi
movq 0x58(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
leaq 0x98(%rsp), %rcx
callq 0x2c6f4
cmpl $0x5, 0x78(%r13)
movq 0x18(%rsp), %r14
jl 0x2d8e2
movl $0xc, %edx
movq 0x267ca(%rip), %rbx     # 0x53fe8
movq %rbx, %rdi
leaq 0x178ad(%rip), %rsi     # 0x450d5
callq 0x7340
movq %rbx, %rdi
movq %r14, %rsi
callq 0x71c0
movq %rax, %rbx
movl $0x6, %edx
movq %rax, %rdi
leaq 0x176d2(%rip), %rsi     # 0x44f1c
callq 0x7340
movq 0x28(%r15), %rsi
subq 0x20(%r15), %rsi
sarq $0x4, %rsi
movq %rbx, %rdi
callq 0x71c0
movq %rax, %rbx
movl $0xa, %edx
movq %rax, %rdi
leaq 0x1786d(%rip), %rsi     # 0x450e2
callq 0x7340
cmpb $0x0, 0x4(%r15)
leaq 0x17867(%rip), %rsi     # 0x450ed
leaq 0x145d8(%rip), %rax     # 0x41e65
cmovneq %rax, %rsi
movl $0x14, %edx
movl $0x7, %eax
cmovneq %rax, %rdx
movq %rbx, %rdi
callq 0x7340
movl $0x8, %edx
movq %rbx, %rdi
leaq 0x145ef(%rip), %rsi     # 0x41ea5
callq 0x7340
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
leaq 0x20(%r15), %rdx
movq 0xe0(%rsp), %rax
movq (%rax), %rdi
movzbl 0x4(%r15), %ecx
movl %ecx, %esi
xorl $0x1, %esi
shll $0x6, %esi
orq $0x20, %rsi
movq 0xa0(%rsp), %rax
movq 0x98(%rsp), %r10
cmpb $0x1, (%rdi,%r12)
jne 0x2d955
movq 0x60(%rsp), %rbx
addq %rbx, %rsi
subq $0x8, %rsp
movzbl %cl, %r11d
movq 0x58(%rsp), %rdi
movl 0x44(%rsp), %ecx
movl 0xf8(%rsp), %r8d
movl 0x30(%rsp), %r9d
jmp 0x2d97b
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %r14
movq 0x70(%rsp), %r8
jmp 0x2da14
movq 0x68(%rsp), %rbx
addq %rbx, %rsi
subq $0x8, %rsp
movzbl %cl, %r11d
movq 0x58(%rsp), %rdi
movl 0x40(%rsp), %ecx
movl 0x100(%rsp), %r8d
movl 0x2c(%rsp), %r9d
pushq %r11
pushq %rbx
pushq %r10
pushq %rax
pushq %r13
callq 0x22a63
addq $0x30, %rsp
movzbl 0x4(%r15), %edx
movl %edx, %ecx
xorb $0x1, %cl
movzbl %cl, %ecx
addl 0x10(%rsp), %ecx
addl %edx, 0x40(%rsp)
testl %eax, %eax
movq 0x8(%rsp), %rsi
js 0x2d9d2
cmpb $0x1, 0x5c(%r13)
jne 0x2d9b7
cmpl %eax, 0x4(%rsp)
jge 0x2d9d2
testb %dl, %dl
movl $0x0, %ecx
movl 0x10(%rsp), %edi
cmovel %ecx, %edi
movl 0x40(%rsp), %edx
cmovnel %ecx, %edx
movl %edx, 0x40(%rsp)
movl %edi, %ecx
movq 0x60(%rsp), %rdi
movq 0xb8(%rdi), %rdx
subq 0xb0(%rdi), %rdx
shrq $0x3, %rdx
movq 0x68(%rsp), %rdi
movq 0xb8(%rdi), %r8
subq 0xb0(%rdi), %r8
shrq $0x3, %r8
addl %edx, %r8d
movl 0x4(%rsp), %edx
cmpl %eax, %edx
cmovlel %eax, %edx
movl %edx, 0x4(%rsp)
movl %ecx, 0x10(%rsp)
incq %r14
addq $0xc, %r12
cmpl 0xe8(%rsp), %r8d
jl 0x2d52b
movq 0x30(%rsp), %rbp
testq %rbp, %rbp
je 0x2db10
movl $0x8, %edi
movl $0x8, %esi
callq 0x71a0
movq %rax, %r15
movq (%rbp), %rax
movq %rax, (%r15)
movq %r15, %r12
addq $0x8, %r12
movl $0x8, %r14d
addq $-0x8, %r12
movq (%r12), %rbx
testb $0x1, (%rbx)
jne 0x2da84
movq %rbx, %rdi
callq 0x7380
leaq -0x8(%r12), %rax
cmpq %r15, %r12
movq %rax, %r12
jne 0x2da61
jmp 0x2db13
cmpl $0x0, (%rbx)
js 0x2dafd
movq $-0x1, %r13
movslq 0xc(%rbp), %rax
addq %rbx, %rax
cmpq $0x0, 0x8(%rax,%r13,8)
je 0x2daef
movq %r12, %rax
subq %r15, %rax
sarq $0x3, %rax
movslq %r14d, %rcx
cmpq %rcx, %rax
jne 0x2dadb
leal (%r14,%r14), %ebp
movslq %ebp, %rsi
shlq $0x3, %rsi
movq %r15, %rdi
callq 0x7590
movq %rax, %r15
shlq $0x21, %r14
sarq $0x21, %r14
leaq (%rax,%r14,8), %r12
movl %ebp, %r14d
movq 0x30(%rsp), %rbp
movslq 0xc(%rbp), %rax
addq %rbx, %rax
movq 0x8(%rax,%r13,8), %rax
movq %rax, (%r12)
addq $0x8, %r12
movl (%rbx), %eax
sarl %eax
cltq
incq %r13
cmpq %rax, %r13
jl 0x2da90
movq %rbx, %rdi
callq 0x7380
cmpq %r15, %r12
jne 0x2da5d
jmp 0x2db13
xorl %r15d, %r15d
movq %rbp, %rdi
callq 0x7380
movq %r15, %rdi
callq 0x7380
movq 0x8(%rsp), %rbx
testq %rbx, %rbx
je 0x2dc0e
movl $0x8, %edi
movl $0x8, %esi
callq 0x71a0
movq %rax, %r14
movq (%rbx), %rax
movq %rax, (%r14)
movq %r14, %r12
addq $0x8, %r12
movl $0x8, %r15d
addq $-0x8, %r12
movq (%r12), %rbx
testb $0x1, (%rbx)
jne 0x2db7d
movq %rbx, %rdi
callq 0x7380
leaq -0x8(%r12), %rax
cmpq %r14, %r12
movq %rax, %r12
jne 0x2db5a
jmp 0x2dc11
cmpl $0x0, (%rbx)
movq 0x8(%rsp), %rdx
js 0x2dbfb
movq $-0x1, %r13
movslq 0xc(%rdx), %rax
addq %rbx, %rax
cmpq $0x0, 0x8(%rax,%r13,8)
je 0x2dbed
movq %r12, %rax
subq %r14, %rax
sarq $0x3, %rax
movslq %r15d, %rcx
cmpq %rcx, %rax
jne 0x2dbd9
leal (%r15,%r15), %ebp
movslq %ebp, %rsi
shlq $0x3, %rsi
movq %r14, %rdi
callq 0x7590
movq 0x8(%rsp), %rdx
movq %rax, %r14
shlq $0x21, %r15
sarq $0x21, %r15
leaq (%rax,%r15,8), %r12
movl %ebp, %r15d
movslq 0xc(%rdx), %rax
addq %rbx, %rax
movq 0x8(%rax,%r13,8), %rax
movq %rax, (%r12)
addq $0x8, %r12
movl (%rbx), %eax
sarl %eax
cltq
incq %r13
cmpq %rax, %r13
jl 0x2db8e
movq %rbx, %rdi
callq 0x7380
cmpq %r14, %r12
jne 0x2db56
jmp 0x2dc11
xorl %r14d, %r14d
movq 0x8(%rsp), %rdi
callq 0x7380
movq %r14, %rdi
callq 0x7380
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq