// File: readmapping[P]alfalfa/src/sparseSA.cpp
// Function: sparseSA::traverse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, interval_t&, int, int) const
void sparseSA::traverse(const string &P, int prefix, interval_t &cur, int min_len, int maxBranching) const {
  if(hasKmer && cur.depth == 0 && min_len >= KMERSIZE){//free match first bases
    unsigned int index = 0;
    for(long i = 0; i < KMERSIZE; i++)
        index = (index << 2 ) | BITADD[ (unsigned char) P[prefix + i]];
    if(index < TABLESIZE && KMR[index].right>0){
        cur.depth = KMERSIZE;
        cur.start = KMR[index].left;
        cur.end = KMR[index].right;
    }
    else{
        return;//this results in no found seeds where the first KMERSIZE bases contain a non-ACGT character
    }
  }
  if(cur.depth >= min_len || cur.size() <= maxBranching) return;

  while(prefix+cur.depth < (int)P.length()) {
    long start = cur.start; long end = cur.end;
    // If we reach a mismatch, stop.
    if(top_down_faster(P[prefix+cur.depth], cur.depth, start, end) == false) return;

    // Advance to next interval.
    cur.depth += 1; cur.start = start; cur.end = end;

    // If we reach min_len, stop.
    if(cur.depth == min_len || cur.size() <= maxBranching) return;
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x44(%rsp)
movq %rcx, 0x38(%rsp)
movl %r8d, 0x34(%rsp)
movl %r9d, 0x30(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rsp)
testb $0x1, 0xf8(%rax)
je 0x2071e
movq 0x38(%rsp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x2071e
movslq 0x34(%rsp), %rax
cmpq $0xa, %rax
jl 0x2071e
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x20(%rsp)
cmpq $0xa, 0x20(%rsp)
jge 0x20698
movl 0x2c(%rsp), %eax
shll $0x2, %eax
movl %eax, 0x4(%rsp)
movq 0x48(%rsp), %rdi
movslq 0x44(%rsp), %rsi
addq 0x20(%rsp), %rsi
callq 0x8410
movq %rax, %rcx
movl 0x4(%rsp), %eax
movzbl (%rcx), %ecx
movl %ecx, %edx
leaq 0x5cdaf(%rip), %rcx     # 0x7d430
orl (%rcx,%rdx,4), %eax
movl %eax, 0x2c(%rsp)
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x20647
movl 0x2c(%rsp), %eax
cmpq $0x100000, %rax         # imm = 0x100000
jge 0x20717
movq 0x8(%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
movl 0x2c(%rsp), %eax
movl %eax, %esi
callq 0x23790
cmpl $0x0, 0x4(%rax)
jbe 0x20717
movq 0x8(%rsp), %rdi
movq 0x38(%rsp), %rax
movl $0xa, 0x10(%rax)
addq $0x100, %rdi            # imm = 0x100
movl 0x2c(%rsp), %eax
movl %eax, %esi
callq 0x23790
movq 0x8(%rsp), %rdi
movl (%rax), %eax
movl %eax, %ecx
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
addq $0x100, %rdi            # imm = 0x100
movl 0x2c(%rsp), %eax
movl %eax, %esi
callq 0x23790
movl 0x4(%rax), %eax
movl %eax, %ecx
movq 0x38(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0x2071c
jmp 0x20822
jmp 0x2071e
movq 0x38(%rsp), %rax
movl 0x10(%rax), %eax
cmpl 0x34(%rsp), %eax
jge 0x20740
movq 0x38(%rsp), %rdi
callq 0x1fbb0
movslq 0x30(%rsp), %rcx
cmpq %rcx, %rax
jg 0x20745
jmp 0x20822
jmp 0x20747
movl 0x44(%rsp), %eax
movq 0x38(%rsp), %rcx
addl 0x10(%rcx), %eax
movl %eax, (%rsp)
movq 0x48(%rsp), %rdi
callq 0x8630
movq %rax, %rcx
movl (%rsp), %eax
cmpl %ecx, %eax
jge 0x20822
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x48(%rsp), %rdi
movl 0x44(%rsp), %eax
movq 0x38(%rsp), %rcx
addl 0x10(%rcx), %eax
movslq %eax, %rsi
callq 0x8410
movq 0x8(%rsp), %rdi
movb (%rax), %al
movq 0x38(%rsp), %rcx
movslq 0x10(%rcx), %rdx
leaq 0x18(%rsp), %rcx
leaq 0x10(%rsp), %r8
movsbl %al, %esi
callq 0x1f000
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x207d0
jmp 0x20822
movq 0x38(%rsp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq 0x18(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x38(%rsp), %rax
movl 0x10(%rax), %eax
cmpl 0x34(%rsp), %eax
je 0x2081b
movq 0x38(%rsp), %rdi
callq 0x1fbb0
movslq 0x30(%rsp), %rcx
cmpq %rcx, %rax
jg 0x2081d
jmp 0x20822
jmp 0x20747
addq $0x58, %rsp
retq
nopw (%rax,%rax)