// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/sparseSA.cpp
// Function: sparseSA::SMEMP(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<match_t, std::allocator<match_t>>&, int, int, int, int) const
void sparseSA::SMEMP(const string &P, vector<match_t> &matches, int min_len, int maxCount, int sparseQ, int max_smem_cont) const {
  if(min_len < K) return;
  // Offset all intervals at different start points.
  int min_lenK = min_len - (sparseQ*K-1);
  interval_t mli(0,N/K-1,0); // min length interval
  vector<interval_t> intervals;
  int prevEnd = 0;
  int prevEndPrefix = 0;
  long prevSize = -1L;
  int minMin_len = sparseQ > 1 ? min_len-K : min_len;
  for(int prefix = 0; prefix <= (int)P.length() - (min_lenK); prefix++) {
      // Right-most match used to terminate search.
      intervals.clear();
      traverse_faster(P, prefix, mli, min_lenK, -1); // Traverse until minimum length matched.
      if(mli.depth <= 1) { mli.reset(N/K-1); continue; }
      if(mli.depth >= min_lenK) {
          intervals.push_back(mli);
          traverse_keep(P, prefix, intervals, P.length(), maxCount); // Traverse until mismatch.
          //decide if this interval should be extended
          if(!intervals.empty()){
              bool extendXmi = (prefix+intervals.back().depth) > prevEnd || 
              prevSize <= max_smem_cont || prefix <= prevEndPrefix+K || 
              intervals.back().size() <= max_smem_cont;
              bool extendMli = extendXmi && intervals.back().size() <= max_smem_cont && 
              ((prefix+intervals.back().depth) > prevEnd || prevSize <= max_smem_cont);
              //collect
              if(extendXmi)
                collectIntervals(P, prefix, intervals, matches, extendMli, prevEnd, minMin_len, maxCount, K*sparseQ);
              //update prevEnd and prevSize:
              if(prevEnd < prefix+intervals.back().depth){
                  prevEnd = prefix+intervals.back().depth;
                  prevSize = intervals.back().size();
                  prevEndPrefix = prevSize > max_smem_cont ? prefix : -1;
              }
              else{
                  prevSize += intervals.back().size();
                  if(prevEndPrefix < 0 && prevSize > max_smem_cont) prevEndPrefix = prefix;
              }
          }
      }
      mli.reset(N / K - 1);
      if(prefix % K == K-1) prefix += (sparseQ-1)*K;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, 0x58(%rsp)
movq %rdx, 0x70(%rsp)
movslq %ecx, %rax
movq 0xe8(%rdi), %r8
cmpq %rax, %r8
jg 0x10b1c
movq %rsi, %r13
movq %rdi, %rbp
movl 0xb0(%rsp), %esi
movl %r8d, %edi
imull %r9d, %edi
movq 0x38(%rbp), %rax
cqto
idivq %r8
decq %rax
leaq 0x40(%rsp), %rdx
andq $0x0, (%rdx)
movq %rax, 0x8(%rdx)
andl $0x0, 0x10(%rdx)
negl %edi
leal (%rcx,%rdi), %ebx
incl %ebx
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
andq $0x0, 0x10(%rdx)
xorl %r15d, %r15d
cmpl $0x2, %r9d
movl $0x0, %eax
cmovgel %r8d, %eax
movaps %xmm0, (%rdx)
subl %eax, %ecx
movq %rcx, 0x60(%rsp)
movslq %esi, %rax
movq %rax, 0x10(%rsp)
movq %r9, 0x68(%rsp)
leal -0x1(%r9), %eax
movl %eax, 0x3c(%rsp)
pushq $-0x1
popq %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0xc(%rsp)
xorl %r12d, %r12d
movl 0x8(%r13), %eax
subl %ebx, %eax
cmpl %eax, %r15d
jg 0x10b12
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x1093c
movq %rax, 0x28(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movl %r15d, %edx
leaq 0x40(%rsp), %rcx
movl %ebx, %r8d
pushq $-0x1
popq %r9
callq 0x112ce
movl 0x50(%rsp), %eax
cmpl $0x1, %eax
jg 0x10984
movq 0x38(%rbp), %rax
cqto
idivq 0xe8(%rbp)
decq %rax
andq $0x0, 0x40(%rsp)
movq %rax, 0x48(%rsp)
andl $0x0, 0x50(%rsp)
jmp 0x10b0a
movslq %r15d, %r14
cmpl %ebx, %eax
jl 0x10ac5
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x117bc
movl 0x8(%r13), %r8d
movq %rbp, %rdi
movq %r13, %rsi
movl %r15d, %edx
leaq 0x20(%rsp), %rcx
movq 0x58(%rsp), %r9
callq 0x117e2
movq 0x28(%rsp), %rax
cmpq %rax, 0x20(%rsp)
je 0x10ac5
movl -0x8(%rax), %ecx
addl %r15d, %ecx
cmpl %r12d, %ecx
setg %sil
movq 0x18(%rsp), %rdx
cmpq 0x10(%rsp), %rdx
setle %dl
orb %sil, %dl
cmpb $0x1, %dl
jne 0x109f2
movq -0x18(%rax), %rsi
jmp 0x10a18
movslq 0xc(%rsp), %rdi
addq 0xe8(%rbp), %rdi
movq -0x18(%rax), %rsi
cmpq %r14, %rdi
jge 0x10a18
movq -0x10(%rax), %rdi
subq %rsi, %rdi
incq %rdi
cmpq 0x10(%rsp), %rdi
jg 0x10a70
movq -0x10(%rax), %rax
subq %rsi, %rax
incq %rax
cmpq 0x10(%rsp), %rax
setle %al
andb %dl, %al
movl 0xe8(%rbp), %r10d
imull 0x68(%rsp), %r10d
movzbl %al, %r9d
movq %rbp, %rdi
movq %r13, %rsi
movl %r15d, %edx
leaq 0x20(%rsp), %rcx
movq 0x70(%rsp), %r8
pushq %r10
pushq 0x60(%rsp)
pushq 0x70(%rsp)
pushq %r12
callq 0xfa98
addq $0x20, %rsp
movq 0x28(%rsp), %rax
movl -0x8(%rax), %ecx
addl %r15d, %ecx
movq -0x18(%rax), %rdx
movq -0x10(%rax), %rax
cmpl %ecx, %r12d
jge 0x10a9a
subq %rdx, %rax
incq %rax
cmpq 0x10(%rsp), %rax
pushq $-0x1
popq %rdx
cmovgl %r15d, %edx
movl %edx, 0xc(%rsp)
movq %rax, 0x18(%rsp)
jmp 0x10ac8
movq 0x18(%rsp), %rcx
addq %rax, %rcx
subq %rdx, %rcx
incq %rcx
movq %rcx, 0x18(%rsp)
cmpq 0x10(%rsp), %rcx
movl 0xc(%rsp), %ecx
movl %ecx, %eax
cmovgl %r15d, %eax
testl %ecx, %ecx
cmovsl %eax, %ecx
movl %ecx, 0xc(%rsp)
movl %r12d, %ecx
movq 0x38(%rbp), %rax
movq 0xe8(%rbp), %rsi
cqto
idivq %rsi
decq %rax
andq $0x0, 0x40(%rsp)
movq %rax, 0x48(%rsp)
andl $0x0, 0x50(%rsp)
movq %r14, %rax
cqto
idivq %rsi
leaq -0x1(%rsi), %rax
cmpq %rax, %rdx
jne 0x10b07
imull 0x3c(%rsp), %esi
addl %r15d, %esi
movl %esi, %r15d
movl %ecx, %r12d
incl %r15d
jmp 0x1091c
leaq 0x20(%rsp), %rdi
callq 0x14ab0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10b2d
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x14ab0
movq %rbx, %rdi
callq 0x75e0