// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/sparseSA.cpp
// Function: sparseSA::findSMAM(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<match_t, std::allocator<match_t>>&, int, int, int) const
void sparseSA::findSMAM(int k, const string &P, vector<match_t> &matches, int min_len, int maxCount, int sparseQ) const {
  if(k < 0 || k >= K) { cerr << "Invalid k." << endl; return; }
  // Offset all intervals at different start points.
  int prefix = k;
  interval_t xmi(0,N/K-1,0); // max match interval

  // Right-most match used to terminate search.
  int min_lenK = min_len - (sparseQ*K-1);
  int minMin_len = sparseQ > 1 ? min_len-K : min_len;
  while( prefix <= (int)P.length() - (min_lenK)) {//bugfix (was (K-k) before)
    if(hasChild) 
        traverse_faster(P, prefix, xmi, P.length(), -1);
    else
        traverse(P, prefix, xmi, P.length(), -1);// Traverse until mismatch.
    if(xmi.depth <= 1) { xmi.reset(N/K-1); prefix += sparseQ*K; continue; }
    if(xmi.depth >= min_lenK) {//less restriction seems to give best results
        collectAllSMAMs(P, prefix, xmi, matches, minMin_len, sparseQ*maxCount, sparseQ*K); // Using LCP info to find MEM length.
        // When using ISA/LCP trick, depth = depth - K. prefix += K.
        prefix += sparseQ*K;
        if (!hasSufLink) {
            xmi.reset(N / K - 1);
            continue;
        } else {
            int i = 0;
            bool succes = true;
            while (i < sparseQ && (succes = suffixlink(xmi)))
                i++;
            if (!succes) {
                xmi.reset(N / K - 1);
                continue;
            }
        }
    }
    else {
      // When using ISA/LCP trick, depth = depth - K. prefix += K.
      prefix += sparseQ*K;
      if (!hasSufLink) {
            xmi.reset(N / K - 1);
            continue;
      } else {
        int i = 0;
        bool succes = true;
        while (i < sparseQ && (succes = suffixlink(xmi)))
            i++;
        if (!succes) {
            xmi.reset(N / K - 1);
            continue;
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x18(%rsp)
movq %rcx, 0x48(%rsp)
testl %esi, %esi
js 0x10144
movl %esi, %ebp
movq %rdi, %r13
movl %esi, %eax
movq 0xe8(%rdi), %rcx
cmpq %rax, %rcx
jle 0x10144
movq %rdx, %r12
movl 0xa0(%rsp), %ebx
movq 0x38(%r13), %rax
cqto
idivq %rcx
decq %rax
leaq 0x20(%rsp), %r15
andq $0x0, (%r15)
movq %rax, 0x8(%r15)
andl $0x0, 0x10(%r15)
movl %ecx, %eax
imull %ebx, %eax
negl %eax
addl %r8d, %eax
incl %eax
movl %eax, 0x14(%rsp)
xorl %edx, %edx
cmpl $0x2, %ebx
cmovll %edx, %ecx
subl %ecx, %r8d
movq %r8, 0x40(%rsp)
movq 0x18(%rsp), %rax
imull %ebx, %eax
movq %rax, 0x18(%rsp)
testl %ebx, %ebx
cmovgl %ebx, %edx
incl %edx
movl %edx, 0x10(%rsp)
movl %ebx, 0xc(%rsp)
movl 0x8(%r12), %r8d
movl %r8d, %eax
subl 0x14(%rsp), %eax
cmpl %eax, %ebp
jg 0x1016d
cmpb $0x1, 0xf0(%r13)
jne 0x1002d
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %r15, %rcx
pushq $-0x1
popq %r9
callq 0x112ce
jmp 0x10041
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %r15, %rcx
pushq $-0x1
popq %r9
callq 0x11590
movl 0x30(%rsp), %eax
cmpl $0x1, %eax
jg 0x10065
movq 0x38(%r13), %rax
movq 0xe8(%r13), %r14
cqto
idivq %r14
andq $0x0, 0x20(%rsp)
jmp 0x10122
cmpl 0x14(%rsp), %eax
jge 0x1009d
movq 0xe8(%r13), %r14
cmpb $0x1, 0xf1(%r13)
movl 0x10(%rsp), %ebx
jne 0x1010f
decl %ebx
je 0x1013e
movq %r13, %rdi
movq %r15, %rsi
callq 0x116b4
testb %al, %al
jne 0x10084
jmp 0x10100
movaps 0x20(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
movl %eax, 0x60(%rsp)
movl 0xe8(%r13), %eax
imull %ebx, %eax
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
leaq 0x50(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x40(%rsp), %r9
pushq %rax
pushq 0x20(%rsp)
callq 0xf5ce
popq %rax
popq %rcx
movq 0xe8(%r13), %r14
cmpb $0x1, 0xf1(%r13)
movl 0x10(%rsp), %ebx
jne 0x1010f
decl %ebx
je 0x1013e
movq %r13, %rdi
movq %r15, %rsi
callq 0x116b4
testb %al, %al
jne 0x100ed
movq 0x38(%r13), %rax
cqto
idivq 0xe8(%r13)
jmp 0x10118
movq 0x38(%r13), %rax
cqto
idivq %r14
andq $0x0, 0x20(%rsp)
movl 0xc(%rsp), %ebx
decq %rax
movq %rax, 0x28(%rsp)
andl $0x0, 0x30(%rsp)
imull %ebx, %r14d
addl %ebp, %r14d
movl %r14d, %ebp
jmp 0xfff9
movl 0xc(%rsp), %ebx
jmp 0x1012f
movq 0x39e9d(%rip), %rdi     # 0x49fe8
leaq 0x2628a(%rip), %rsi     # 0x363dc
callq 0x72b0
movq %rax, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7160
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq