// File: 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:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movl %edx, 0xe4(%rsp)
movq %rcx, 0xd8(%rsp)
movl %r8d, 0xd4(%rsp)
movl %r9d, 0xd0(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x1fc10
movq %rax, %rsi
leaq 0xb8(%rsp), %rdi
callq 0x1fbd0
leaq 0xb8(%rsp), %rdi
callq 0x1fbb0
movslq 0xd0(%rsp), %rcx
cmpq %rcx, %rax
jle 0x20e5a
movq 0xd8(%rsp), %rdi
callq 0x23cc0
movl 0xc8(%rsp), %eax
cmpl 0xd4(%rsp), %eax
jge 0x20e7d
leaq 0xb8(%rsp), %rdi
callq 0x1fbb0
cmpq $-0x1, %rax
jg 0x20e82
jmp 0x21634
movl 0xe4(%rsp), %eax
addl 0xc8(%rsp), %eax
movl %eax, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
movl %eax, 0x8c(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x8630
movq 0x98(%rsp), %rdi
movq %rax, %rcx
movl 0x8c(%rsp), %eax
cmpl %ecx, %eax
setl %al
andb $0x1, %al
movb %al, 0xb3(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x90(%rsp)
addq $0xd0, %rdi
movq 0xc0(%rsp), %rsi
callq 0x237b0
movq %rax, %rcx
movq 0x90(%rsp), %rax
movslq (%rcx), %rcx
cmpq %rcx, %rax
jge 0x20f78
movq 0x98(%rsp), %rdi
addq $0xd0, %rdi
movq 0xc0(%rsp), %rsi
callq 0x237b0
movslq (%rax), %rax
cmpq 0xc0(%rsp), %rax
jg 0x20f78
movq 0x98(%rsp), %rdi
movq %rdi, %rax
addq $0xa0, %rax
movq %rax, 0x80(%rsp)
addq $0xd0, %rdi
movq 0xc0(%rsp), %rsi
callq 0x237b0
movq 0x80(%rsp), %rdi
movslq (%rax), %rsi
callq 0x1ed20
movl %eax, 0xac(%rsp)
jmp 0x20fb6
movq 0x98(%rsp), %rdi
movq %rdi, %rax
addq $0xa0, %rax
movq %rax, 0x78(%rsp)
addq $0xd0, %rdi
movq 0xb8(%rsp), %rsi
callq 0x237b0
movq 0x78(%rsp), %rdi
movslq (%rax), %rsi
callq 0x1ed20
movl %eax, 0xac(%rsp)
testb $0x1, 0xb3(%rsp)
je 0x2105c
leaq 0xb8(%rsp), %rdi
callq 0x1fbb0
cmpq $0x1, %rax
jle 0x2105c
movl 0xac(%rsp), %eax
cmpl 0xc8(%rsp), %eax
jne 0x2105c
movq 0xe8(%rsp), %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8410
movq 0x98(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
movsbl (%rax), %esi
callq 0x237d0
andb $0x1, %al
movb %al, 0xb3(%rsp)
testb $0x1, 0xb3(%rsp)
je 0x2105a
leaq 0xb8(%rsp), %rdi
callq 0x1fbb0
movslq 0xd0(%rsp), %rcx
cmpq %rcx, %rax
jg 0x2105a
movq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x20d60
jmp 0x210da
testb $0x1, 0xb3(%rsp)
je 0x210d8
movq 0xe8(%rsp), %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8410
movq 0x98(%rsp), %rdi
movsbl (%rax), %eax
movl %eax, 0x74(%rsp)
movq %rdi, %rax
addq $0x50, %rax
movq %rax, 0x68(%rsp)
addq $0x70, %rdi
movq 0xb8(%rsp), %rsi
callq 0x1fb90
movq 0x68(%rsp), %rdi
movl (%rax), %eax
movl %eax, %esi
movslq 0xc8(%rsp), %rax
addq %rax, %rsi
callq 0x8410
movq %rax, %rcx
movl 0x74(%rsp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movb %al, 0xb3(%rsp)
jmp 0x210da
movb $0x0, 0xab(%rsp)
xorl %eax, %eax
testb $0x1, 0xb3(%rsp)
movb %al, 0x67(%rsp)
je 0x21160
xorl %eax, %eax
testb $0x1, 0xab(%rsp)
movb %al, 0x67(%rsp)
jne 0x21160
movl 0xb4(%rsp), %eax
movl %eax, 0x60(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x8630
movl 0x60(%rsp), %ecx
movl %eax, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, 0x67(%rsp)
jge 0x21160
movl 0xc8(%rsp), %ecx
xorl %eax, %eax
cmpl 0xd4(%rsp), %ecx
movb %al, 0x5f(%rsp)
jge 0x21158
leaq 0xb8(%rsp), %rdi
callq 0x1fbb0
cmpq $-0x1, %rax
setg %al
movb %al, 0x5f(%rsp)
movb 0x5f(%rsp), %al
movb %al, 0x67(%rsp)
movb 0x67(%rsp), %al
testb $0x1, %al
jne 0x2116d
jmp 0x215b6
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
movl 0xc8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc8(%rsp)
movq 0xb8(%rsp), %rax
cmpq 0xc0(%rsp), %rax
je 0x2146b
movq 0x98(%rsp), %rdi
movq 0xb8(%rsp), %rax
movq %rax, 0x50(%rsp)
addq $0xd0, %rdi
movq 0xc0(%rsp), %rsi
callq 0x237b0
movq %rax, %rcx
movq 0x50(%rsp), %rax
movslq (%rcx), %rcx
cmpq %rcx, %rax
jge 0x21247
movq 0x98(%rsp), %rdi
addq $0xd0, %rdi
movq 0xc0(%rsp), %rsi
callq 0x237b0
movslq (%rax), %rax
cmpq 0xc0(%rsp), %rax
jg 0x21247
movq 0x98(%rsp), %rdi
movq %rdi, %rax
addq $0xa0, %rax
movq %rax, 0x48(%rsp)
addq $0xd0, %rdi
movq 0xc0(%rsp), %rsi
callq 0x237b0
movq 0x48(%rsp), %rdi
movslq (%rax), %rsi
callq 0x1ed20
movl %eax, 0xa4(%rsp)
jmp 0x21285
movq 0x98(%rsp), %rdi
movq %rdi, %rax
addq $0xa0, %rax
movq %rax, 0x40(%rsp)
addq $0xd0, %rdi
movq 0xb8(%rsp), %rsi
callq 0x237b0
movq 0x40(%rsp), %rdi
movslq (%rax), %rsi
callq 0x1ed20
movl %eax, 0xa4(%rsp)
leaq 0xa4(%rsp), %rdi
leaq 0xd4(%rsp), %rsi
callq 0xc080
movl (%rax), %eax
movl %eax, 0xa0(%rsp)
xorl %eax, %eax
testb $0x1, 0xab(%rsp)
movb %al, 0x3f(%rsp)
jne 0x212f0
movl 0xb4(%rsp), %eax
movl %eax, 0x38(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x8630
movl 0x38(%rsp), %ecx
movl %eax, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, 0x3f(%rsp)
jge 0x212f0
movl 0xc8(%rsp), %eax
cmpl 0xa0(%rsp), %eax
setl %al
movb %al, 0x3f(%rsp)
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x212fd
jmp 0x213a1
movq 0x98(%rsp), %rdi
movq %rdi, %rax
addq $0x50, %rax
movq %rax, 0x28(%rsp)
addq $0x70, %rdi
movq 0xb8(%rsp), %rsi
callq 0x1fb90
movq 0x28(%rsp), %rdi
movl (%rax), %eax
movl %eax, %esi
movslq 0xc8(%rsp), %rax
addq %rax, %rsi
callq 0x8410
movsbl (%rax), %eax
movl %eax, 0x34(%rsp)
movq 0xe8(%rsp), %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8410
movq %rax, %rcx
movl 0x34(%rsp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movb %al, 0xab(%rsp)
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
movb 0xab(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
addl 0xc8(%rsp), %eax
movl %eax, 0xc8(%rsp)
jmp 0x212a3
movl 0xb4(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x8630
movl 0x20(%rsp), %ecx
movl %eax, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, 0x27(%rsp)
jge 0x21420
xorl %eax, %eax
testb $0x1, 0xab(%rsp)
movb %al, 0x27(%rsp)
jne 0x21420
movl 0xc8(%rsp), %ecx
xorl %eax, %eax
cmpl 0xd4(%rsp), %ecx
movb %al, 0x27(%rsp)
jge 0x21420
movq 0xe8(%rsp), %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8410
movq 0x98(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
movsbl (%rax), %esi
callq 0x237d0
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
andb $0x1, %al
movb %al, 0xb3(%rsp)
testb $0x1, 0xb3(%rsp)
je 0x21466
leaq 0xb8(%rsp), %rdi
callq 0x1fbb0
movslq 0xd0(%rsp), %rcx
cmpq %rcx, %rax
jg 0x21466
movq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x20d60
jmp 0x215b1
jmp 0x2146d
xorl %eax, %eax
testb $0x1, 0xab(%rsp)
movb %al, 0x1f(%rsp)
jne 0x214ba
movl 0xb4(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x8630
movl 0x18(%rsp), %ecx
movl %eax, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, 0x1f(%rsp)
jge 0x214ba
movl 0xc8(%rsp), %eax
cmpl 0xd4(%rsp), %eax
setl %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x214c7
jmp 0x215af
movq 0x98(%rsp), %rdi
addq $0x70, %rdi
movq 0xb8(%rsp), %rsi
callq 0x1fb90
movq 0x98(%rsp), %rdx
movl (%rax), %eax
movl %eax, %ecx
movslq 0xc8(%rsp), %rax
addq %rax, %rcx
movb $0x1, %al
cmpq 0x38(%rdx), %rcx
movb %al, 0x17(%rsp)
jge 0x21570
movq 0x98(%rsp), %rdi
movq %rdi, %rax
addq $0x50, %rax
movq %rax, 0x8(%rsp)
addq $0x70, %rdi
movq 0xb8(%rsp), %rsi
callq 0x1fb90
movq 0x8(%rsp), %rdi
movl (%rax), %eax
movl %eax, %esi
movslq 0xc8(%rsp), %rax
addq %rax, %rsi
callq 0x8410
movsbl (%rax), %eax
movl %eax, 0x10(%rsp)
movq 0xe8(%rsp), %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8410
movq %rax, %rcx
movl 0x10(%rsp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
setne %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
andb $0x1, %al
movb %al, 0xab(%rsp)
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
movb 0xab(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
addl 0xc8(%rsp), %eax
movl %eax, 0xc8(%rsp)
jmp 0x2146d
jmp 0x215b1
jmp 0x210e2
movq 0xd8(%rsp), %rdi
callq 0x21640
testb $0x1, %al
jne 0x21634
movq 0xd8(%rsp), %rdi
callq 0x1fc10
movq (%rax), %rax
cmpq 0xb8(%rsp), %rax
jne 0x21634
movq 0xd8(%rsp), %rdi
callq 0x1fc10
movq 0x8(%rax), %rax
cmpq 0xc0(%rsp), %rax
jne 0x21634
movq 0xd8(%rsp), %rdi
callq 0x1fc10
movl 0x10(%rax), %eax
cmpl 0xc8(%rsp), %eax
jge 0x21634
movl 0xc8(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x1fc10
movl 0x4(%rsp), %ecx
movl %ecx, 0x10(%rax)
addq $0xf8, %rsp
retq
nopl (%rax)