// File: /workspace/github_cpp_makefile_star2_O3/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)
movq %rsi, %r13
movslq %ecx, %rax
movq 0xe8(%rdi), %rsi
cmpq %rax, %rsi
jg 0x1563d
movq %rdi, %rbp
movl %esi, %eax
imull %r9d, %eax
negl %eax
leal (%rcx,%rax), %r12d
incl %r12d
movq 0x38(%rdi), %rax
cqto
idivq %rsi
decq %rax
xorl %ebx, %ebx
movq %rbx, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movl $0x0, 0x48(%rsp)
movq %rbx, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
cmpl $0x2, %r9d
movl $0x0, %eax
cmovgel %esi, %eax
cmpl 0x8(%r13), %r12d
jg 0x1563d
subl %eax, %ecx
movq %rcx, 0x60(%rsp)
movslq 0xb0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r9, 0x68(%rsp)
leal -0x1(%r9), %eax
movl %eax, 0x54(%rsp)
movq $-0x1, 0x30(%rsp)
movl $0x0, 0x4(%rsp)
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x15435
movq %rax, 0x18(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movl %r14d, %edx
leaq 0x38(%rsp), %rcx
movl %r12d, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x15b88
movl 0x48(%rsp), %eax
cmpl $0x1, %eax
jg 0x15485
movq 0x38(%rbp), %rax
cqto
idivq 0xe8(%rbp)
decq %rax
movq $0x0, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movl $0x0, 0x48(%rsp)
jmp 0x1560f
movslq %r14d, %r15
cmpl %r12d, %eax
jl 0x155c6
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x1633a
movl 0x8(%r13), %r8d
movq %rbp, %rdi
movq %r13, %rsi
movl %r14d, %edx
leaq 0x10(%rsp), %rcx
movq 0x58(%rsp), %r9
callq 0x16360
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%rsp)
je 0x155c6
movl -0x8(%rax), %ecx
addl %r14d, %ecx
cmpl %ebx, %ecx
setg %sil
movq 0x30(%rsp), %rdx
cmpq 0x8(%rsp), %rdx
setle %dl
orb %sil, %dl
cmpb $0x1, %dl
jne 0x154f3
movq -0x18(%rax), %rsi
jmp 0x15519
movslq 0x4(%rsp), %rdi
addq 0xe8(%rbp), %rdi
movq -0x18(%rax), %rsi
cmpq %r15, %rdi
jge 0x15519
movq -0x10(%rax), %rdi
subq %rsi, %rdi
incq %rdi
cmpq 0x8(%rsp), %rdi
jg 0x15570
movq -0x10(%rax), %rax
subq %rsi, %rax
incq %rax
cmpq 0x8(%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 %r14d, %edx
leaq 0x10(%rsp), %rcx
movq 0x70(%rsp), %r8
pushq %r10
pushq 0x60(%rsp)
pushq 0x70(%rsp)
pushq %rbx
callq 0x13c64
addq $0x20, %rsp
movq 0x18(%rsp), %rax
movl -0x8(%rax), %ecx
addl %r14d, %ecx
movq -0x18(%rax), %rdx
movq -0x10(%rax), %rax
cmpl %ecx, %ebx
jge 0x1559b
subq %rdx, %rax
incq %rax
cmpq 0x8(%rsp), %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovgl %r14d, %edx
movl %edx, 0x4(%rsp)
movq %rax, 0x30(%rsp)
jmp 0x155c8
movq 0x30(%rsp), %rcx
addq %rax, %rcx
subq %rdx, %rcx
incq %rcx
movq %rcx, 0x30(%rsp)
cmpq 0x8(%rsp), %rcx
movl 0x4(%rsp), %ecx
movl %ecx, %eax
cmovgl %r14d, %eax
testl %ecx, %ecx
cmovsl %eax, %ecx
movl %ecx, 0x4(%rsp)
movl %ebx, %ecx
movq 0x38(%rbp), %rax
movq 0xe8(%rbp), %rsi
cqto
idivq %rsi
decq %rax
movq $0x0, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movl $0x0, 0x48(%rsp)
movq %r15, %rax
cqto
idivq %rsi
leaq -0x1(%rsi), %rax
cmpq %rax, %rdx
jne 0x1560d
imull 0x54(%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 0x15424
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1563d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x72f0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1564e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x15668
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x72f0
movq %rbx, %rdi
callq 0x7600