// File: /workspace/github_cpp_makefile_star2_O3/readmapping[P]alfalfa/src/sparseSA.cpp
// Function: sparseSA::traverse_keep(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, std::vector<interval_t, std::allocator<interval_t>>&, int, int) const
void sparseSA::traverse_keep(const string &P,const int prefix, vector<interval_t> &current, int min_len, int maxBranching) const{
    interval_t cur = current.back();
    if(cur.size() > maxBranching ) current.pop_back();
    if(cur.depth >= min_len || cur.size() <= -1) return;
    int c = prefix + cur.depth;
    bool intervalFound = c < (int) 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);
        if(intervalFound && cur.size() <= maxBranching) current.push_back(cur);
    }
    else if(intervalFound)
        intervalFound = P[c] == S[((long)SA[cur.start])+cur.depth];
    bool mismatchFound = false;
    while(intervalFound && !mismatchFound &&
            c < (int) P.length() && (cur.depth < min_len && cur.size() > -1)){
        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 < (int) P.length() && cur.depth < minimum){
                mismatchFound = S[((long)SA[cur.start])+cur.depth] != P[c];
                c++;
                cur.depth += !mismatchFound;
            }
            intervalFound = c < (int) P.length() && !mismatchFound &&
                    cur.depth < min_len && top_down_child(P[c], cur);
            if(intervalFound && cur.size() <= maxBranching) current.push_back(cur);
        }
        else{
            while(!mismatchFound && c < (int) 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;
            }
        }
    }
    if(!current.empty() && current.back().start == cur.start && current.back().end == cur.end && current.back().depth < cur.depth)
        current.back().depth = cur.depth;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, 0x8(%rsp)
movl %edx, %r13d
movq %rsi, 0x38(%rsp)
movq 0x8(%rcx), %rax
movq -0x18(%rax), %r12
movq %r12, 0x18(%rsp)
movq -0x10(%rax), %rbx
movq %rbx, 0x20(%rsp)
movslq -0x8(%rax), %rbp
movl %ebp, 0x28(%rsp)
movq %rbx, %r14
subq %r12, %r14
incq %r14
movslq %r9d, %rsi
cmpq %rsi, %r14
jle 0x163b2
addq $-0x18, %rax
movq %rax, 0x8(%rcx)
cmpl 0x8(%rsp), %ebp
setge %al
testq %r14, %r14
sets %dl
orb %al, %dl
jne 0x1687b
movq %rsi, 0x50(%rsp)
movq %rcx, 0x30(%rsp)
addl %ebp, %r13d
movq 0x38(%rsp), %rax
movl 0x8(%rax), %r15d
movq 0xd0(%rdi), %rax
movslq (%rax,%rbx,4), %rsi
cmpq %rsi, %r12
setl %cl
cmpq %rsi, %rbx
setge %dl
movq %rdi, 0x10(%rsp)
addq $0xa0, %rdi
movq %rdi, 0x40(%rsp)
testb %dl, %cl
jne 0x1640d
movslq (%rax,%r12,4), %rsi
movq 0x40(%rsp), %rdi
callq 0x15a0e
cmpl %r15d, %r13d
movq 0x30(%rsp), %r15
jge 0x16850
movslq %r13d, %rcx
movq 0x38(%rsp), %rdx
movq (%rdx), %rdx
movb (%rdx,%rcx), %dil
cmpq $0x2, %r14
jl 0x16484
cmpl %ebp, %eax
jne 0x16484
movq 0x10(%rsp), %rsi
movq 0xd0(%rsi), %rax
movslq (%rax,%rbx,4), %r14
cmpq %r14, %r12
setl %cl
cmpq %r14, %rbx
setge %dl
testb %dl, %cl
jne 0x16462
movslq (%rax,%r12,4), %r14
movq 0x50(%rsi), %rcx
movq 0x70(%rsi), %rdx
movl (%rdx,%r12,4), %esi
addl %ebp, %esi
cmpb %dil, (%rcx,%rsi)
jne 0x164a5
leaq -0x1(%r14), %rax
movq %rax, 0x20(%rsp)
jmp 0x16564
movq 0x10(%rsp), %rcx
movq 0x70(%rcx), %rax
movl (%rax,%r12,4), %eax
addq 0x50(%rcx), %rax
cmpb (%rbp,%rax), %dil
je 0x1657b
jmp 0x16850
movq %r13, 0x48(%rsp)
movslq (%rax,%r14,4), %rax
cmpq %rax, %r14
jge 0x16514
movq 0x40(%rsp), %r12
movq 0x10(%rsp), %r15
movl %edi, %r13d
movq %r12, %rdi
movq %r14, %rsi
callq 0x15a0e
movl %eax, 0xc(%rsp)
movq 0xd0(%r15), %rax
movslq (%rax,%r14,4), %rsi
movq %r12, %rdi
callq 0x15a0e
movq 0x50(%r15), %rcx
movq 0x70(%r15), %rdx
cmpl %eax, 0xc(%rsp)
jne 0x16519
movq 0xd0(%r15), %rsi
movslq (%rsi,%r14,4), %rax
movl (%rdx,%r14,4), %edi
addl %ebp, %edi
cmpb %r13b, (%rcx,%rdi)
je 0x16546
movl %r13d, %edi
movq %rax, %r14
cmpl (%rsi,%rax,4), %eax
jl 0x164bd
jmp 0x1651f
movq %r14, %rax
jmp 0x1651f
movq %r14, %rax
movl %r13d, %edi
addl (%rdx,%rax,4), %ebp
cmpb %dil, (%rcx,%rbp)
movq 0x30(%rsp), %r15
movq 0x48(%rsp), %r13
jne 0x16850
movq %rax, 0x18(%rsp)
incq %rbx
movq %rax, %r12
movq %rbx, %r14
jmp 0x16564
movq %r14, 0x18(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq %r14, %r12
movq %rax, %r14
movq 0x30(%rsp), %r15
movq 0x48(%rsp), %r13
subq %r12, %r14
cmpq 0x50(%rsp), %r14
jg 0x1657b
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x1633a
xorl %ebx, %ebx
movq 0x38(%rsp), %rax
movq 0x8(%rax), %r9
cmpl %r9d, %r13d
jge 0x16850
movl 0x28(%rsp), %eax
cmpl 0x8(%rsp), %eax
jge 0x16850
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %rcx, %rsi
subq %rdx, %rsi
incq %rsi
js 0x16850
leal 0x1(%r13), %r12d
incl %eax
movl %eax, 0x28(%rsp)
cmpq %rcx, %rdx
jne 0x16650
cmpl %r9d, %r12d
jge 0x16827
movslq %r13d, %r12
cmpl 0x8(%rsp), %eax
jge 0x167e5
movq 0x10(%rsp), %rdi
movq 0x70(%rdi), %rdx
movq 0x38(%rdi), %rsi
movq 0x50(%rdi), %rdi
movq 0x38(%rsp), %r8
movq (%r8), %r8
movslq %r9d, %r9
addq $0x2, %r12
movl (%rdx,%rcx,4), %r11d
movslq %eax, %r10
addq %r11, %r10
movb $0x1, %bl
cmpq %rsi, %r10
jge 0x1661c
movb (%rdi,%r10), %r10b
cmpb -0x1(%r8,%r12), %r10b
setne %bl
movl %ebx, %r10d
xorb $0x1, %r10b
movzbl %r10b, %r10d
addl %r10d, %eax
movl %eax, 0x28(%rsp)
testb %bl, %bl
jne 0x16827
cmpq %r9, %r12
jge 0x16827
incq %r12
cmpl 0x8(%rsp), %eax
jl 0x165ff
decq %r12
jmp 0x16827
movq 0x10(%rsp), %rax
movq 0xd0(%rax), %rax
movslq (%rax,%rcx,4), %rsi
cmpq %rsi, %rdx
setl %dil
cmpq %rsi, %rcx
setge %cl
testb %cl, %dil
jne 0x16676
movslq (%rax,%rdx,4), %rsi
movq 0x40(%rsp), %rdi
callq 0x15a0e
movl 0x8(%rsp), %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
movl 0x28(%rsp), %ecx
movq 0x38(%rsp), %rdx
movq (%rdx), %r8
movq 0x8(%rdx), %r9
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x50(%rsi), %rdx
movq 0x70(%rsi), %rsi
movslq %r12d, %r12
movslq %r9d, %r10
cmpq %r12, %r10
jle 0x16710
cmpl %eax, %ecx
jge 0x16710
movslq %ecx, %r11
cltq
incq %r11
movl (%rsi,%rdi,4), %ebx
addq %rdx, %rbx
movb -0x1(%r11,%rbx), %bl
movb (%r8,%r12), %bpl
xorl %r14d, %r14d
cmpb %bpl, %bl
sete %r14b
addl %ecx, %r14d
movl %r14d, 0x28(%rsp)
cmpb %bpl, %bl
jne 0x16850
incq %r12
incl %ecx
cmpq %r10, %r12
jge 0x16702
leaq 0x1(%r11), %r14
cmpq %rax, %r11
movq %r14, %r11
jl 0x166c2
xorl %eax, %eax
cmpb %bpl, %bl
sete %al
addl %eax, %ecx
decl %ecx
xorl %ebx, %ebx
cmpl %r9d, %r12d
jge 0x16850
cmpl 0x8(%rsp), %ecx
jge 0x16850
movq 0x20(%rsp), %r9
movq 0x10(%rsp), %rax
movq 0xd0(%rax), %rax
movslq (%rax,%r9,4), %r13
cmpq %r13, %rdi
setl %r10b
cmpq %r13, %r9
setge %r9b
testb %r9b, %r10b
jne 0x1674f
movslq (%rax,%rdi,4), %r13
movslq %r12d, %r9
movb (%r8,%r9), %r9b
movl (%rsi,%rdi,4), %r8d
addl %ecx, %r8d
movb %r9b, 0xc(%rsp)
cmpb %r9b, (%rdx,%r8)
jne 0x16776
leaq -0x1(%r13), %rax
movq %rax, 0x20(%rsp)
jmp 0x16810
movslq (%rax,%r13,4), %rdi
movq %r13, %rax
cmpq %rdi, %r13
jge 0x167ed
movq 0x40(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x15a0e
movl %eax, %r14d
movq 0x10(%rsp), %r15
movq 0xd0(%r15), %rax
movslq (%rax,%r13,4), %rsi
movq %rbp, %rdi
callq 0x15a0e
movq 0x50(%r15), %rdx
movq 0x70(%r15), %rsi
movl 0x28(%rsp), %ecx
cmpl %eax, %r14d
jne 0x167ea
movq 0xd0(%r15), %rdi
movslq (%rdi,%r13,4), %rax
movl (%rsi,%r13,4), %r8d
addl %ecx, %r8d
movb 0xc(%rsp), %r9b
cmpb %r9b, (%rdx,%r8)
je 0x16835
movq %rax, %r13
cmpl (%rdi,%rax,4), %eax
jl 0x16782
jmp 0x167ed
incq %r12
jmp 0x16827
movq %r13, %rax
addl (%rsi,%rax,4), %ecx
movb 0xc(%rsp), %sil
cmpb %sil, (%rdx,%rcx)
movq 0x30(%rsp), %r15
jne 0x16850
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %r13
incq %r13
movq %rax, %rdi
subq %rdi, %r13
cmpq 0x50(%rsp), %r13
jg 0x16827
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
callq 0x1633a
movl %r12d, %r13d
testb $0x1, %bl
je 0x1657d
jmp 0x16850
movq %r13, 0x18(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq %r13, %rdi
movq %rax, %r13
movq 0x30(%rsp), %r15
jmp 0x16810
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
je 0x1687b
movq -0x18(%rax), %rcx
cmpq 0x18(%rsp), %rcx
jne 0x1687b
movq -0x10(%rax), %rcx
cmpq 0x20(%rsp), %rcx
jne 0x1687b
movl 0x28(%rsp), %ecx
cmpl %ecx, -0x8(%rax)
jge 0x1687b
movl %ecx, -0x8(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq