// File: /workspace/github_cpp_makefile_star2_O1/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, 0x68(%rsp)
movq %rdx, 0x70(%rsp)
movq %rsi, %r13
movslq %ecx, %rax
movq 0xe8(%rdi), %rsi
cmpq %rax, %rsi
jg 0x157d6
movq %rdi, %rbp
movl %esi, %eax
imull %r9d, %eax
negl %eax
movq %rcx, 0x38(%rsp)
leal (%rcx,%rax), %r12d
incl %r12d
movq 0x38(%rdi), %rax
cqto
idivq %rsi
decq %rax
xorl %ebx, %ebx
movq %rbx, 0x40(%rsp)
movq %rax, 0x48(%rsp)
movl $0x0, 0x50(%rsp)
movq %rbx, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %r9, 0x60(%rsp)
cmpl $0x2, %r9d
movl $0x0, %eax
cmovgel %esi, %eax
cmpl 0x8(%r13), %r12d
jg 0x157bf
movq 0x38(%rsp), %rcx
subl %eax, %ecx
movq %rcx, 0x38(%rsp)
movslq 0xb0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x60(%rsp), %rax
decl %eax
movl %eax, 0x5c(%rsp)
movq $-0x1, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
xorl %r14d, %r14d
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x155c6
movq %rax, 0x28(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movl %r14d, %edx
leaq 0x40(%rsp), %rcx
movl %r12d, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x15cf4
movl 0x50(%rsp), %eax
cmpl $0x1, %eax
jg 0x15616
movq 0x38(%rbp), %rax
cqto
idivq 0xe8(%rbp)
decq %rax
movq $0x0, 0x40(%rsp)
movq %rax, 0x48(%rsp)
movl $0x0, 0x50(%rsp)
jmp 0x157a8
movslq %r14d, %r15
cmpl %r12d, %eax
jl 0x1575f
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x164f8
movl 0x8(%r13), %r8d
movq %rbp, %rdi
movq %r13, %rsi
movl %r14d, %edx
leaq 0x20(%rsp), %rcx
movq 0x68(%rsp), %r9
callq 0x1651e
movq 0x28(%rsp), %rdx
cmpq %rdx, 0x20(%rsp)
je 0x1575f
movl -0x8(%rdx), %ecx
addl %r14d, %ecx
movb $0x1, %al
cmpl %ebx, %ecx
jg 0x15699
movq 0x10(%rsp), %rsi
cmpq 0x18(%rsp), %rsi
jle 0x15699
movslq 0xc(%rsp), %rsi
addq 0xe8(%rbp), %rsi
cmpq %r15, %rsi
jge 0x15699
movq -0x10(%rdx), %rax
subq -0x18(%rdx), %rax
incq %rax
cmpq 0x18(%rsp), %rax
setle %al
testb %al, %al
je 0x156b2
movq -0x10(%rdx), %rsi
subq -0x18(%rdx), %rsi
incq %rsi
movq 0x18(%rsp), %rdi
cmpq %rdi, %rsi
jle 0x156b6
xorl %ecx, %ecx
jmp 0x156c5
cmpl %ebx, %ecx
setg %dl
cmpq %rdi, 0x10(%rsp)
setle %cl
orb %dl, %cl
testb %al, %al
je 0x156fe
movl 0xe8(%rbp), %eax
imull 0x60(%rsp), %eax
movzbl %cl, %r9d
movq %rbp, %rdi
movq %r13, %rsi
movl %r14d, %edx
leaq 0x20(%rsp), %rcx
movq 0x70(%rsp), %r8
pushq %rax
pushq 0x70(%rsp)
pushq 0x48(%rsp)
pushq %rbx
callq 0x13eae
addq $0x20, %rsp
movq 0x28(%rsp), %rax
movl -0x8(%rax), %ecx
addl %r14d, %ecx
movq -0x18(%rax), %rdx
movq -0x10(%rax), %rax
cmpl %ecx, %ebx
jge 0x15734
subq %rdx, %rax
incq %rax
cmpq 0x18(%rsp), %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovgl %r14d, %edx
movl %edx, 0xc(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x15761
movq 0x10(%rsp), %rcx
addq %rax, %rcx
subq %rdx, %rcx
incq %rcx
movq %rcx, 0x10(%rsp)
cmpq 0x18(%rsp), %rcx
movl 0xc(%rsp), %ecx
movl %ecx, %eax
cmovgl %r14d, %eax
testl %ecx, %ecx
cmovsl %eax, %ecx
movl %ecx, 0xc(%rsp)
movl %ebx, %ecx
movq 0x38(%rbp), %rax
movq 0xe8(%rbp), %rsi
cqto
idivq %rsi
decq %rax
movq $0x0, 0x40(%rsp)
movq %rax, 0x48(%rsp)
movl $0x0, 0x50(%rsp)
movq %r15, %rax
cqto
idivq %rsi
leaq -0x1(%rsi), %rax
cmpq %rax, %rdx
jne 0x157a6
imull 0x5c(%rsp), %esi
addl %r14d, %esi
movl %esi, %r14d
movl %ecx, %ebx
leal 0x1(%r14), %eax
movl 0x8(%r13), %ecx
subl %r12d, %ecx
cmpl %ecx, %r14d
movl %eax, %r14d
jl 0x155b5
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x157d6
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x72f0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x157e7
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x15801
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x72f0
movq %rbx, %rdi
callq 0x7600