// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/sparseSA.cpp
// Function: sparseSA::collectXmiAndMli(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, intervTuple_t, std::vector<match_t, std::allocator<match_t>>&, bool, int, int, int, int, int) const
void sparseSA::collectXmiAndMli(const string &P, intervTuple_t interval, 
        vector<match_t> &matches, bool calcMli, int nextEndStop, 
        int nextEndStopPrefix, int min_len, int maxCount, int maxLeft) const {
    int prefix = interval.prefix;
    interval_t xmi = interval.xmi;
    interval_t mli = interval.mli;
    if(xmi.depth + prefix < min_len) return;
    //always calculate xmi MEMs
    for(long i = xmi.start; i <= xmi.end; i++)
        find_LmaximalStrict(P, prefix, SA[i], xmi.depth, matches, min_len, maxLeft);
    //if we need to calculate mli:
    if(!calcMli || (mli.start == xmi.start && mli.end == xmi.end)) return;
    //calc all mli until new end is smaller or equal to nextEndStop or ...
    if(xmi.end+1 < N/K) xmi.depth = max(LCP[xmi.start], LCP[xmi.end+1]);
    else xmi.depth = LCP[xmi.start];
    //iterate over all intervals
    while(xmi.size() < maxCount && prefix+xmi.depth > nextEndStop && xmi.depth >= mli.depth && xmi.depth + prefix >= min_len){
        long prevStart = xmi.start;
        long prevStop = xmi.end;
        // Scan RMEMs to the left, check their left maximality..
        long minStart = max(0L,xmi.start-(maxCount-xmi.size()));
        while(xmi.start >= minStart && LCP[xmi.start] >= xmi.depth)
            xmi.start--;
        // Find RMEMs to the right, check their left maximality.
        long maxEnd = min(N/K,xmi.end+1+(maxCount-xmi.size()));
        while(xmi.end+1 < maxEnd && LCP[xmi.end+1] >= xmi.depth)
            xmi.end++;
        if(xmi.size() < maxCount){
            for(long i = xmi.start; i < prevStart; i++)
                find_LmaximalStrict(P, prefix, SA[i], xmi.depth, matches, min_len, maxLeft);
            for(long i = prevStop+1; i <= xmi.end; i++)
                find_LmaximalStrict(P, prefix, SA[i], xmi.depth, matches, min_len, maxLeft);
            // Attempt to "unmatch" xmi using LCP information.
            if(xmi.end+1 < N/K) xmi.depth = max(LCP[xmi.start], LCP[xmi.end+1]);
            else xmi.depth = LCP[xmi.start];
        }
    }
    //last possible mli
    if(xmi.size() < maxCount && prefix+xmi.depth == nextEndStop && xmi.depth >= mli.depth && xmi.depth + prefix >= min_len && prefix <= nextEndStopPrefix+K){
        long prevStart = xmi.start;
        long prevStop = xmi.end;
        // Scan RMEMs to the left, check their left maximality..
        long minStart = max(0L,xmi.start-(maxCount-xmi.size()));
        while(xmi.start >= minStart && LCP[xmi.start] >= xmi.depth)
            xmi.start--;
        // Find RMEMs to the right, check their left maximality.
        long maxEnd = min(N/K,xmi.end+(maxCount-xmi.size()));
        while(xmi.end+1 < maxEnd && LCP[xmi.end+1] >= xmi.depth)
            xmi.end++;
        if(xmi.size() < maxCount){
            for(long i = xmi.start; i < prevStart; i++)
                find_LmaximalStrict(P, prefix, SA[i], xmi.depth, matches, min_len, maxLeft);
            for(long i = prevStop+1; i <= xmi.end; i++)
                find_LmaximalStrict(P, prefix, SA[i], xmi.depth, matches, min_len, maxLeft);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, 0x4c(%rsp)
movq %rcx, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, 0x10(%rsp)
movl 0xa8(%rsp), %ecx
movslq 0x30(%rdx), %rax
movl 0x28(%rdx), %r14d
movq %rax, 0x20(%rsp)
addl %r14d, %eax
cmpl %ecx, %eax
jl 0xf6f6
movl %r8d, %r12d
movq 0x18(%rdx), %rbp
movq 0x20(%rdx), %r15
movq (%rdx), %r13
movq 0x8(%rdx), %rax
movq %rax, 0x18(%rsp)
movl 0x10(%rdx), %eax
movl %eax, 0x48(%rsp)
movq %rbp, %rbx
cmpq %r15, %rbx
jg 0xf6e5
movq 0x10(%rsp), %rdi
movq 0x70(%rdi), %rax
movl (%rax,%rbx,4), %ecx
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r14d, %r8d
movq 0x30(%rsp), %r9
movl 0xb8(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
callq 0x1123a
popq %rax
popq %rcx
incq %rbx
jmp 0xf6a6
testb %r12b, %r12b
je 0xf6f6
cmpq %rbp, %r13
jne 0xf705
cmpq %r15, 0x18(%rsp)
jne 0xf705
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1(%r15), %r14
movq 0x10(%rsp), %rcx
movq 0x38(%rcx), %rax
cqto
idivq 0xe8(%rcx)
movq %rax, %r12
leaq 0xa0(%rcx), %rdi
movq %rdi, 0x18(%rsp)
movq %rbp, %rsi
callq 0x10ed8
movl %eax, %r13d
cmpq %r12, %r14
jge 0xf751
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x10ed8
cmpl %eax, %r13d
cmovgl %r13d, %eax
movl %eax, %r13d
movslq 0xb0(%rsp), %r12
movq %r12, 0x58(%rsp)
movq 0x20(%rsp), %rax
leal (%rax,%r13), %esi
cmpl 0x4c(%rsp), %esi
setle %al
cmpl 0x48(%rsp), %r13d
setl %cl
movl 0xa8(%rsp), %edx
movl %esi, 0x44(%rsp)
cmpl %edx, %esi
setl %dl
orb %cl, %dl
orb %al, %dl
movb %dl, 0xf(%rsp)
movq %r13, 0x38(%rsp)
movq %r15, %rbx
movq %rbp, 0x50(%rsp)
subq %rbp, %rbx
incq %rbx
cmpq %r12, %rbx
jge 0xf6f6
cmpb $0x0, 0xf(%rsp)
movq %r15, 0x60(%rsp)
jne 0xf92c
movq 0x50(%rsp), %rbp
movq %rbp, %r14
subq %r12, %r14
addq %rbx, %r14
testq %r14, %r14
movl $0x0, %eax
cmovleq %rax, %r14
cmpq %r14, %rbp
jl 0xf7f3
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x10ed8
cmpl %r13d, %eax
jl 0xf7f3
decq %rbp
incq %rbx
jmp 0xf7d4
movq 0x10(%rsp), %rcx
movq 0x38(%rcx), %rax
cqto
idivq 0xe8(%rcx)
movq %r12, %rcx
movq %rax, %r12
leaq (%rcx,%rbp), %rax
cmpq %r12, %rax
cmovlq %rax, %r12
movq %r15, %r14
movq %r14, %r15
movq %rbx, %r13
incq %r14
cmpq %r12, %r14
jge 0xf83e
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x10ed8
leaq 0x1(%r13), %rbx
cmpl 0x38(%rsp), %eax
jge 0xf819
movq 0x58(%rsp), %r12
cmpq %r12, %r13
movq 0x38(%rsp), %r13
jge 0xf793
movq %rbp, %r12
cmpq 0x50(%rsp), %r12
jge 0xf896
movq 0x10(%rsp), %rdi
movq 0x70(%rdi), %rax
movl (%rax,%r12,4), %ecx
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r13d, %r8d
movq 0x30(%rsp), %r9
movl 0xb8(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
callq 0x1123a
popq %rax
popq %rcx
incq %r12
jmp 0xf854
movq 0x60(%rsp), %rbx
cmpq %r15, %rbx
jge 0xf8dd
movq 0x10(%rsp), %rdi
movq 0x70(%rdi), %rax
movl 0x4(%rax,%rbx,4), %ecx
incq %rbx
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r13d, %r8d
movq 0x30(%rsp), %r9
movl 0xb8(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
callq 0x1123a
addq $0x10, %rsp
jmp 0xf89b
movq 0x10(%rsp), %rcx
movq 0x38(%rcx), %rax
cqto
idivq 0xe8(%rcx)
movq %rax, %r12
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x10ed8
movl %eax, %r13d
cmpq %r12, %r14
movq 0x58(%rsp), %r12
jge 0xf75e
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x10ed8
cmpl %eax, %r13d
cmovgl %r13d, %eax
movl %eax, %r13d
jmp 0xf75e
movl 0xa8(%rsp), %eax
cmpl %eax, 0x44(%rsp)
jl 0xf6f6
movl 0x44(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jne 0xf6f6
cmpl 0x48(%rsp), %r13d
jl 0xf6f6
movslq 0xa0(%rsp), %rax
movq 0x10(%rsp), %rcx
addq 0xe8(%rcx), %rax
cmpq 0x20(%rsp), %rax
jl 0xf6f6
movq 0x50(%rsp), %rbp
movq %rbp, %rax
subq %r12, %rax
addq %rbx, %rax
xorl %r14d, %r14d
testq %rax, %rax
cmovgq %rax, %r14
leaq 0x1(%r15), %r13
cmpq %r14, %rbp
jl 0xf9ae
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x10ed8
cmpl 0x38(%rsp), %eax
jl 0xf9ae
decq %rbp
jmp 0xf991
movq 0x10(%rsp), %rcx
movq 0x38(%rcx), %rax
cqto
idivq 0xe8(%rcx)
movq %rax, %r14
leaq (%r12,%rbp), %rax
decq %rax
cmpq %r14, %rax
cmovlq %rax, %r14
subq %rbp, %r13
movq %r15, %r12
movq %r12, %r15
movq %r13, %rbx
incq %r12
cmpq %r14, %r12
jge 0xf9fc
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x10ed8
leaq 0x1(%rbx), %r13
cmpl 0x38(%rsp), %eax
jge 0xf9d7
cmpq 0x58(%rsp), %rbx
movq 0x38(%rsp), %rbx
movq 0x60(%rsp), %r14
jge 0xf6f6
cmpq 0x50(%rsp), %rbp
jge 0xfa8e
movq 0x10(%rsp), %rdi
movq 0x70(%rdi), %rax
movl (%rax,%rbp,4), %ecx
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %ebx, %r8d
movq 0x30(%rsp), %r9
movl 0xb8(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
callq 0x1123a
popq %rax
popq %rcx
incq %rbp
jmp 0xfa11
movq 0x10(%rsp), %rdi
movq 0x70(%rdi), %rax
movl 0x4(%rax,%r14,4), %ecx
incq %r14
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %ebx, %r8d
movq 0x30(%rsp), %r9
movl 0xb8(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
callq 0x1123a
addq $0x10, %rsp
cmpq %r15, %r14
jl 0xfa52
jmp 0xf6f6