// File: /workspace/github_cpp_makefile_star2_O1/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 $0x108, %rsp            # imm = 0x108
movq %rdi, %r12
xorps %xmm0, %xmm0
leaq 0xb0(%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 0x17840
leaq 0x40(%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 0x17a14
movq 0x38(%r12), %rax
cqto
idivq 0xe8(%r12)
movl %ebx, 0x4(%rsp)
movl %ebx, (%rsp)
decq %rax
leaq 0x18(%rsp), %rsi
movq $0x0, (%rsi)
movq %rax, 0x8(%rsi)
movl %ebx, 0x10(%rsi)
leaq 0xb0(%rsp), %rdi
callq 0x17ba6
movq 0x70(%rsp), %rax
movq 0x80(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x10ab5
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x70(%rsp)
jmp 0x10ac4
leaq 0x40(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x17e28
movq 0xe0(%rsp), %rax
cmpq 0xc0(%rsp), %rax
je 0x11147
leaq 0xa0(%r12), %rcx
movq %rcx, 0x30(%rsp)
leaq 0x33952(%rip), %rbx     # 0x44440
movq %r12, 0x90(%rsp)
movq 0xe8(%rsp), %rdi
movq %rax, %rcx
cmpq %rdi, %rax
jne 0x10b1a
movq 0xf8(%rsp), %rcx
movq -0x8(%rcx), %rcx
movl $0x1f8, %edx            # imm = 0x1F8
addq %rdx, %rcx
movq -0x18(%rcx), %rbp
movq -0x10(%rcx), %r15
movl -0x8(%rcx), %r14d
cmpq %rdi, %rax
je 0x10b31
addq $-0x18, %rax
jmp 0x10b70
movl $0x1f8, %esi            # imm = 0x1F8
callq 0x72f0
movq 0xf8(%rsp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0xf8(%rsp)
movq -0x8(%rax), %rax
movq %rax, 0xe8(%rsp)
leaq 0x1f8(%rax), %rcx
movq %rcx, 0xf0(%rsp)
addq $0x1e0, %rax            # imm = 0x1E0
movq %rax, 0xe0(%rsp)
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rdi
cmpq %rdi, %rax
je 0x10b94
movl -0x4(%rax), %ecx
addq $-0x4, %rax
movl %ecx, 0x4(%rsp)
jmp 0x10be8
movq 0x88(%rsp), %rax
movq -0x8(%rax), %rax
movl 0x1fc(%rax), %eax
movl %eax, 0x4(%rsp)
movl $0x200, %esi            # imm = 0x200
callq 0x72f0
movq 0x88(%rsp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x88(%rsp)
movq -0x8(%rax), %rax
movq %rax, 0x78(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x80(%rsp)
movl $0x1fc, %ecx            # imm = 0x1FC
addq %rcx, %rax
movq %rax, 0x70(%rsp)
cmpl $0xa, %r14d
movq %r15, 0x8(%rsp)
jne 0x10c25
movl 0x4(%rsp), %eax
cmpq $0xfffff, %rax          # imm = 0xFFFFF
ja 0x11131
movq 0x100(%r12), %rcx
movl %ebp, (%rcx,%rax,8)
movl 0x4(%rsp), %eax
movq 0x8(%rsp), %rdx
movl %edx, 0x4(%rcx,%rax,8)
jmp 0x11131
movslq %r14d, %rax
movq %rax, 0x10(%rsp)
cmpb $0x0, 0xf0(%r12)
je 0x10c56
cmpq %rbp, %r15
jne 0x10e73
movq 0x38(%r12), %rax
movq 0x70(%r12), %rcx
movl (%rcx,%rbp,4), %ecx
subq %rcx, %rax
jmp 0x10ea5
subq %rbp, %r15
movq %r15, 0x98(%rsp)
jl 0x11131
movq 0x8(%rsp), %rax
incq %rax
movq %rax, 0xa0(%rsp)
leaq 0x1(%rbp), %rax
movq %rax, 0xa8(%rsp)
leal 0x1(%r14), %eax
movl %eax, 0x3c(%rsp)
movq %rbp, %rsi
movl 0x4(%rsp), %eax
shll $0x2, %eax
movq 0x50(%r12), %rcx
movq 0x70(%r12), %rdx
movl (%rdx,%rsi,4), %esi
addl %r14d, %esi
movzbl (%rcx,%rsi), %esi
orl (%rbx,%rsi,4), %eax
movl %eax, (%rsp)
movl (%rdx,%rbp,4), %edi
leal (%rdi,%r14), %esi
movb (%rcx,%rsi), %sil
addq %rcx, %rdi
movq 0x10(%rsp), %r8
movb (%r8,%rdi), %bl
movq %rbp, %r13
movq 0xa8(%rsp), %rdi
cmpb %sil, %bl
movq 0x8(%rsp), %r15
jg 0x10dfc
movl (%rdx,%r15,4), %edi
addq %rcx, %rdi
movq 0x10(%rsp), %r8
movb (%r8,%rdi), %r9b
movq %r15, %r13
movq 0xa0(%rsp), %rdi
cmpb %sil, %r9b
jl 0x10dfc
movb $0x1, %r10b
movq %r15, %r8
movq %rbp, %r11
movq %rbp, %rdi
cmpb %sil, %bl
je 0x10da6
cmpq $0x2, 0x98(%rsp)
jl 0x10d9a
movq 0x10(%rsp), %rdi
leaq (%rcx,%rdi), %r13
xorl %r10d, %r10d
movq %rbp, %r12
movq %r15, %rdi
movq %rbp, %r11
movq %r15, %r8
leaq (%rdi,%r12), %r15
movq %r15, %rbx
shrq $0x3f, %rbx
addq %r15, %rbx
sarq %rbx
movl (%rdx,%rbx,4), %r15d
cmpb %sil, (%r13,%r15)
jge 0x10d5c
movq %rbx, %r12
jmp 0x10d7f
setne %r15b
orb %r10b, %r15b
testb $0x1, %r15b
cmoveq %rdi, %r8
cmoveq %rbx, %r11
movzbl %r10b, %r10d
movl $0x1, %edi
cmovel %edi, %r10d
movq %rbx, %rdi
movq %rdi, %rbx
subq %r12, %rbx
cmpq $0x1, %rbx
jg 0x10d3b
movq 0x90(%rsp), %r12
movq 0x8(%rsp), %r15
jmp 0x10da6
xorl %r10d, %r10d
movq %r15, %r8
movq %rbp, %r11
movq %r15, %rdi
cmpb %sil, %r9b
jne 0x10db0
movq %r15, %r13
jmp 0x10dfc
leaq -0x1(%rdi), %r13
testb $0x1, %r10b
cmovneq %r11, %r13
movq %r8, %r9
subq %r13, %r9
cmpq $0x2, %r9
jl 0x10dfc
addq 0x10(%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 0x10ded
movq %r9, %r13
jmp 0x10df0
movq %r9, %r8
movq %r8, %r9
subq %r13, %r9
cmpq $0x1, %r9
jg 0x10dcd
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0x10e5a
movq %rdi, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0x28(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x17ba6
movq 0x70(%rsp), %rax
movq 0x80(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x10e4d
movl (%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x70(%rsp)
jmp 0x10e5a
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x17e28
leaq 0x1(%r13), %rsi
cmpq %r15, %r13
leaq 0x335d8(%rip), %rbx     # 0x44440
jl 0x10c8e
jmp 0x11131
movq 0xd0(%r12), %rax
movslq (%rax,%r15,4), %rsi
cmpq %rsi, %rbp
jge 0x10e95
cmpq %rsi, %r15
jl 0x10e95
movq 0x30(%rsp), %rdi
callq 0x15b7a
jmp 0x10ea3
movslq (%rax,%rbp,4), %rsi
movq 0x30(%rsp), %rdi
callq 0x15b7a
cltq
cmpq $0xa, %rax
movl $0xa, %ecx
cmovgeq %rcx, %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rsp)
subq 0x10(%rsp), %rax
jle 0x10ee8
movl (%rsp), %ecx
movq 0x50(%r12), %rdx
movq 0x70(%r12), %rsi
shll $0x2, %ecx
movl (%rsi,%rbp,4), %edi
addl %r14d, %edi
movzbl (%rdx,%rdi), %edi
orl (%rbx,%rdi,4), %ecx
movl %ecx, (%rsp)
incl %r14d
decq %rax
jne 0x10ecd
cmpl $0xa, %r14d
jne 0x10f10
movl (%rsp), %eax
cmpq $0xfffff, %rax          # imm = 0xFFFFF
ja 0x11131
movq 0x100(%r12), %rcx
movl %ebp, (%rcx,%rax,8)
movl (%rsp), %eax
jmp 0x10c17
movq 0xd0(%r12), %rcx
movslq (%rcx,%r15,4), %r15
movl (%rsp), %eax
movl %eax, 0x4(%rsp)
cmpq %r15, %rbp
jge 0x10f2f
cmpq %r15, 0x8(%rsp)
jge 0x10f33
movslq (%rcx,%rbp,4), %r15
shll $0x2, %eax
movq 0x50(%r12), %rcx
movq 0x70(%r12), %rdx
movl (%rdx,%rbp,4), %edx
addl %r14d, %edx
movzbl (%rcx,%rdx), %ecx
orl (%rbx,%rcx,4), %eax
movl %eax, (%rsp)
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0x10fb2
leaq -0x1(%r15), %rax
leal 0x1(%r14), %ecx
movq %rbp, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %ecx, 0x28(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x17ba6
movq 0x70(%rsp), %rax
movq 0x80(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x10fa5
movl (%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x70(%rsp)
jmp 0x10fb2
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x17e28
movq 0xd0(%r12), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %r15
jge 0x110a5
leal 0x1(%r14), %ebx
movq %r15, %r13
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x15b7a
movl %eax, %ebp
movq 0xd0(%r12), %rax
movslq (%rax,%r13,4), %rsi
movq 0x30(%rsp), %rdi
callq 0x15b7a
cmpl %eax, %ebp
jne 0x110a2
movq 0xd0(%r12), %rax
movslq (%rax,%r13,4), %r15
movl 0x4(%rsp), %eax
shll $0x2, %eax
movq 0x50(%r12), %rcx
movq 0x70(%r12), %rdx
movl (%rdx,%r13,4), %edx
addl %r14d, %edx
movzbl (%rcx,%rdx), %ecx
leaq 0x33416(%rip), %rdx     # 0x44440
orl (%rdx,%rcx,4), %eax
movl %eax, (%rsp)
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0x1108e
leaq -0x1(%r15), %rax
movq %r13, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %ebx, 0x28(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x17ba6
movq 0x70(%rsp), %rax
movq 0x80(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x11081
movl (%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x70(%rsp)
jmp 0x1108e
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x17e28
movq 0xd0(%r12), %rax
cmpl (%rax,%r15,4), %r15d
jl 0x10fcb
jmp 0x110a5
movq %r13, %r15
movl 0x4(%rsp), %eax
shll $0x2, %eax
movq 0x50(%r12), %rcx
movq 0x70(%r12), %rdx
movl (%rdx,%r15,4), %edx
addl %r14d, %edx
movzbl (%rcx,%rdx), %ecx
leaq 0x33378(%rip), %rbx     # 0x44440
orl (%rbx,%rcx,4), %eax
movl %eax, (%rsp)
cmpl $0xfffff, %eax          # imm = 0xFFFFF
ja 0x11131
incl %r14d
movq %r15, 0x18(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
movl %r14d, 0x28(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x17ba6
movq 0x70(%rsp), %rax
movq 0x80(%rsp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x11124
movl (%rsp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x70(%rsp)
jmp 0x11131
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x17e28
movq 0xe0(%rsp), %rax
cmpq 0xc0(%rsp), %rax
jne 0x10af6
leaq 0x40(%rsp), %rdi
callq 0x16c20
leaq 0xb0(%rsp), %rdi
callq 0x16c70
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11187
jmp 0x11187
jmp 0x11187
movq %rax, %rbx
jmp 0x11194
jmp 0x11187
jmp 0x11187
jmp 0x11187
jmp 0x11187
jmp 0x11187
jmp 0x11187
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x16c20
leaq 0xb0(%rsp), %rdi
callq 0x16c70
movq %rbx, %rdi
callq 0x7600
nop