// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movl %r8d, %ebp
movl %edx, %r13d
movq %rsi, 0x28(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x8(%rcx), %rdx
movq -0x18(%rdx), %rbx
movq %rbx, 0x10(%rsp)
movq -0x10(%rdx), %rax
movq %rax, 0x18(%rsp)
movslq -0x8(%rdx), %r14
movl %r14d, 0x20(%rsp)
movq %rax, %r15
subq %rbx, %r15
incq %r15
movslq %r9d, %rdi
cmpq %rdi, %r15
jle 0x11838
addq $-0x18, %rdx
movq %rdx, 0x8(%rcx)
cmpl %ebp, %r14d
setge %sil
testq %r15, %r15
sets %dl
orb %sil, %dl
jne 0x11b36
movq %rdi, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
addl %r14d, %r13d
movq 0x28(%rsp), %rcx
movl 0x8(%rcx), %r12d
movq 0x8(%rsp), %rdi
movq 0xd0(%rdi), %rcx
movslq (%rcx,%rax,4), %rsi
cmpq %rsi, %rbx
setl %dl
cmpq %rsi, %rax
setge %al
addq $0xa0, %rdi
movq %rdi, 0x40(%rsp)
testb %al, %dl
jne 0x11894
movslq (%rcx,%rbx,4), %rsi
movq 0x40(%rsp), %rdi
callq 0x10ed8
cmpl %r12d, %r13d
jge 0x118fa
movslq %r13d, %rcx
movq 0x28(%rsp), %rdx
movq (%rdx), %rdx
movb (%rdx,%rcx), %cl
cmpq $0x2, %r15
jl 0x118ff
cmpl %r14d, %eax
jne 0x118ff
movsbl %cl, %esi
leaq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x11fba
testb %al, %al
je 0x118fa
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
incq %rax
movb $0x1, %r15b
cmpq 0x38(%rsp), %rax
jg 0x11917
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0x117bc
jmp 0x11917
xorl %r15d, %r15d
jmp 0x11917
movq 0x8(%rsp), %rdx
movq 0x70(%rdx), %rax
movl (%rax,%rbx,4), %eax
addq 0x50(%rdx), %rax
cmpb (%r14,%rax), %cl
sete %r15b
xorl %ebx, %ebx
movabsq $0x100000000, %r12      # imm = 0x100000000
testb $0x1, %r15b
je 0x11b06
testb $0x1, %bl
jne 0x11b06
movq 0x28(%rsp), %rax
movq 0x8(%rax), %r10
cmpl %r10d, %r13d
jge 0x11b06
movl 0x20(%rsp), %eax
cmpl %ebp, %eax
jge 0x11b06
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %rcx, %rsi
subq %rdx, %rsi
incq %rsi
js 0x11b06
leal 0x1(%r13), %r14d
incl %eax
movl %eax, 0x20(%rsp)
cmpq %rcx, %rdx
jne 0x119ed
movq 0x8(%rsp), %rdi
movq 0x70(%rdi), %rdx
movq 0x38(%rdi), %rsi
movq 0x50(%rdi), %rdi
movq 0x28(%rsp), %r8
movq (%r8), %r8
movslq %r13d, %r9
movslq %r10d, %r10
incq %r9
movb $0x1, %r15b
testb $0x1, %bl
jne 0x11a90
cmpq %r10, %r9
jge 0x11a90
cmpl %ebp, %eax
jge 0x11a90
movl (%rdx,%rcx,4), %ebx
movslq %eax, %r11
addq %rbx, %r11
movb $0x1, %bl
cmpq %rsi, %r11
jge 0x119d6
movb (%rdi,%r11), %r11b
cmpb (%r8,%r9), %r11b
setne %bl
movl %ebx, %r11d
xorb $0x1, %r11b
movzbl %r11b, %r11d
addl %r11d, %eax
movl %eax, 0x20(%rsp)
incl %r14d
jmp 0x1199b
movq 0x8(%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 0x11a13
movslq (%rax,%rdx,4), %rsi
movq 0x40(%rsp), %rdi
callq 0x10ed8
cmpl %ebp, %eax
cmovgel %ebp, %eax
movl 0x20(%rsp), %esi
movq 0x28(%rsp), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rdi
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %rdx
movq 0x50(%rdx), %r9
movq 0x70(%rdx), %r10
movslq %r14d, %r11
movslq %edi, %r15
movq %r11, %rdx
shlq $0x20, %rdx
movl %r14d, %r13d
testb $0x1, %bl
jne 0x11a98
cmpq %r15, %r11
jge 0x11a98
cmpl %eax, %esi
jge 0x11a98
movl (%r10,%r8,4), %ebx
movslq %esi, %r14
addq %r9, %rbx
movb (%r14,%rbx), %bl
xorl %r14d, %r14d
cmpb (%rcx,%r11), %bl
setne %bl
sete %r14b
incq %r11
addl %r14d, %esi
movl %esi, 0x20(%rsp)
incl %r13d
addq %r12, %rdx
jmp 0x11a54
movl %r14d, %r13d
jmp 0x11923
xorl %r15d, %r15d
cmpl %edi, %r13d
jge 0x11923
testb $0x1, %bl
jne 0x11923
cmpl %ebp, %esi
jge 0x11923
sarq $0x20, %rdx
movsbl (%rcx,%rdx), %esi
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x11fba
xorl %r15d, %r15d
testb %al, %al
je 0x11923
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
incq %rax
movb $0x1, %r15b
cmpq 0x38(%rsp), %rax
jg 0x11923
movq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x117bc
jmp 0x11923
movq 0x30(%rsp), %rcx
movq 0x8(%rcx), %rax
cmpq %rax, (%rcx)
je 0x11b36
movq -0x18(%rax), %rcx
cmpq 0x10(%rsp), %rcx
jne 0x11b36
movq -0x10(%rax), %rcx
cmpq 0x18(%rsp), %rcx
jne 0x11b36
movl 0x20(%rsp), %ecx
cmpl %ecx, -0x8(%rax)
jge 0x11b36
movl %ecx, -0x8(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop