// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rcx, 0x58(%rsp)
testl %esi, %esi
js 0x146ea
movq %rdi, %r13
movl %esi, %eax
movq 0xe8(%rdi), %rcx
cmpq %rax, %rcx
jle 0x146ea
movl %r8d, %r14d
movq %rdx, %rbp
movl 0xb0(%rsp), %edi
movq 0x38(%r13), %rax
cqto
idivq %rcx
decq %rax
movq $0x0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl $0x0, 0x20(%rsp)
movl %ecx, %eax
imull %edi, %eax
negl %eax
leal (%r14,%rax), %r15d
incl %r15d
xorl %eax, %eax
cmpl $0x2, %edi
cmovgel %ecx, %eax
movl 0x8(%rbp), %r8d
movl %r8d, %ecx
subl %r15d, %ecx
cmpl %esi, %ecx
jge 0x1473a
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3f8f7(%rip), %rbx     # 0x53fe8
leaq 0x2fc94(%rip), %rsi     # 0x4438c
movl $0xa, %edx
movq %rbx, %rdi
callq 0x7340
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x71d0
movl %r9d, %ebx
movl %esi, %edx
subl %eax, %r14d
imull %edi, %ebx
leaq 0xa0(%r13), %rax
movq %rax, 0x30(%rsp)
movq %rbx, 0x48(%rsp)
movq %r14, 0x40(%rsp)
movq %rbp, 0x38(%rsp)
movl %r15d, 0x4(%rsp)
movl %edi, 0xc(%rsp)
cmpb $0x1, 0xf0(%r13)
movl %edx, 0x8(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
leaq 0x10(%rsp), %rcx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
jne 0x1478f
callq 0x15b88
jmp 0x14794
callq 0x1605e
movl 0x20(%rsp), %ecx
cmpl $0x1, %ecx
movl 0xc(%rsp), %edi
jg 0x147bf
movq 0x38(%r13), %rax
movq 0xe8(%r13), %r12
cqto
idivq %r12
movq $0x0, 0x10(%rsp)
jmp 0x14ac7
cmpl %r15d, %ecx
jge 0x148fa
movq 0xe8(%r13), %r12
cmpb $0x1, 0xf1(%r13)
jne 0x14aa4
testl %edi, %edi
jle 0x14ad7
xorl %eax, %eax
movl %eax, 0x2c(%rsp)
movq 0xe8(%r13), %rsi
subl %esi, %ecx
movl %ecx, 0x20(%rsp)
testl %ecx, %ecx
jle 0x14a79
movq 0x70(%r13), %rdi
movq 0x88(%r13), %r8
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %r9
movl (%rdi,%rax,4), %eax
xorl %edx, %edx
idivq %rsi
movslq 0x4(%r8,%rax,4), %rbx
movq %rbx, 0x10(%rsp)
movl (%rdi,%r9,4), %eax
xorl %edx, %edx
idivq %rsi
movslq 0x4(%r8,%rax,4), %rbp
movq %rbp, 0x18(%rsp)
addl %ecx, %ecx
movslq %ecx, %r15
imulq 0x40(%r13), %r15
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x15a0e
movl 0x20(%rsp), %ecx
cmpl %ecx, %eax
movq %r15, 0x50(%rsp)
jge 0x14863
xorl %r15d, %r15d
jmp 0x1489b
cmpq $0x2, %r15
movl $0x1, %r14d
cmovgeq %r15, %r14
decq %r14
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x14a79
incq %r15
decq %rbx
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x15a0e
movl 0x20(%rsp), %ecx
cmpl %ecx, %eax
jge 0x14877
cmpq %rbp, 0x48(%r13)
jle 0x148d6
incq %r15
leaq 0x1(%rbp), %r14
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x15a0e
movl 0x20(%rsp), %ecx
cmpl %ecx, %eax
jl 0x148d6
cmpq 0x50(%rsp), %r15
jge 0x14a79
incq %r15
movq %r14, %rbp
cmpq 0x48(%r13), %r14
jl 0x148a4
jmp 0x148d9
movq %rbp, %r14
movq %rbx, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movl 0x2c(%rsp), %eax
incl %eax
movl 0xc(%rsp), %edi
cmpl %edi, %eax
jne 0x147e7
jmp 0x14a65
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movl %ecx, 0x70(%rsp)
movl 0xe8(%r13), %eax
imull %edi, %eax
movl %edi, %r15d
movq %r13, %rdi
movq %rbp, %rsi
movl 0x8(%rsp), %edx
leaq 0x60(%rsp), %rcx
movq 0x58(%rsp), %r8
movl %r14d, %r9d
pushq %rax
pushq %rbx
callq 0x133f0
addq $0x10, %rsp
movq 0xe8(%r13), %r12
cmpb $0x1, 0xf1(%r13)
jne 0x14aad
testl %r15d, %r15d
jle 0x14afd
xorl %eax, %eax
movl 0x20(%rsp), %ecx
movl %eax, 0x2c(%rsp)
movq 0xe8(%r13), %rsi
subl %esi, %ecx
movl %ecx, 0x20(%rsp)
testl %ecx, %ecx
jle 0x14a79
movq 0x70(%r13), %rdi
movq 0x88(%r13), %r8
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %r9
movl (%rdi,%rax,4), %eax
xorl %edx, %edx
idivq %rsi
movslq 0x4(%r8,%rax,4), %rbx
movq %rbx, 0x10(%rsp)
movl (%rdi,%r9,4), %eax
xorl %edx, %edx
idivq %rsi
movslq 0x4(%r8,%rax,4), %rbp
movq %rbp, 0x18(%rsp)
addl %ecx, %ecx
movslq %ecx, %r15
imulq 0x40(%r13), %r15
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x15a0e
movl 0x20(%rsp), %ecx
cmpl %ecx, %eax
movq %r15, 0x50(%rsp)
jge 0x149d7
xorl %r15d, %r15d
jmp 0x14a0f
cmpq $0x2, %r15
movl $0x1, %r14d
cmovgeq %r15, %r14
decq %r14
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x14a79
incq %r15
decq %rbx
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x15a0e
movl 0x20(%rsp), %ecx
cmpl %ecx, %eax
jge 0x149eb
cmpq %rbp, 0x48(%r13)
jle 0x14a46
incq %r15
leaq 0x1(%rbp), %r14
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x15a0e
movl 0x20(%rsp), %ecx
cmpl %ecx, %eax
jl 0x14a46
cmpq 0x50(%rsp), %r15
jge 0x14a79
incq %r15
movq %r14, %rbp
cmpq 0x48(%r13), %r14
jl 0x14a18
jmp 0x14a49
movq %rbp, %r14
movq %rbx, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movl 0x2c(%rsp), %eax
incl %eax
movl 0xc(%rsp), %edi
cmpl %edi, %eax
jne 0x1495b
movq 0x48(%rsp), %rbx
movq 0x40(%rsp), %r14
movq 0x38(%rsp), %rbp
jmp 0x14b00
movq 0x38(%r13), %rax
cqto
idivq 0xe8(%r13)
movq $0x0, 0x10(%rsp)
movq 0x48(%rsp), %rbx
movq 0x40(%rsp), %r14
movq 0x38(%rsp), %rbp
movl 0xc(%rsp), %edi
jmp 0x14ac2
movq 0x38(%r13), %rax
jmp 0x147ac
movq 0x38(%r13), %rax
cqto
idivq %r12
movq $0x0, 0x10(%rsp)
movl %r15d, %edi
movl 0x4(%rsp), %r15d
decq %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x20(%rsp)
movl 0x8(%rsp), %eax
imull %edi, %r12d
addl %eax, %r12d
movl 0x8(%rbp), %r8d
movl %r8d, %eax
subl %r15d, %eax
movl %r12d, %edx
cmpl %eax, %r12d
jle 0x14769
jmp 0x146db
movl %r15d, %edi
movl 0x8(%rsp), %eax
movl 0x4(%rsp), %r15d
jmp 0x14adb
nop