// File: /workspace/github_cpp_makefile_star2_O3/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, 0x20(%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 0x23e5b
movq %rax, %r15
movl $0x200, %edi            # imm = 0x200
callq 0x23e5b
movq %rax, 0x8(%rsp)
cmpl $0x0, 0xe8(%rsp)
movq %r15, 0x18(%rsp)
jle 0x2d907
movsd 0x179b4(%rip), %xmm0    # 0x44d10
movapd 0x70(%rsp), %xmm3
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
movapd 0x179b3(%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 0x20(%rsp), %xmm4
mulsd %xmm4, %xmm2
cvttsd2si %xmm2, %eax
movl %eax, 0x30(%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, 0x2c(%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 %ebp, %ebp
movl $0x0, 0x40(%rsp)
movl $0x0, 0x10(%rsp)
xorl %edi, %edi
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, %rbp
jae 0x2d907
movq %rdi, 0x70(%rsp)
movq %rbp, 0x20(%rsp)
cmpb $0x0, (%rax,%r12)
movslq 0x4(%rax,%r12), %rax
movq 0x90(%rsp), %rcx
cmovneq 0x88(%rsp), %rcx
movq %r13, %rbx
movq (%rcx), %r13
imulq $0x38, %rax, %rbp
cmpb $0x0, 0x4(%r13,%rbp)
leaq (%r13,%rbp), %r14
movq 0x8(%rsp), %rsi
cmovneq %r15, %rsi
movq %r14, %rdi
callq 0x23eea
movl %eax, %r15d
cmpb $0x0, 0x4(%r13,%rbp)
movq %rbx, %r13
movl 0x10(%rsp), %ebp
cmovnel 0x40(%rsp), %ebp
testb %al, %al
jne 0x2d4a2
cmpl 0x54(%r13), %ebp
jl 0x2d4a2
xorl %ecx, %ecx
jmp 0x2d4d2
movq 0xe0(%rsp), %rax
movq (%rax), %rax
cmpb $0x0, (%rax,%r12)
movl 0x2c(%rsp), %eax
cmovnel 0x30(%rsp), %eax
cmpl %eax, (%r14)
setge %al
movq 0x28(%r14), %rcx
subq 0x20(%r14), %rcx
cmpq $0x11, %rcx
setae %cl
orb %al, %cl
cmpl $0x2, 0x78(%r13)
jl 0x2d6b9
movl $0x6, %edx
movq 0x26aff(%rip), %r13     # 0x53fe8
movq %r13, %rdi
leaq 0x17bac(%rip), %rsi     # 0x4509f
movl %ecx, 0x34(%rsp)
callq 0x7340
movq %r13, %rdi
movq 0x20(%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 %rbx, %r13
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl $0x8, %edx
movq 0x26aa6(%rip), %rbx     # 0x53fe8
movq %rbx, %rdi
leaq 0x17b5a(%rip), %rsi     # 0x450a6
callq 0x7340
movzbl %r15b, %esi
movq %rbx, %rdi
callq 0x75a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl $0x7, %edx
movq %rbx, %rdi
leaq 0x17b19(%rip), %rsi     # 0x450af
callq 0x7340
movq %rbx, %rdi
movl %ebp, %esi
callq 0x75d0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl $0x8, %edx
movq %rbx, %rdi
leaq 0x17ad9(%rip), %rsi     # 0x450b7
callq 0x7340
movzbl 0x34(%rsp), %esi
movq %rbx, %rdi
callq 0x75a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl $0x9, %edx
movq %rbx, %rdi
leaq 0x17a97(%rip), %rsi     # 0x450c0
callq 0x7340
movq 0x28(%r14), %rsi
subq 0x20(%r14), %rsi
sarq $0x4, %rsi
movq %rbx, %rdi
callq 0x71c0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl $0xa, %edx
movq %rbx, %rdi
leaq 0x17a4f(%rip), %rsi     # 0x450ca
callq 0x7340
movl (%r14), %esi
movq %rbx, %rdi
callq 0x75d0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movl 0x34(%rsp), %ecx
testb %cl, %cl
je 0x2d826
movq 0x20(%r14), %rax
movq (%rax), %rsi
movq 0x58(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
leaq 0x98(%rsp), %rcx
callq 0x2c5ce
cmpl $0x5, 0x78(%r13)
movq 0x20(%rsp), %rbp
jl 0x2d7c2
movl $0xc, %edx
movq 0x268ea(%rip), %rbx     # 0x53fe8
movq %rbx, %rdi
leaq 0x179cd(%rip), %rsi     # 0x450d5
callq 0x7340
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x71c0
movq %rax, %r15
movl $0x6, %edx
movq %rax, %rdi
leaq 0x177f2(%rip), %rsi     # 0x44f1c
callq 0x7340
movq 0x28(%r14), %rsi
subq 0x20(%r14), %rsi
sarq $0x4, %rsi
movq %r15, %rdi
callq 0x71c0
movq %rax, %r15
movl $0xa, %edx
movq %rax, %rdi
leaq 0x1798d(%rip), %rsi     # 0x450e2
callq 0x7340
cmpb $0x0, 0x4(%r14)
leaq 0x17987(%rip), %rsi     # 0x450ed
leaq 0x146f8(%rip), %rax     # 0x41e65
cmovneq %rax, %rsi
movl $0x14, %edx
movl $0x7, %eax
cmovneq %rax, %rdx
movq %r15, %rdi
callq 0x7340
movl $0x8, %edx
movq %r15, %rdi
leaq 0x1470f(%rip), %rsi     # 0x41ea5
callq 0x7340
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
leaq 0x20(%r14), %rdx
movq 0xe0(%rsp), %rax
movq (%rax), %rdi
movzbl 0x4(%r14), %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)
movq 0x18(%rsp), %r15
jne 0x2d83a
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 0x38(%rsp), %r9d
jmp 0x2d860
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %rbp
movq 0x70(%rsp), %rdi
jmp 0x2d8f3
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 0x34(%rsp), %r9d
pushq %r11
pushq %rbx
pushq %r10
pushq %rax
pushq %r13
callq 0x22769
addq $0x30, %rsp
movzbl 0x4(%r14), %edx
movl %edx, %ecx
xorb $0x1, %cl
movzbl %cl, %ecx
addl 0x10(%rsp), %ecx
addl %edx, 0x40(%rsp)
testl %eax, %eax
js 0x2d8b2
cmpb $0x1, 0x5c(%r13)
jne 0x2d897
cmpl %eax, 0x4(%rsp)
jge 0x2d8b2
testb %dl, %dl
movl $0x0, %ecx
movl 0x10(%rsp), %esi
cmovel %ecx, %esi
movl 0x40(%rsp), %edx
cmovnel %ecx, %edx
movl %edx, 0x40(%rsp)
movl %esi, %ecx
movq 0x60(%rsp), %rsi
movq 0xb8(%rsi), %rdx
subq 0xb0(%rsi), %rdx
shrq $0x3, %rdx
movq 0x68(%rsp), %rsi
movq 0xb8(%rsi), %rdi
subq 0xb0(%rsi), %rdi
shrq $0x3, %rdi
addl %edx, %edi
movl 0x4(%rsp), %edx
cmpl %eax, %edx
cmovlel %eax, %edx
movl %edx, 0x4(%rsp)
movl %ecx, 0x10(%rsp)
incq %rbp
addq $0xc, %r12
cmpl 0xe8(%rsp), %edi
jl 0x2d407
testq %r15, %r15
je 0x2da05
movl $0x8, %edi
movl $0x8, %esi
callq 0x71a0
movq %rax, %rbx
movq (%r15), %rax
movq %rax, (%rbx)
movq %rbx, %r12
addq $0x8, %r12
movl $0x8, %r15d
movq 0x8(%rsp), %r13
addq $-0x8, %r12
movq (%r12), %r14
movl (%r14), %ecx
testb $0x1, %cl
jne 0x2d964
movq %r14, %rdi
callq 0x7380
leaq -0x8(%r12), %rax
cmpq %rbx, %r12
movq %rax, %r12
jne 0x2d93e
jmp 0x2da0c
testl %ecx, %ecx
js 0x2d9ed
movq 0x18(%rsp), %rax
movl 0xc(%rax), %eax
movq $-0x1, %r13
movslq %eax, %rdx
addq %r14, %rdx
cmpq $0x0, 0x8(%rdx,%r13,8)
je 0x2d9de
movq %r12, %rcx
subq %rbx, %rcx
sarq $0x3, %rcx
movslq %r15d, %rdx
cmpq %rdx, %rcx
jne 0x2d9c8
leal (%r15,%r15), %ebp
movslq %ebp, %rsi
shlq $0x3, %rsi
movq %rbx, %rdi
callq 0x7590
movq %rax, %rbx
shlq $0x21, %r15
sarq $0x21, %r15
leaq (%rax,%r15,8), %r12
movq 0x18(%rsp), %rax
movl 0xc(%rax), %eax
movl %ebp, %r15d
movslq %eax, %rcx
addq %r14, %rcx
movq 0x8(%rcx,%r13,8), %rcx
movq %rcx, (%r12)
addq $0x8, %r12
movl (%r14), %ecx
movl %ecx, %edx
sarl %edx
movslq %edx, %rdx
incq %r13
cmpq %rdx, %r13
jl 0x2d97b
movq %r14, %rdi
callq 0x7380
cmpq %rbx, %r12
movq 0x8(%rsp), %r13
jne 0x2d93a
jmp 0x2da0c
xorl %ebx, %ebx
movq 0x8(%rsp), %r13
movq 0x18(%rsp), %rdi
callq 0x7380
movq %rbx, %rdi
callq 0x7380
testq %r13, %r13
je 0x2db10
movl $0x8, %edi
movl $0x8, %esi
callq 0x71a0
movq %rax, %rbx
movq (%r13), %rax
movq %rax, (%rbx)
movq %rbx, %r12
addq $0x8, %r12
movl $0x8, %r15d
addq $-0x8, %r12
movq (%r12), %r14
movl (%r14), %ecx
testb $0x1, %cl
jne 0x2da77
movq %r14, %rdi
callq 0x7380
leaq -0x8(%r12), %rax
cmpq %rbx, %r12
movq %rax, %r12
jne 0x2da51
jmp 0x2db12
testl %ecx, %ecx
js 0x2daf8
movl 0xc(%r13), %eax
movq $-0x1, %r13
movslq %eax, %rdx
addq %r14, %rdx
cmpq $0x0, 0x8(%rdx,%r13,8)
je 0x2dae9
movq %r12, %rcx
subq %rbx, %rcx
sarq $0x3, %rcx
movslq %r15d, %rdx
cmpq %rdx, %rcx
jne 0x2dad3
leal (%r15,%r15), %ebp
movslq %ebp, %rsi
shlq $0x3, %rsi
movq %rbx, %rdi
callq 0x7590
movq %rax, %rbx
shlq $0x21, %r15
sarq $0x21, %r15
leaq (%rax,%r15,8), %r12
movq 0x8(%rsp), %rax
movl 0xc(%rax), %eax
movl %ebp, %r15d
movslq %eax, %rcx
addq %r14, %rcx
movq 0x8(%rcx,%r13,8), %rcx
movq %rcx, (%r12)
addq $0x8, %r12
movl (%r14), %ecx
movl %ecx, %edx
sarl %edx
movslq %edx, %rdx
incq %r13
cmpq %rdx, %r13
jl 0x2da86
movq %r14, %rdi
callq 0x7380
cmpq %rbx, %r12
movq 0x8(%rsp), %r13
jne 0x2da4d
jmp 0x2db12
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x7380
movq %rbx, %rdi
callq 0x7380
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq