// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/sparseSA.cpp
// Function: sparseSA::traverse_faster(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, interval_t&, int, int) const
void sparseSA::traverse_faster(const string &P,const 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 >= (int) min_len || cur.size() <= maxBranching) return;
        size_t c = prefix + cur.depth;
        bool intervalFound = c < P.length();
        int curLCP; //check if this is correct for root interval (unlikely case)
        if (cur.start < CHILD[cur.end] && CHILD[cur.end] <= cur.end)
            curLCP = LCP[CHILD[cur.end]];
        else
            curLCP = LCP[CHILD[cur.start]];
        if (intervalFound && cur.size() > 1 && curLCP == cur.depth)
            intervalFound = top_down_child(P[c], cur);
        else if(intervalFound)
            intervalFound = P[c] == S[((long)SA[cur.start])+(long)cur.depth];
        bool mismatchFound = false;
        while(intervalFound && !mismatchFound && c < P.length() && 
                (cur.depth < min_len && cur.size() > maxBranching)){
            c++;
            cur.depth++;
            if(cur.start != cur.end){
                int childLCP;
                //calculate LCP of child node, which is now cur. the LCP value
                //of the parent is currently c - prefix
                if(cur.start < (long) CHILD[cur.end] && (long) CHILD[cur.end] <= cur.end)
                    childLCP = LCP[CHILD[cur.end]];
                else
                    childLCP = LCP[CHILD[cur.start]];
                int minimum = min(childLCP,min_len);
                //match along branch, note: no cur.size() restriction as this does not change 
                while(!mismatchFound && c < P.length() && cur.depth < minimum){
                    mismatchFound = S[((long)SA[cur.start])+(long)cur.depth] != P[c];
                    c++;
                    cur.depth += !mismatchFound;
                }
                intervalFound = c < P.length() && !mismatchFound &&
                        cur.depth < min_len && top_down_child(P[c], cur);
            }
            else{
                while(!mismatchFound && c < P.length() && cur.depth < min_len){
                    mismatchFound = (long) SA[cur.start]+cur.depth >= N ||
                            S[((long)SA[cur.start])+cur.depth] != P[c];
                    c++;
                    cur.depth += !mismatchFound;
                }
            }
        }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebx
movq %rcx, %r14
movq %rsi, %r15
movq %rdi, %r12
movl 0x10(%rcx), %eax
cmpb $0x1, 0xf8(%rdi)
jne 0x11365
testl %eax, %eax
setne %cl
cmpl $0xa, %ebx
setl %sil
orb %cl, %sil
jne 0x11365
movslq %edx, %rax
addq (%r15), %rax
xorl %esi, %esi
leaq 0x2514c(%rip), %rdi     # 0x36460
xorl %ecx, %ecx
cmpq $0xa, %rsi
je 0x1132d
shll $0x2, %ecx
movzbl (%rax,%rsi), %r8d
orl (%rdi,%r8,4), %ecx
incq %rsi
jmp 0x11316
cmpl $0x100000, %ecx         # imm = 0x100000
jae 0x11581
movl %ecx, %eax
movq 0x100(%r12), %rsi
movl 0x4(%rsi,%rax,8), %ecx
testq %rcx, %rcx
je 0x11581
movl $0xa, 0x10(%r14)
movl (%rsi,%rax,8), %eax
movq %rax, (%r14)
movq %rcx, 0x8(%r14)
pushq $0xa
popq %rax
cmpl %ebx, %eax
jge 0x11581
movq (%r14), %rcx
movq 0x8(%r14), %rdi
movq %rdi, %rsi
subq %rcx, %rsi
incq %rsi
movslq %r9d, %r8
movq %r8, 0x10(%rsp)
cmpq %r8, %rsi
jle 0x11581
addl %edx, %eax
movslq %eax, %r13
movq 0x8(%r15), %rbp
movq 0xd0(%r12), %rax
movslq (%rax,%rdi,4), %rsi
cmpq %rsi, %rcx
setl %dl
cmpq %rsi, %rdi
setge %dil
leaq 0xa0(%r12), %r8
movq %r8, 0x8(%rsp)
testb %dil, %dl
jne 0x113c6
movslq (%rax,%rcx,4), %rsi
movq 0x8(%rsp), %rdi
callq 0x10ed8
cmpq %r13, %rbp
jbe 0x11407
movq (%r14), %rcx
movq 0x8(%r14), %rdi
subq %rcx, %rdi
incq %rdi
movq (%r15), %rdx
movb (%rdx,%r13), %dl
movl 0x10(%r14), %esi
cmpq $0x2, %rdi
jl 0x1140b
cmpl %esi, %eax
jne 0x1140b
movsbl %dl, %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x11fba
jmp 0x11421
xorl %eax, %eax
jmp 0x11421
movq 0x70(%r12), %rax
movl (%rax,%rcx,4), %eax
addq 0x50(%r12), %rax
movslq %esi, %rcx
cmpb (%rcx,%rax), %dl
sete %al
xorl %ebp, %ebp
testb $0x1, %al
je 0x11581
testb $0x1, %bpl
jne 0x11581
movq 0x8(%r15), %rcx
cmpq %rcx, %r13
jae 0x11581
movl 0x10(%r14), %edx
cmpl %ebx, %edx
jge 0x11581
movq (%r14), %rax
movq 0x8(%r14), %rdi
movq %rdi, %rsi
subq %rax, %rsi
incq %rsi
cmpq 0x10(%rsp), %rsi
jle 0x11581
incq %r13
incl %edx
movl %edx, 0x10(%r14)
cmpq %rdi, %rax
jne 0x114ca
movq 0x70(%r12), %rsi
movq 0x38(%r12), %r8
movq 0x50(%r12), %r9
movq (%r15), %r10
movb $0x1, %al
testb $0x1, %bpl
jne 0x11423
cmpq %rcx, %r13
jae 0x11423
cmpl %ebx, %edx
jge 0x11423
movl (%rsi,%rdi,4), %r11d
movslq %edx, %rax
addq %r11, %rax
movb $0x1, %bpl
cmpq %r8, %rax
jge 0x114b8
movb (%r9,%rax), %al
cmpb (%r10,%r13), %al
setne %bpl
incq %r13
movl %ebp, %eax
xorb $0x1, %al
movzbl %al, %eax
addl %eax, %edx
movl %edx, 0x10(%r14)
jmp 0x11489
movq 0xd0(%r12), %rcx
movslq (%rcx,%rdi,4), %rsi
cmpq %rsi, %rax
setl %dl
cmpq %rsi, %rdi
setge %dil
testb %dil, %dl
jne 0x114ec
movslq (%rcx,%rax,4), %rsi
movq 0x8(%rsp), %rdi
callq 0x10ed8
cmpl %ebx, %eax
cmovgel %ebx, %eax
movq (%r15), %rdx
movq 0x8(%r15), %rsi
movq (%r14), %rdi
movq 0x50(%r12), %r8
movq 0x70(%r12), %r9
movl 0x10(%r14), %ecx
testb $0x1, %bpl
jne 0x1154b
cmpq %rsi, %r13
jae 0x1154b
cmpl %eax, %ecx
jge 0x1154b
movl (%r9,%rdi,4), %r10d
movslq %ecx, %r11
addq %r8, %r10
movb (%r11,%r10), %r10b
xorl %r11d, %r11d
cmpb (%rdx,%r13), %r10b
setne %bpl
sete %r11b
incq %r13
addl %r11d, %ecx
movl %ecx, 0x10(%r14)
jmp 0x11513
xorl %eax, %eax
cmpq 0x8(%r15), %r13
jae 0x11423
testb $0x1, %bpl
jne 0x11423
cmpl %ebx, %ecx
jge 0x11423
movq (%r15), %rax
movsbl (%rax,%r13), %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x11fba
jmp 0x11423
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq