// File: /workspace/github_cpp_makefile_star2_O1/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 %r9, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, 0x38(%rsp)
testl %esi, %esi
js 0x14c89
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %eax
movq 0xe8(%rdi), %rcx
cmpq %rax, %rcx
jle 0x14c89
movl 0xb0(%rsp), %ebp
movq 0x38(%r14), %rax
cqto
idivq %rcx
decq %rax
movq $0x0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl $0x0, 0x20(%rsp)
movl %ecx, %eax
imull %ebp, %eax
negl %eax
movq 0x48(%rsp), %rdx
addl %eax, %edx
incl %edx
xorl %eax, %eax
cmpl $0x2, %ebp
cmovgel %ecx, %eax
movq 0x38(%rsp), %rcx
movl 0x8(%rcx), %r8d
movl %r8d, %ecx
movl %edx, 0x44(%rsp)
subl %edx, %ecx
cmpl %ebx, %ecx
jl 0x14c7a
movq 0x48(%rsp), %rcx
subl %eax, %ecx
movq %rcx, 0x48(%rsp)
movq 0x50(%rsp), %rax
imull %ebp, %eax
movq %rax, 0x50(%rsp)
leaq 0xa0(%r14), %r15
movq %r14, 0x28(%rsp)
movl %ebp, 0x8(%rsp)
cmpb $0x1, 0xf0(%r14)
jne 0x14945
movq %r14, %rdi
movq 0x38(%rsp), %rsi
movl %ebx, %edx
leaq 0x10(%rsp), %rcx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x15cf4
jmp 0x1495f
movq %r14, %rdi
movq 0x38(%rsp), %rsi
movl %ebx, %edx
leaq 0x10(%rsp), %rcx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x16208
movl 0x20(%rsp), %eax
cmpl $0x1, %eax
jg 0x14978
movq 0x38(%r14), %rax
movq 0xe8(%r14), %rdi
jmp 0x14c3d
cmpl 0x44(%rsp), %eax
movl %ebx, 0xc(%rsp)
jge 0x14abb
movq 0xe8(%r14), %rdi
cmpb $0x1, 0xf1(%r14)
jne 0x14c39
testl %ebp, %ebp
jle 0x14c5b
xorl %edx, %edx
movq %rdi, 0x30(%rsp)
movq 0xe8(%r14), %rsi
movl 0x20(%rsp), %ecx
subl %esi, %ecx
movl %ecx, 0x20(%rsp)
testl %ecx, %ecx
jle 0x14a1c
movl %edx, 0x4(%rsp)
movq 0x70(%r14), %rdi
movq 0x88(%r14), %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), %r12
movq %r12, 0x18(%rsp)
addl %ecx, %ecx
movslq %ecx, %r13
imulq 0x40(%r14), %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0x15b7a
cmpl 0x20(%rsp), %eax
jge 0x14a23
xorl %ebp, %ebp
jmp 0x14a52
xorl %eax, %eax
jmp 0x14aa4
cmpq $0x2, %r13
movl $0x1, %r14d
cmovgeq %r13, %r14
decq %r14
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x14a7e
incq %rbp
decq %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x15b7a
cmpl 0x20(%rsp), %eax
jge 0x14a36
movq 0x28(%rsp), %rax
cmpq 0x48(%rax), %r12
jge 0x14a82
leaq 0x1(%r12), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x15b7a
cmpl 0x20(%rsp), %eax
jl 0x14a82
incq %rbp
movq %r14, %r12
cmpq %r13, %rbp
jl 0x14a52
xorl %eax, %eax
jmp 0x14a8e
movq %rbx, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movb $0x1, %al
movq 0x28(%rsp), %r14
movl 0xc(%rsp), %ebx
movl 0x8(%rsp), %ebp
movq 0x30(%rsp), %rdi
movl 0x4(%rsp), %edx
testb %al, %al
je 0x14c2a
incl %edx
cmpl %ebp, %edx
jne 0x149aa
jmp 0x14c26
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movl %eax, 0x70(%rsp)
movl 0xe8(%r14), %eax
imull %ebp, %eax
movq %r14, %rdi
movq 0x38(%rsp), %rsi
movl %ebx, %edx
leaq 0x60(%rsp), %rcx
movq 0x58(%rsp), %r8
movq 0x48(%rsp), %r9
pushq %rax
pushq 0x58(%rsp)
callq 0x13562
addq $0x10, %rsp
movq 0xe8(%r14), %rdi
cmpb $0x1, 0xf1(%r14)
jne 0x14c39
testl %ebp, %ebp
jle 0x14c5b
xorl %edx, %edx
movq %rdi, 0x30(%rsp)
movq 0xe8(%r14), %rsi
movl 0x20(%rsp), %ecx
subl %esi, %ecx
movl %ecx, 0x20(%rsp)
testl %ecx, %ecx
jle 0x14b90
movl %edx, 0x4(%rsp)
movq 0x70(%r14), %rdi
movq 0x88(%r14), %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), %r12
movq %r12, 0x18(%rsp)
addl %ecx, %ecx
movslq %ecx, %r13
imulq 0x40(%r14), %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0x15b7a
cmpl 0x20(%rsp), %eax
jge 0x14b97
xorl %ebp, %ebp
jmp 0x14bc6
xorl %eax, %eax
jmp 0x14c18
cmpq $0x2, %r13
movl $0x1, %r14d
cmovgeq %r13, %r14
decq %r14
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x14bf2
incq %rbp
decq %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x15b7a
cmpl 0x20(%rsp), %eax
jge 0x14baa
movq 0x28(%rsp), %rax
cmpq 0x48(%rax), %r12
jge 0x14bf6
leaq 0x1(%r12), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x15b7a
cmpl 0x20(%rsp), %eax
jl 0x14bf6
incq %rbp
movq %r14, %r12
cmpq %r13, %rbp
jl 0x14bc6
xorl %eax, %eax
jmp 0x14c02
movq %rbx, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movb $0x1, %al
movq 0x28(%rsp), %r14
movl 0xc(%rsp), %ebx
movl 0x8(%rsp), %ebp
movq 0x30(%rsp), %rdi
movl 0x4(%rsp), %edx
testb %al, %al
je 0x14c2a
incl %edx
cmpl %ebp, %edx
jne 0x14b1e
testb %al, %al
jne 0x14c5b
movq 0x38(%r14), %rax
cqto
idivq 0xe8(%r14)
jmp 0x14c42
movq 0x38(%r14), %rax
cqto
idivq %rdi
movq $0x0, 0x10(%rsp)
decq %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x20(%rsp)
imull %ebp, %edi
addl %ebx, %edi
movq 0x38(%rsp), %rax
movl 0x8(%rax), %r8d
movl %r8d, %eax
subl 0x44(%rsp), %eax
movl %edi, %ebx
cmpl %eax, %edi
jle 0x1491f
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3f358(%rip), %rbx     # 0x53fe8
leaq 0x2f6f5(%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
nop