// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/mapper.cpp
// Function: processLisIntervals(sparseSA const&, read_t&, align_opt const&, std::vector<lis_t, std::allocator<lis_t>> const&, int, int, int, int)
void processLisIntervals(const sparseSA& sa, read_t & read, const align_opt & alnOptions, 
        const vector<lis_t> & lisIntervals, int editDist, int maxAlnCount, int minCoverage, int minScore){
    //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;
    while((int)(read.alignments.size()) < maxAlnCount && lisIndex < lisIntervals.size()){
        bool unique = hasUnique(lisIntervals[lisIndex], lisIntervals[lisIndex].fw ? treeF : treeR);
        bool extend = unique;
        int trial = lisIntervals[lisIndex].fw ? trialF : trialR;
        bool extensionCriterium = (trial < alnOptions.maxTrial || extend) && (lisIntervals[lisIndex].matches.size() > 1 || lisIntervals[lisIndex].score >= minCoverage);
#ifndef NDEBUG
        if(alnOptions.debugFile != NULL){
            int Plength = read.sequence.length();
            printLisData(sa, lisIntervals[lisIndex], alnOptions, lisIndex, extensionCriterium, unique, trial < alnOptions.maxTrial, Plength, editDist);
        }
#endif
        if(alnOptions.print >=2 ){
            cerr << "#LISI " << lisIndex << endl;
            cerr << "#UNIQUE " << unique << endl;
            cerr << "#TRIAL " << trial << endl;
            cerr << "#EXTEND " << extensionCriterium << endl;
            cerr << "#LISMEMS " << lisIntervals[lisIndex].matches.size() << endl;
            cerr << "#LISSCORE " << lisIntervals[lisIndex].score << endl;
        }
        if(extensionCriterium){
            //sort matches in this interval according to query position
            const lis_t & cluster = lisIntervals[lisIndex];
            const vector<match_t> & matchVector = cluster.matches;
            long chrStart, chrEnd;
            sa.getChromBounds(matchVector[0].ref, chrStart, chrEnd);
            if(alnOptions.print >=5) cerr << "try cluster " << lisIndex << " with " << matchVector.size() << " seeds on " << (cluster.fw ? "forward" : "reverse complemented") << " strand." << endl;
            int returnedAlnScore = extendAlignmentChain(sa.S, cluster.fw ? read.sequence : read.rcSequence, matchVector, editDist, minScore, minCoverage, alnOptions, chrStart, chrEnd, read, 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;
            }
            maxAlnScore = max(maxAlnScore, returnedAlnScore);
        }
        lisIndex++;
    }
#ifndef NDEBUG
    if(alnOptions.debugFile != NULL){
        int Plength = read.sequence.length();
        fprintf(alnOptions.debugFile,"$E\n");
        size_t lisAfterIndex =  lisIndex;
        while( lisAfterIndex < lisIntervals.size()){
            printLisData(sa, lisIntervals[lisAfterIndex], alnOptions, lisAfterIndex, false, false, false, Plength, editDist);
            lisAfterIndex++;
        }
        fprintf(alnOptions.debugFile,"#END\n");
    }
#endif         
    kb_destroy(qCov, treeF);
    kb_destroy(qCov, treeR);
    if(alnOptions.print >=5){
        cerr << "stopped matching because: " << endl; 
        if((int)(read.alignments.size()) >= maxAlnCount) cerr << " enough alignments were found."<< endl;
        else if(lisIndex >= lisIntervals.size()) cerr << " no more clusters are available."<< endl;
        else if(lisIntervals[lisIndex].score <= minCoverage) cerr << " no new clusters reach minimum query coverage."<< endl;
        else if(min(trialF,trialR) >= alnOptions.maxTrial) cerr << " max number of extensions without result have been reached."<< endl;
        if(lisIndex < lisIntervals.size()){
            cerr << "remaining clusters map approx to:" << endl;
            for(size_t i = lisIndex; i < lisIntervals.size(); i++){
                //sort this candidate region by query position
                const lis_t & cluster = lisIntervals[i];
                const vector<match_t> & matchVector = cluster.matches;
                long chrStart, chrEnd;
                cerr << "cluster " << i << " with " << matchVector.size() << " seeds and " << cluster.score << " bases covered" << endl;
                sa.getChromBounds(matchVector[0].ref, chrStart, chrEnd);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, 0x34(%rsp)
movl %r8d, 0x4c(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, %rbp
movq %rsi, 0x40(%rsp)
movq %rdi, %r14
movl $0x200, %edi            # imm = 0x200
callq 0x1c760
movq %rax, 0x38(%rsp)
movl $0x200, %edi            # imm = 0x200
callq 0x1c760
movq %rax, %rbx
movq %r14, 0x50(%rsp)
leaq 0x50(%r14), %rax
movq %rax, 0x70(%rsp)
pushq $0x20
popq %r12
movl $0x0, 0x4(%rsp)
xorl %r14d, %r14d
movl $0x0, (%rsp)
xorl %r13d, %r13d
movq %rbp, 0x20(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x10(%rsp), %r15
movq 0x40(%rsp), %rcx
movq 0xb8(%rcx), %rax
subq 0xb0(%rcx), %rax
shrq $0x3, %rax
cmpl 0x34(%rsp), %eax
movq %r12, 0x8(%rsp)
jge 0x1ce3d
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
cqto
pushq $0x38
popq %rsi
idivq %rsi
cmpq %rax, %r13
jae 0x1ce3d
leaq (%rcx,%r12), %rdi
addq $-0x20, %rdi
cmpb $0x0, 0x4(%rdi)
cmovneq 0x38(%rsp), %rbx
movq %rbx, %rsi
callq 0x1c7dd
movl %eax, %ebp
movq 0x10(%rsp), %rax
movq (%rax), %rax
cmpb $0x0, -0x1c(%rax,%r12)
movl 0x4(%rsp), %r12d
cmovnel (%rsp), %r12d
testb %bpl, %bpl
jne 0x1cb81
movq 0x20(%rsp), %rcx
cmpl 0x54(%rcx), %r12d
jl 0x1cb81
xorl %ebx, %ebx
jmp 0x1cbaa
movq 0x8(%rsp), %rdx
movq 0x8(%rax,%rdx), %rcx
subq (%rax,%rdx), %rcx
movb $0x1, %bl
cmpq $0x10, %rcx
ja 0x1cbaa
movq 0x8(%rsp), %rcx
movl 0xb0(%rsp), %edx
cmpl %edx, -0x20(%rax,%rcx)
setge %bl
movq 0x20(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x1ccae
movl %r14d, 0x28(%rsp)
movq 0x2d423(%rip), %r14     # 0x49fe8
movq %r14, %rdi
leaq 0x1a490(%rip), %rsi     # 0x3705f
callq 0x72b0
movq %rax, %rdi
movq %r13, %rsi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
leaq 0x1a475(%rip), %rsi     # 0x37066
callq 0x72b0
movzbl %bpl, %esi
movq %rax, %rdi
callq 0x75a0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
leaq 0x1a45b(%rip), %rsi     # 0x3706f
callq 0x72b0
movq %rax, %rdi
movl %r12d, %esi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
leaq 0x1a441(%rip), %rsi     # 0x37077
callq 0x72b0
movzbl %bl, %esi
movq %rax, %rdi
callq 0x75a0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
leaq 0x1a428(%rip), %rsi     # 0x37080
callq 0x72b0
movq (%r15), %rcx
movq 0x8(%rsp), %r12
movq 0x8(%rcx,%r12), %rsi
subq (%rcx,%r12), %rsi
sarq $0x4, %rsi
movq %rax, %rdi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
movq %r14, %rdi
movl 0x28(%rsp), %r14d
leaq 0x1a3f9(%rip), %rsi     # 0x3708a
callq 0x72b0
movq (%r15), %rcx
movl -0x20(%rcx,%r12), %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
testb %bl, %bl
je 0x1ce10
movq 0x10(%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rsp), %r12
movq (%rbx,%r12), %rax
movq (%rax), %rsi
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0x58(%rsp), %rcx
callq 0x22b12
movq 0x20(%rsp), %rbp
cmpl $0x5, 0x78(%rbp)
jl 0x1cd75
movq 0x2d2f4(%rip), %rdi     # 0x49fe8
leaq 0x1a39a(%rip), %rsi     # 0x37095
callq 0x72b0
movq %rax, %rdi
movq %r13, %rsi
callq 0x71d0
movq %rax, %rdi
leaq 0x1a1c7(%rip), %rsi     # 0x36edc
callq 0x72b0
movq 0x8(%rbx,%r12), %rsi
subq (%rbx,%r12), %rsi
sarq $0x4, %rsi
movq %rax, %rdi
callq 0x71d0
movq %rax, %rdi
leaq 0x1a369(%rip), %rsi     # 0x370a2
callq 0x72b0
cmpb $0x0, -0x1c(%rbx,%r12)
leaq 0x1a362(%rip), %rsi     # 0x370ad
leaq 0x17193(%rip), %rcx     # 0x33ee5
cmovneq %rcx, %rsi
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
leaq 0x171bd(%rip), %rsi     # 0x33f25
callq 0x72b0
movq %rax, %rdi
callq 0x7160
leaq (%rbx,%r12), %rdx
movzbl -0x1c(%rbx,%r12), %eax
movl %eax, %ecx
xorb $0x1, %cl
movzbl %cl, %ecx
shll $0x6, %ecx
movq 0x40(%rsp), %r10
leaq (%r10,%rcx), %rsi
addq $0x20, %rsi
subq $0x8, %rsp
movq 0x78(%rsp), %rdi
movl 0x54(%rsp), %ecx
movl 0xc0(%rsp), %r8d
movl 0xb8(%rsp), %r9d
pushq %rax
pushq %r10
pushq 0x70(%rsp)
pushq 0x80(%rsp)
pushq %rbp
callq 0x1b714
addq $0x30, %rsp
movzbl -0x1c(%rbx,%r12), %edx
movl %edx, %ecx
xorb $0x1, %cl
movzbl %cl, %ecx
addl 0x4(%rsp), %ecx
addl %edx, (%rsp)
testl %eax, %eax
js 0x1ce21
cmpb $0x1, 0x5c(%rbp)
movq 0x18(%rsp), %rbx
jne 0x1cdf5
cmpl %eax, %r14d
jge 0x1ce26
testb %dl, %dl
movl 0x4(%rsp), %edx
movl $0x0, %esi
cmovel %esi, %edx
movl (%rsp), %ecx
cmovnel %esi, %ecx
movl %ecx, (%rsp)
movl %edx, %ecx
jmp 0x1ce26
movq 0x8(%rsp), %r12
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %rbx
jmp 0x1ce31
movq 0x18(%rsp), %rbx
cmpl %eax, %r14d
cmovlel %eax, %r14d
movl %ecx, 0x4(%rsp)
incq %r13
addq $0x38, %r12
jmp 0x1caf3
movq 0x38(%rsp), %r14
testq %r14, %r14
movq %r13, 0x68(%rsp)
je 0x1cf43
pushq $0x8
popq %rbp
pushq $0x8
popq %rdi
movq %rdi, %rsi
callq 0x71b0
movq %rax, %r15
movq (%r14), %rax
movq %rax, (%r15)
movq %r15, %rbx
addq $0x8, %rbx
pushq $0x38
popq %r13
addq $-0x8, %rbx
leaq 0x8(%rbx), %rax
cmpq %r15, %rax
je 0x1cf37
movq (%rbx), %r12
movl (%r12), %eax
testb $0x1, %al
jne 0x1ce98
movq %r12, %rdi
callq 0x7360
jmp 0x1ce72
movq %r15, 0x28(%rsp)
movq %r12, %r15
xorl %r13d, %r13d
movl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
cmpq %rcx, %r13
jg 0x1cf21
movslq 0xc(%r14), %rcx
movq (%r15,%rcx), %rcx
testq %rcx, %rcx
je 0x1cf18
movq %rbx, %rax
movq 0x28(%rsp), %rdi
subq %rdi, %rax
sarq $0x3, %rax
movslq %ebp, %rdx
cmpq %rdx, %rax
jne 0x1cf0d
leal (,%rbp,2), %r14d
movslq %r14d, %rsi
shlq $0x3, %rsi
callq 0x7590
shlq $0x21, %rbp
sarq $0x21, %rbp
movq %rax, 0x28(%rsp)
leaq (%rax,%rbp,8), %rbx
movq 0x38(%rsp), %rax
movslq 0xc(%rax), %rax
movq (%r15,%rax), %rcx
movl %r14d, %ebp
movq 0x38(%rsp), %r14
movq %rcx, (%rbx)
addq $0x8, %rbx
movl (%r12), %eax
incq %r13
addq $0x8, %r15
jmp 0x1cea3
movq %r12, %rdi
callq 0x7360
pushq $0x38
popq %r13
movq 0x28(%rsp), %r15
jmp 0x1ce72
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %rbx
jmp 0x1cf4a
xorl %r15d, %r15d
pushq $0x38
popq %r13
movq %r14, %rdi
callq 0x7360
movq %r15, %rdi
callq 0x7360
testq %rbx, %rbx
je 0x1d049
pushq $0x8
popq %rdi
movq %rdi, %rsi
callq 0x71b0
movq %rax, %rdi
movq (%rbx), %rax
movq %rax, (%rdi)
movq %rdi, %r14
addq $0x8, %r14
pushq $0x8
popq %rbp
addq $-0x8, %r14
leaq 0x8(%r14), %rax
cmpq %rdi, %rax
je 0x1d03f
movq (%r14), %r12
movl (%r12), %eax
testb $0x1, %al
jne 0x1cfad
movq %rdi, %r15
movq %r12, %rdi
callq 0x7360
movq %r15, %rdi
jmp 0x1cf81
movq %r12, %r15
xorl %r13d, %r13d
movl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
cmpq %rcx, %r13
jg 0x1d028
movslq 0xc(%rbx), %rcx
movq (%r15,%rcx), %rcx
testq %rcx, %rcx
je 0x1d01f
movq %r14, %rax
subq %rdi, %rax
sarq $0x3, %rax
movslq %ebp, %rdx
cmpq %rdx, %rax
jne 0x1d014
leal (,%rbp,2), %ebx
movslq %ebx, %rsi
shlq $0x3, %rsi
callq 0x7590
movq %rax, %rdi
shlq $0x21, %rbp
sarq $0x21, %rbp
leaq (%rax,%rbp,8), %r14
movq 0x18(%rsp), %rax
movslq 0xc(%rax), %rax
movq (%r15,%rax), %rcx
movl %ebx, %ebp
movq 0x18(%rsp), %rbx
movq %rcx, (%r14)
addq $0x8, %r14
movl (%r12), %eax
incq %r13
addq $0x8, %r15
jmp 0x1cfb3
movq %rdi, %r15
movq %r12, %rdi
callq 0x7360
movq %r15, %rdi
pushq $0x38
popq %r13
jmp 0x1cf81
movq 0x20(%rsp), %rbp
movq %rdi, %r14
jmp 0x1d04c
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x7360
movq %r14, %rdi
callq 0x7360
cmpl $0x5, 0x78(%rbp)
movq 0x68(%rsp), %rbx
jl 0x1d223
movq 0x2cf76(%rip), %rdi     # 0x49fe8
leaq 0x1a049(%rip), %rsi     # 0x370c2
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq 0x40(%rsp), %rcx
movq 0xb8(%rcx), %rax
subq 0xb0(%rcx), %rax
shrq $0x3, %rax
cmpl 0x34(%rsp), %eax
jge 0x1d0eb
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
cqto
idivq %r13
cmpq %rax, %rbx
movq 0x8(%rsp), %rax
jae 0x1d0f4
movl 0xb0(%rsp), %edx
cmpl %edx, -0x20(%rcx,%rax)
jle 0x1d0fd
movq %rbx, %r14
movl (%rsp), %eax
movl 0x4(%rsp), %ecx
cmpl %eax, %ecx
cmovll %ecx, %eax
cmpl 0x54(%rbp), %eax
jl 0x1d11b
leaq 0x1a063(%rip), %rsi     # 0x3714c
jmp 0x1d104
leaq 0x19feb(%rip), %rsi     # 0x370dd
jmp 0x1d104
leaq 0x1a001(%rip), %rsi     # 0x370fc
jmp 0x1d104
leaq 0x1a019(%rip), %rsi     # 0x3711d
movq 0x2cedd(%rip), %rdi     # 0x49fe8
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq %rbx, %r14
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
idivq %r13
cmpq %rax, %r14
jae 0x1d223
addq $0x8, 0x8(%rsp)
movq 0x2cea6(%rip), %r15     # 0x49fe8
leaq 0x1a03f(%rip), %rsi     # 0x37188
movq %r15, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
leaq 0x60(%rsp), %r12
leaq 0x58(%rsp), %rbp
movq 0x10(%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %rax
subq %rbx, %rax
cqto
idivq %r13
cmpq %rax, %r14
jae 0x1d223
movq %r15, %rdi
leaq 0x19f0f(%rip), %rsi     # 0x37099
callq 0x72b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x71d0
movq %rax, %rdi
leaq 0x19d38(%rip), %rsi     # 0x36edc
callq 0x72b0
movq 0x8(%rsp), %r13
movq (%rbx,%r13), %rsi
subq -0x8(%rbx,%r13), %rsi
sarq $0x4, %rsi
movq %rax, %rdi
callq 0x71d0
movq %rax, %rdi
leaq 0x19fdd(%rip), %rsi     # 0x371aa
callq 0x72b0
movl -0x28(%rbx,%r13), %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
leaq 0x19fcd(%rip), %rsi     # 0x371b6
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq -0x8(%rbx,%r13), %rax
movq (%rax), %rsi
movq 0x50(%rsp), %rdi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x22b12
incq %r14
addq $0x38, %r13
movq %r13, 0x8(%rsp)
pushq $0x38
popq %r13
jmp 0x1d163
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq