// File: /workspace/github_cpp_makefile_star2_O2/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 $0xf8, %rsp
movq %rdi, %rbx
leaq 0x58(%rsp), %rdi
callq 0x10f12
leaq 0xa8(%rsp), %rdi
callq 0x10f2e
movq 0x38(%rbx), %rax
cqto
idivq 0xe8(%rbx)
andl $0x0, 0xc(%rsp)
andl $0x0, 0x8(%rsp)
decq %rax
leaq 0x10(%rsp), %rsi
andq $0x0, (%rsi)
movq %rax, 0x8(%rsi)
andl $0x0, 0x10(%rsi)
leaq 0x58(%rsp), %rdi
callq 0x12fd8
leaq 0xa8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x1324a
leaq 0xa0(%rbx), %rax
movq %rax, 0x28(%rsp)
movq 0x88(%rsp), %rax
cmpq 0x68(%rsp), %rax
je 0xdf12
cmpq 0x90(%rsp), %rax
jne 0xdb2d
movq 0xa0(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x1f8, %ecx            # imm = 0x1F8
addq %rcx, %rax
movq -0x18(%rax), %r12
movq -0x10(%rax), %rbp
movl -0x8(%rax), %r13d
leaq 0x58(%rsp), %rdi
callq 0x1347e
movq 0xd8(%rsp), %rax
cmpq 0xe0(%rsp), %rax
leaq 0xa8(%rsp), %r14
jne 0xdb71
movq 0xf0(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movl -0x4(%rax), %eax
movl %eax, 0xc(%rsp)
movq %r14, %rdi
callq 0x134d4
cmpl $0xa, %r13d
jne 0xdbae
movl 0xc(%rsp), %eax
cmpq $0xfffff, %rax          # imm = 0xFFFFF
ja 0xdafc
movq 0x100(%rbx), %rcx
movl %r12d, (%rcx,%rax,8)
movl 0xc(%rsp), %eax
movl %ebp, 0x4(%rcx,%rax,8)
jmp 0xdafc
movslq %r13d, %r15
cmpb $0x1, 0xf0(%rbx)
jne 0xdbdc
movq %r13, 0x40(%rsp)
cmpq %rbp, %r12
jne 0xdc97
movq 0x38(%rbx), %rsi
movq 0x70(%rbx), %rax
movl (%rax,%r12,4), %eax
subq %rax, %rsi
jmp 0xdcc9
movq %r12, 0x38(%rsp)
incl %r13d
movq %r12, %rax
movq %rbp, 0x30(%rsp)
cmpq %rbp, %rax
jg 0xdafc
movl 0xc(%rsp), %ecx
shll $0x2, %ecx
movq 0x50(%rbx), %rdx
movq 0x70(%rbx), %rsi
movl (%rsi,%rax,4), %eax
addl %r15d, %eax
movzbl (%rdx,%rax), %eax
leaq 0x2884b(%rip), %rdi     # 0x36460
orl (%rdi,%rax,4), %ecx
movl %ecx, 0x8(%rsp)
movq %r12, 0x38(%rsp)
movq %rbp, 0x30(%rsp)
movl (%rsi,%r12,4), %eax
addl %r15d, %eax
movsbl (%rdx,%rax), %esi
movq %rbx, %rdi
movq %r15, %rdx
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x10f4a
cmpl $0xfffff, 0x8(%rsp)     # imm = 0xFFFFF
ja 0xdc85
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movl %r13d, 0x20(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12fd8
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x1324a
movq 0x30(%rsp), %rax
incq %rax
movq %rax, 0x38(%rsp)
jmp 0xdbe7
movq 0xd0(%rbx), %rax
movslq (%rax,%rbp,4), %rsi
cmpq %rsi, %r12
jge 0xdcb8
cmpq %rsi, %rbp
jl 0xdcb8
movq 0x28(%rsp), %rdi
callq 0x10ed8
jmp 0xdcc6
movslq (%rax,%r12,4), %rsi
movq 0x28(%rsp), %rdi
callq 0x10ed8
movslq %eax, %rsi
cmpq $0xa, %rsi
pushq $0xa
popq %rax
cmovgeq %rax, %rsi
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x50(%rbx), %rcx
movq 0x70(%rbx), %rdx
movl %r15d, %edi
xorl %r13d, %r13d
leaq (%r15,%r13), %r8
cmpq %r8, %rsi
jle 0xdd17
shll $0x2, %eax
leal (%rdi,%r13), %r8d
addl (%rdx,%r12,4), %r8d
movzbl (%rcx,%r8), %r8d
leaq 0x28756(%rip), %r9      # 0x36460
orl (%r9,%r8,4), %eax
movl %eax, 0x8(%rsp)
incq %r13
jmp 0xdcea
cmpq $0xa, %r8
je 0xddae
movq 0xd0(%rbx), %rsi
movslq (%rsi,%rbp,4), %r14
movl %eax, 0xc(%rsp)
cmpq %r14, %r12
jge 0xdd3a
cmpq %r14, %rbp
jge 0xdd3e
movslq (%rsi,%r12,4), %r14
shll $0x2, %eax
movl (%rdx,%r12,4), %edx
movq 0x40(%rsp), %rsi
addl %esi, %edx
addl %r13d, %edx
movzbl (%rcx,%rdx), %ecx
leaq 0x28706(%rip), %rdx     # 0x36460
orl (%rdx,%rcx,4), %eax
movl %eax, 0x8(%rsp)
cmpl $0x100000, %eax         # imm = 0x100000
jae 0xddd3
leaq -0x1(%r14), %rax
leaq (%rsi,%r13), %rcx
incq %rcx
movq %r12, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq %rcx, 0x48(%rsp)
movl %ecx, 0x20(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12fd8
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1324a
movq 0x40(%rsp), %rsi
jmp 0xddde
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0xdafc
movl %eax, %eax
movq 0x100(%rbx), %rcx
movl %r12d, (%rcx,%rax,8)
movl 0x8(%rsp), %eax
movl %ebp, 0x4(%rcx,%rax,8)
jmp 0xdafc
leal (%rsi,%r13), %eax
incl %eax
movq %rax, 0x48(%rsp)
addq %r13, %rsi
movq %rsi, 0x50(%rsp)
movq %r14, %r15
movq 0xd0(%rbx), %rax
movslq (%rax,%r14,4), %rax
cmpq %rax, %r14
jge 0xdea0
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x10ed8
movl %eax, %r12d
movq 0xd0(%rbx), %rax
movslq (%rax,%r15,4), %rsi
movq 0x28(%rsp), %rdi
callq 0x10ed8
movl 0xc(%rsp), %ecx
cmpl %eax, %r12d
jne 0xdea4
movq 0xd0(%rbx), %rax
movslq (%rax,%r15,4), %r14
shll $0x2, %ecx
movq 0x50(%rbx), %rax
movq 0x70(%rbx), %rdx
movl (%rdx,%r15,4), %edx
addl 0x50(%rsp), %edx
movzbl (%rax,%rdx), %eax
leaq 0x2860c(%rip), %rdx     # 0x36460
orl (%rdx,%rax,4), %ecx
movl %ecx, 0x8(%rsp)
cmpl $0xfffff, %ecx          # imm = 0xFFFFF
ja 0xdde6
leaq -0x1(%r14), %rax
movq %r15, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
movl %eax, 0x20(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12fd8
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1324a
jmp 0xdde6
movl 0xc(%rsp), %ecx
shll $0x2, %ecx
movq 0x50(%rbx), %rax
movq 0x70(%rbx), %rdx
movl (%rdx,%r15,4), %edx
addl 0x40(%rsp), %edx
addl %edx, %r13d
movzbl (%rax,%r13), %eax
leaq 0x2859a(%rip), %rdx     # 0x36460
orl (%rdx,%rax,4), %ecx
movl %ecx, 0x8(%rsp)
cmpl $0xfffff, %ecx          # imm = 0xFFFFF
ja 0xdafc
movq %r15, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
movq 0x48(%rsp), %rax
movl %eax, 0x20(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12fd8
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1324a
jmp 0xdafc
leaq 0xa8(%rsp), %rdi
callq 0x11d38
leaq 0x58(%rsp), %rdi
callq 0x11d90
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xdf52
jmp 0xdf52
movq %rax, %rbx
jmp 0xdf62
jmp 0xdf52
jmp 0xdf52
jmp 0xdf52
jmp 0xdf52
jmp 0xdf52
jmp 0xdf52
jmp 0xdf52
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x11d38
leaq 0x58(%rsp), %rdi
callq 0x11d90
movq %rbx, %rdi
callq 0x75e0