// File: 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 %rbx
subq $0x120, %rsp            # imm = 0x120
movl 0x130(%rsp), %eax
movq %rdi, 0x118(%rsp)
movq %rsi, 0x110(%rsp)
movq %rdx, 0x108(%rsp)
movl %ecx, 0x104(%rsp)
movl %r8d, 0x100(%rsp)
movl %r9d, 0xfc(%rsp)
movq 0x118(%rsp), %rcx
movq %rcx, 0x98(%rsp)
movslq 0x104(%rsp), %rax
cmpq 0xe8(%rcx), %rax
jge 0x1db74
jmp 0x1e16d
movq 0x98(%rsp), %rcx
movslq 0x104(%rsp), %rax
movslq 0xfc(%rsp), %rdx
imulq 0xe8(%rcx), %rdx
subq $0x1, %rdx
subq %rdx, %rax
movl %eax, 0xf8(%rsp)
movq 0x38(%rcx), %rax
cqto
idivq 0xe8(%rcx)
movq %rax, %rdx
subq $0x1, %rdx
leaq 0xe0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
callq 0x1eea0
leaq 0xc8(%rsp), %rdi
callq 0x20d30
movl $0x0, 0xc4(%rsp)
movl $0x0, 0xc0(%rsp)
movq $-0x1, 0xb8(%rsp)
cmpl $0x1, 0xfc(%rsp)
jle 0x1dc23
movq 0x98(%rsp), %rcx
movslq 0x104(%rsp), %rax
subq 0xe8(%rcx), %rax
movq %rax, 0x90(%rsp)
jmp 0x1dc33
movslq 0x104(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movl %eax, 0xb4(%rsp)
movl $0x0, 0xb0(%rsp)
movl 0xb0(%rsp), %eax
movl %eax, 0x8c(%rsp)
movq 0x110(%rsp), %rdi
callq 0x8630
movq %rax, %rcx
movl 0x8c(%rsp), %eax
subl 0xf8(%rsp), %ecx
cmpl %ecx, %eax
jg 0x1e160
leaq 0xc8(%rsp), %rdi
callq 0x20d40
movq 0x98(%rsp), %rdi
movq 0x110(%rsp), %rsi
movl 0xb0(%rsp), %edx
movl 0xf8(%rsp), %r8d
leaq 0xe0(%rsp), %rcx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x1fc90
jmp 0x1dcc2
cmpl $0x1, 0xf0(%rsp)
jg 0x1dd24
movq 0x98(%rsp), %rcx
movq 0x38(%rcx), %rax
movq 0xe8(%rcx), %rcx
cqto
idivq %rcx
movq %rax, %rsi
decq %rsi
leaq 0xe0(%rsp), %rdi
callq 0x20830
jmp 0x1dcf9
jmp 0x1e14a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x21690
jmp 0x1e176
movl 0xf0(%rsp), %eax
cmpl 0xf8(%rsp), %eax
jl 0x1e0bb
leaq 0xc8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x20d60
jmp 0x1dd4f
movq 0x110(%rsp), %rdi
movq %rdi, 0x80(%rsp)
movl 0xb0(%rsp), %eax
movl %eax, 0x88(%rsp)
callq 0x8630
movq 0x98(%rsp), %rdi
movq 0x80(%rsp), %rsi
movl 0x88(%rsp), %edx
movl %eax, %r8d
movl 0x100(%rsp), %r9d
leaq 0xc8(%rsp), %rcx
callq 0x20dd0
jmp 0x1dda3
leaq 0xc8(%rsp), %rdi
callq 0x21640
testb $0x1, %al
jne 0x1e0b9
movl 0xb0(%rsp), %eax
movl %eax, 0x78(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x1fc10
movl 0x78(%rsp), %ecx
addl 0x10(%rax), %ecx
movb $0x1, %al
cmpl 0xc4(%rsp), %ecx
movb %al, 0x7f(%rsp)
jg 0x1de5e
movq 0xb8(%rsp), %rcx
movslq 0x130(%rsp), %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, 0x7f(%rsp)
jle 0x1de5e
movq 0x98(%rsp), %rax
movslq 0xb0(%rsp), %rcx
movslq 0xc0(%rsp), %rdx
addq 0xe8(%rax), %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, 0x7f(%rsp)
jle 0x1de5e
leaq 0xc8(%rsp), %rdi
callq 0x1fc10
movq %rax, %rdi
callq 0x1fbb0
movq %rax, 0x70(%rsp)
jmp 0x1de47
movq 0x70(%rsp), %rax
movslq 0x130(%rsp), %rcx
cmpq %rcx, %rax
setle %al
movb %al, 0x7f(%rsp)
movb 0x7f(%rsp), %al
andb $0x1, %al
movb %al, 0xa3(%rsp)
xorl %eax, %eax
testb $0x1, 0xa3(%rsp)
movb %al, 0x6f(%rsp)
je 0x1df03
leaq 0xc8(%rsp), %rdi
callq 0x1fc10
movq %rax, %rdi
callq 0x1fbb0
movq %rax, 0x60(%rsp)
jmp 0x1de9b
movq 0x60(%rsp), %rcx
movslq 0x130(%rsp), %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x6f(%rsp)
jg 0x1df03
movl 0xb0(%rsp), %eax
movl %eax, 0x58(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x1fc10
movl 0x58(%rsp), %ecx
addl 0x10(%rax), %ecx
movb $0x1, %al
cmpl 0xc4(%rsp), %ecx
movb %al, 0x5f(%rsp)
jg 0x1defb
movq 0xb8(%rsp), %rax
movslq 0x130(%rsp), %rcx
cmpq %rcx, %rax
setle %al
movb %al, 0x5f(%rsp)
movb 0x5f(%rsp), %al
movb %al, 0x6f(%rsp)
movb 0x6f(%rsp), %al
andb $0x1, %al
movb %al, 0xa2(%rsp)
testb $0x1, 0xa3(%rsp)
je 0x1df8e
movq 0x98(%rsp), %rdi
movq 0x110(%rsp), %rsi
movl 0xb0(%rsp), %edx
movq 0x108(%rsp), %r8
movl 0xc4(%rsp), %ecx
movl 0xb4(%rsp), %r10d
movl 0x100(%rsp), %r11d
movl 0xe8(%rdi), %ebx
movl 0xfc(%rsp), %eax
imull %eax, %ebx
movzbl 0xa2(%rsp), %r9d
movq %rsp, %rax
movl %ebx, 0x18(%rax)
movl %r11d, 0x10(%rax)
movl %r10d, 0x8(%rax)
movl %ecx, (%rax)
andl $0x1, %r9d
leaq 0xc8(%rsp), %rcx
callq 0x1bd90
jmp 0x1df8c
jmp 0x1df8e
movl 0xc4(%rsp), %eax
movl %eax, 0x54(%rsp)
movl 0xb0(%rsp), %eax
movl %eax, 0x50(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x1fc10
movl 0x50(%rsp), %ecx
movq %rax, %rdx
movl 0x54(%rsp), %eax
addl 0x10(%rdx), %ecx
cmpl %ecx, %eax
jge 0x1e057
movl 0xb0(%rsp), %eax
movl %eax, 0x44(%rsp)
leaq 0xc8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x1fc10
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl 0x44(%rsp), %eax
movl 0x10(%rcx), %ecx
addl %ecx, %eax
movl %eax, 0xc4(%rsp)
callq 0x1fc10
movq %rax, %rdi
callq 0x1fbb0
movq %rax, 0x48(%rsp)
jmp 0x1e010
movq 0x48(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movslq 0x130(%rsp), %rcx
cmpq %rcx, %rax
jle 0x1e03f
movl 0xb0(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x1e04a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x34(%rsp)
jmp 0x1e04a
movl 0x34(%rsp), %eax
movl %eax, 0xc0(%rsp)
jmp 0x1e0b7
leaq 0xc8(%rsp), %rdi
callq 0x1fc10
movq %rax, %rdi
callq 0x1fbb0
movq %rax, 0x28(%rsp)
jmp 0x1e073
movq 0x28(%rsp), %rax
addq 0xb8(%rsp), %rax
movq %rax, 0xb8(%rsp)
cmpl $0x0, 0xc0(%rsp)
jge 0x1e0b5
movq 0xb8(%rsp), %rax
movslq 0x130(%rsp), %rcx
cmpq %rcx, %rax
jle 0x1e0b5
movl 0xb0(%rsp), %eax
movl %eax, 0xc0(%rsp)
jmp 0x1e0b7
jmp 0x1e0b9
jmp 0x1e0bb
movq 0x98(%rsp), %rcx
movq 0x38(%rcx), %rax
movq 0xe8(%rcx), %rcx
cqto
idivq %rcx
movq %rax, %rsi
decq %rsi
leaq 0xe0(%rsp), %rdi
callq 0x20830
jmp 0x1e0e8
movq 0x98(%rsp), %rcx
movslq 0xb0(%rsp), %rax
cqto
idivq 0xe8(%rcx)
movq 0x98(%rsp), %rax
movq 0xe8(%rax), %rax
subq $0x1, %rax
cmpq %rax, %rdx
jne 0x1e148
movq 0x98(%rsp), %rax
movl 0xfc(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq 0xe8(%rax), %rcx
movslq 0xb0(%rsp), %rax
addq %rcx, %rax
movl %eax, 0xb0(%rsp)
jmp 0x1e14a
movl 0xb0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb0(%rsp)
jmp 0x1dc4d
leaq 0xc8(%rsp), %rdi
callq 0x21690
addq $0x120, %rsp            # imm = 0x120
popq %rbx
retq
movq 0xa8(%rsp), %rdi
callq 0x8730
nopw %cs:(%rax,%rax)