// File: /workspace/github_cpp_makefile_star2_O3/readmapping[P]alfalfa/src/sparseSA.cpp
// Function: sparseSA::computeKmer()
void sparseSA::computeKmer() {
    stack<interval_t> intervalStack;
    stack<unsigned int> indexStack;
    
    interval_t curInterval(0,N/K-1,0);
    unsigned int curIndex = 0;
    unsigned int newIndex = 0;
    
    intervalStack.push(interval_t(0,N/K-1,0));
    indexStack.push(curIndex);
    
    while(!intervalStack.empty()){
        curInterval = intervalStack.top(); intervalStack.pop();
        curIndex = indexStack.top(); indexStack.pop();
        if(KMERSIZE == (long) (curInterval.depth)){
            if(curIndex < TABLESIZE){
                KMR[curIndex].left = curInterval.start;
                KMR[curIndex].right = curInterval.end;
            }
        }
        else{
            if(hasChild){//similar to function traverse_faster
                //walk up to depth KMERSIZE or new child
                long curLCP; //max LCP of this interval
                if (curInterval.start == curInterval.end)//BUGFIX: was omitted first and caused a bug
                    curLCP = N - SA[curInterval.start];
                else if (curInterval.start < CHILD[curInterval.end] && CHILD[curInterval.end] <= curInterval.end)
                    curLCP = LCP[CHILD[curInterval.end]];
                else
                    curLCP = LCP[CHILD[curInterval.start]];
                long minimum = min(curLCP,KMERSIZE);
                newIndex = curIndex;
                while(curInterval.depth < (long) minimum){
                    newIndex = (newIndex << 2) | BITADD[(unsigned char) S[SA[curInterval.start]+curInterval.depth]];
                    curInterval.depth ++;
                }
                if(curInterval.depth == KMERSIZE){//reached KMERSIZE in the middle of an edge
                    if(newIndex < TABLESIZE){
                        KMR[newIndex].left = curInterval.start;
                        KMR[newIndex].right = curInterval.end;
                    }
                }
                else{//find child intervals
                    long left = curInterval.start;
                    long right = CHILD[curInterval.end];
                    curIndex = newIndex;
                    if(curInterval.start >= right || right > curInterval.end)
                        right = CHILD[curInterval.start];
                    //now left and right point to first child
                    newIndex = (curIndex << 2) | BITADD[(unsigned char) S[SA[left]+curInterval.depth]];
                    if(newIndex < TABLESIZE){
                        intervalStack.push(interval_t(left,right-1,curInterval.depth+1));
                        indexStack.push(newIndex);
                    }
                    left = right;
                    //while has next L-index
                    while(CHILD[right] > right && LCP[right] == LCP[CHILD[right]]){
                        right = CHILD[right];
                        newIndex = (curIndex << 2) | BITADD[ (unsigned char) S[SA[left]+curInterval.depth]];
                        if(newIndex < TABLESIZE){
                            intervalStack.push(interval_t(left,right-1,curInterval.depth+1));
                            indexStack.push(newIndex);
                        }
                        left = right;
                    }
                    //last interval
                    newIndex = (curIndex << 2) | BITADD[ (unsigned char) S[SA[left]+curInterval.depth]];
                    if(newIndex < TABLESIZE){
                        intervalStack.push(interval_t(left,curInterval.end,curInterval.depth+1));
                        indexStack.push(newIndex);
                    }
                }
            }
            else{//similar to function traverse
                long start = curInterval.start; long end = curInterval.end;
                while(start <= curInterval.end){//bug: did not calculate correctly
                    newIndex = (curIndex << 2) | BITADD[ (unsigned char) S[SA[start]+curInterval.depth]];
                    start = curInterval.start;
                    end = curInterval.end;
                    top_down_faster(S[SA[start]+curInterval.depth], curInterval.depth, start, end);
                    if(newIndex < TABLESIZE){
                        intervalStack.push(interval_t(start,end,curInterval.depth+1));
                        indexStack.push(newIndex);
                    }
                    // Advance to next interval.
                    start = end+1; end = curInterval.end;
                }
            }
        }
    }
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x175a8
leaq 0x50(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0x1777c
movq 0x38(%r14), %rax
cqto
movq %r14, 0x40(%rsp)
idivq 0xe8(%r14)
movl %ebx, 0xc(%rsp)
movl %ebx, 0x8(%rsp)
decq %rax
leaq 0x18(%rsp), %rsi
movq $0x0, (%rsi)
movq %rax, 0x8(%rsi)
movl %ebx, 0x10(%rsi)
leaq 0xc0(%rsp), %rdi
callq 0x1790e
movq 0x80(%rsp), %rax
movq 0x90(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x10908
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x80(%rsp)
movq 0x40(%rsp), %rbx
jmp 0x1091c
leaq 0x50(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x17b90
movq 0x40(%rsp), %rbx
movq 0xf0(%rsp), %rax
cmpq 0xd0(%rsp), %rax
je 0x10fcf
leaq 0xa0(%rbx), %rcx
movq %rcx, 0x30(%rsp)
leaq 0x33afb(%rip), %r12     # 0x44440
movq 0xf8(%rsp), %rdi
cmpq %rdi, %rax
je 0x10964
leaq -0x18(%rax), %rcx
movq -0x18(%rax), %rbp
movq -0x10(%rax), %r15
movl -0x8(%rax), %r14d
jmp 0x109c6
movq 0x108(%rsp), %rax
movq -0x8(%rax), %rax
movq 0x1e0(%rax), %rbp
movq 0x1e8(%rax), %r15
movl 0x1f0(%rax), %r14d
movl $0x1f8, %esi            # imm = 0x1F8
callq 0x72f0
movq 0x108(%rsp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x108(%rsp)
movq -0x8(%rax), %rcx
movq %rcx, 0xf8(%rsp)
leaq 0x1f8(%rcx), %rax
movq %rax, 0x100(%rsp)
movl $0x1e0, %eax            # imm = 0x1E0
addq %rax, %rcx
movq %rcx, 0xf0(%rsp)
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rdi
cmpq %rdi, %rax
je 0x109f0
movl -0x4(%rax), %ecx
addq $-0x4, %rax
movl %ecx, 0xc(%rsp)
jmp 0x10a47
movq 0x98(%rsp), %rax
movq -0x8(%rax), %rax
movl 0x1fc(%rax), %eax
movl %eax, 0xc(%rsp)
movl $0x200, %esi            # imm = 0x200
callq 0x72f0
movq 0x98(%rsp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x98(%rsp)
movq -0x8(%rax), %rax
movq %rax, 0x88(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x90(%rsp)
movl $0x1fc, %ecx            # imm = 0x1FC
addq %rcx, %rax
movq %rax, 0x80(%rsp)
cmpl $0xa, %r14d
movq %r15, 0x10(%rsp)
jne 0x10a86
movl 0xc(%rsp), %eax
cmpq $0xfffff, %rax          # imm = 0xFFFFF
ja 0x10fb9
movq 0x100(%rbx), %rcx
movl %ebp, (%rcx,%rax,8)
movl 0xc(%rsp), %eax
movq 0x10(%rsp), %rdx
movl %edx, 0x4(%rcx,%rax,8)
jmp 0x10fb9
cmpb $0x0, 0xf0(%rbx)
je 0x10aac
cmpq %rbp, %r15
jne 0x10ce3
movq 0x38(%rbx), %rcx
movq 0x70(%rbx), %rax
movl (%rax,%r15,4), %eax
subq %rax, %rcx
jmp 0x10d15
subq %rbp, %r15
movq %r15, 0xa8(%rsp)
jl 0x10fb9
movslq %r14d, %rax
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rax
leaq -0x1(%rax), %rcx
movq %rcx, 0xa0(%rsp)
incq %rax
movq %rax, 0xb0(%rsp)
leaq 0x1(%rbp), %rax
movq %rax, 0xb8(%rsp)
leal 0x1(%r14), %eax
movl %eax, 0x4c(%rsp)
movq %rbp, %rsi
movl 0xc(%rsp), %eax
shll $0x2, %eax
movq 0x50(%rbx), %rcx
movq 0x70(%rbx), %rdx
movl (%rdx,%rsi,4), %esi
addl %r14d, %esi
movzbl (%rcx,%rsi), %esi
orl (%r12,%rsi,4), %eax
movl %eax, 0x8(%rsp)
movl (%rdx,%rbp,4), %edi
leal (%rdi,%r14), %esi
movb (%rcx,%rsi), %sil
addq %rcx, %rdi
movq 0x38(%rsp), %r8
movb (%r8,%rdi), %r10b
movq %rbp, %r13
movq 0xb8(%rsp), %rdi
cmpb %sil, %r10b
movq 0x10(%rsp), %r15
jg 0x10c6a
movl (%rdx,%r15,4), %edi
addq %rcx, %rdi
movq 0x38(%rsp), %r8
movb (%r8,%rdi), %r9b
movq %r15, %r13
movq 0xb0(%rsp), %rdi
cmpb %sil, %r9b
jl 0x10c6a
movq %rbp, %rdi
movq %r15, %r8
movq %rbp, %r13
cmpb %sil, %r10b
je 0x10c20
movq %r15, %rdi
movq %r15, %r8
movq 0xa0(%rsp), %r13
cmpq $0x2, 0xa8(%rsp)
jl 0x10c20
movq 0x38(%rsp), %rdi
leaq (%rcx,%rdi), %r11
xorl %r10d, %r10d
movq %rbp, %rbx
movq %r15, %rdi
movq %rbp, %r12
movq %r15, %r8
leaq (%rdi,%rbx), %r15
movq %r15, %r13
shrq $0x3f, %r13
addq %r15, %r13
sarq %r13
movl (%rdx,%r13,4), %r15d
cmpb %sil, (%r11,%r15)
jge 0x10bd4
movq %r13, %rbx
jmp 0x10bf7
setne %r15b
orb %r10b, %r15b
testb $0x1, %r15b
cmoveq %rdi, %r8
cmoveq %r13, %r12
movzbl %r10b, %r10d
movl $0x1, %edi
cmovel %edi, %r10d
movq %r13, %rdi
movq %rdi, %r15
subq %rbx, %r15
cmpq $0x1, %r15
jg 0x10bb4
leaq -0x1(%rdi), %r13
testb $0x1, %r10b
cmovneq %r12, %r13
movq 0x40(%rsp), %rbx
leaq 0x33825(%rip), %r12     # 0x44440
movq 0x10(%rsp), %r15
cmpb %sil, %r9b
jne 0x10c2a
movq %r15, %r13
jmp 0x10c6a
movq %r8, %r9
subq %r13, %r9
cmpq $0x2, %r9
jl 0x10c6a
addq 0x38(%rsp), %rcx
leaq (%r8,%r13), %r10
movq %r10, %r9
shrq $0x3f, %r9
addq %r10, %r9
sarq %r9
movl (%rdx,%r9,4), %r10d
cmpb %sil, (%rcx,%r10)
jg 0x10c5b
movq %r9, %r13
jmp 0x10c5e
movq %r9, %r8
movq %r8, %r9
subq %r13, %r9
cmpq $0x1, %r9
jg 0x10c3b
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0x10cd1
movq %rdi, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x28(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1790e
movq 0x80(%rsp), %rax
movq 0x90(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x10cc2
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x80(%rsp)
jmp 0x10cd1
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x17b90
leaq 0x1(%r13), %rsi
cmpq %r15, %r13
jl 0x10af8
jmp 0x10fb9
movq 0xd0(%rbx), %rax
movslq (%rax,%r15,4), %rsi
cmpq %rsi, %rbp
jge 0x10d04
cmpq %rsi, %r15
jl 0x10d04
movq 0x30(%rsp), %rdi
callq 0x15a0e
jmp 0x10d12
movslq (%rax,%rbp,4), %rsi
movq 0x30(%rsp), %rdi
callq 0x15a0e
movslq %eax, %rcx
cmpq $0xa, %rcx
movl $0xa, %edx
cmovlq %rcx, %rdx
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
movslq %r14d, %rdi
movq %rdx, %rsi
subq %rdi, %rsi
jle 0x10d85
movq 0x50(%rbx), %rdi
movq 0x70(%rbx), %r8
shll $0x2, %eax
movl (%r8,%rbp,4), %r9d
addl %r14d, %r9d
movzbl (%rdi,%r9), %r9d
orl (%r12,%r9,4), %eax
movl %eax, 0x8(%rsp)
incl %r14d
decq %rsi
jne 0x10d3d
cmpq $0xa, %rcx
jl 0x10d82
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0x10fb9
movl %eax, %eax
movq 0x100(%rbx), %rcx
movl %ebp, (%rcx,%rax,8)
movl 0x8(%rsp), %eax
jmp 0x10a78
movl %edx, %r14d
movq 0xd0(%rbx), %rcx
movslq (%rcx,%r15,4), %r15
movl %eax, 0xc(%rsp)
cmpq %r15, %rbp
jge 0x10da0
cmpq %r15, 0x10(%rsp)
jge 0x10da4
movslq (%rcx,%rbp,4), %r15
shll $0x2, %eax
movq 0x50(%rbx), %rcx
movq 0x70(%rbx), %rdx
movl (%rdx,%rbp,4), %edx
addl %r14d, %edx
movzbl (%rcx,%rdx), %ecx
orl (%r12,%rcx,4), %eax
movl %eax, 0x8(%rsp)
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0x10e2c
leaq -0x1(%r15), %rax
leal 0x1(%r14), %ecx
movq %rbp, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %ecx, 0x28(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1790e
movq 0x80(%rsp), %rax
movq 0x90(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x10e1d
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x80(%rsp)
jmp 0x10e2c
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x17b90
movq 0xd0(%rbx), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %r15
jge 0x10f24
leal 0x1(%r14), %r12d
movq %r15, %r13
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x15a0e
movl %eax, %ebp
movq 0xd0(%rbx), %rax
movslq (%rax,%r13,4), %rsi
movq 0x30(%rsp), %rdi
callq 0x15a0e
cmpl %eax, %ebp
jne 0x10f21
movq 0xd0(%rbx), %rax
movslq (%rax,%r13,4), %r15
movl 0xc(%rsp), %eax
shll $0x2, %eax
movq 0x50(%rbx), %rcx
movq 0x70(%rbx), %rdx
movl (%rdx,%r13,4), %edx
addl %r14d, %edx
movzbl (%rcx,%rdx), %ecx
leaq 0x335a1(%rip), %rdx     # 0x44440
orl (%rdx,%rcx,4), %eax
movl %eax, 0x8(%rsp)
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0x10f0e
leaq -0x1(%r15), %rax
movq %r13, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %r12d, 0x28(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1790e
movq 0x80(%rsp), %rax
movq 0x90(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x10eff
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x80(%rsp)
jmp 0x10f0e
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x17b90
movq 0xd0(%rbx), %rax
cmpl (%rax,%r15,4), %r15d
jl 0x10e44
jmp 0x10f24
movq %r13, %r15
movl 0xc(%rsp), %eax
shll $0x2, %eax
movq 0x50(%rbx), %rcx
movq 0x70(%rbx), %rdx
movl (%rdx,%r15,4), %edx
addl %r14d, %edx
movzbl (%rcx,%rdx), %ecx
leaq 0x334fb(%rip), %r12     # 0x44440
orl (%r12,%rcx,4), %eax
movl %eax, 0x8(%rsp)
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0x10fb9
incl %r14d
movq %r15, 0x18(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
movl %r14d, 0x28(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1790e
movq 0x80(%rsp), %rax
movq 0x90(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x10faa
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x80(%rsp)
jmp 0x10fb9
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x17b90
movq 0xf0(%rsp), %rax
cmpq 0xd0(%rsp), %rax
jne 0x10945
leaq 0x50(%rsp), %rdi
callq 0x169ca
leaq 0xc0(%rsp), %rdi
callq 0x16a22
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1100f
jmp 0x1100f
movq %rax, %rbx
jmp 0x1101c
jmp 0x1100f
jmp 0x1100f
jmp 0x1100f
jmp 0x1100f
jmp 0x1100f
jmp 0x1100f
jmp 0x1100f
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x169ca
leaq 0xc0(%rsp), %rdi
callq 0x16a22
movq %rbx, %rdi
callq 0x7600
nop