// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/eis-specialsrank.c
// Function: gt_newSpecialsRankLookup
SpecialsRankLookup *
gt_newSpecialsRankLookup(const GtEncseq *encseq, GtReadmode readmode,
                         unsigned sampleIntervalLog2)
{
  struct specialsRankLookup *ranker;
  GtUword seqLastPos, seqLen;
  GtUword sampleInterval = ((GtUword)1) << sampleIntervalLog2;
  gt_assert(encseq);
  gt_assert(sampleIntervalLog2 < sizeof (GtUword) * CHAR_BIT);
  seqLastPos = gt_encseq_total_length(encseq);
  seqLen = seqLastPos + 1;
  if (gt_encseq_has_specialranges(encseq))
  {
    /* this sequence has some special characters */
    struct specialsRankTable *rankTable;
    GtSpecialrangeiterator *sri;
    GtUword *sample, *maxSample, sum = 0, pos = 0, nextSamplePos;
    GtRange range = { 0, 0 };
    ranker = allocSpecialsRankTable(encseq, seqLen, sampleIntervalLog2,
                                    readmode);
    rankTable = &ranker->implementationData.sampleTable;
    sri = gt_specialrangeiterator_new(encseq, !GT_ISDIRREVERSE(readmode));
    sample = rankTable->rankSumSamples;
    maxSample = sample + rankTable->numSamples;
    *sample++ = sum;
    nextSamplePos = sampleInterval;
    nextRange(&range, sri, readmode, seqLastPos);
    while (sample < maxSample)
    {
      while (pos < nextSamplePos)
      {
        pos = GT_MIN(GT_MAX(pos, range.start), nextSamplePos);
        sum += GT_MIN(range.end - pos, nextSamplePos - pos);
        pos = GT_MIN(range.end, nextSamplePos);
        if (pos < nextSamplePos)
        {
          nextRange(&range, sri, readmode, seqLastPos);
        }
      }
      *sample++ = sum;
      nextSamplePos += sampleInterval;
    }
    gt_specialrangeiterator_delete(sri);
    sri = NULL;
  }
  else
  {
    /* While there is no special characters in this sequence, there
     * is of course the terminator */
    ranker = allocEmptySpecialsRankLookup(encseq, seqLastPos);
  }
  return ranker;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %r12d
pushq $0x1
popq %rax
movl %r12d, %ecx
shlq %cl, %rax
movq %rax, 0x8(%rsp)
testq %rdi, %rdi
je 0x149e09
cmpl $0x40, %r12d
jae 0x149e33
movl %esi, %ebx
movq %rdi, %r13
callq 0x7055e
movq %rax, %r14
movq %r13, %rdi
callq 0x740a6
testb %al, %al
je 0x149dc7
movl %r12d, %ecx
movq %r14, %r15
incq %r15
xorps %xmm0, %xmm0
shrq %cl, %r15
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
leaq 0x40(,%r15,8), %rdi
incq %r15
leaq 0x1fa17b(%rip), %rsi    # 0x343e33
pushq $0x31
popq %rdx
callq 0x93160
movq %rax, %rbp
addq $0x38, %rax
movq %rax, 0x18(%rbp)
movl %r12d, 0x34(%rbp)
movq 0x8(%rsp), %rax
movq %rax, 0x28(%rbp)
movl %ebx, 0x30(%rbp)
movq %r15, 0x20(%rbp)
xorl %r15d, %r15d
movq %r13, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x72260
movq %rax, 0x10(%rbp)
movq %r13, 0x8(%rbp)
leaq 0x1d9(%rip), %rax       # 0x149ed6
movq %rax, (%rbp)
movl %ebx, %eax
andl $-0x3, %eax
xorl %esi, %esi
cmpl $0x1, %eax
setne %sil
movq %r13, %rdi
callq 0x741f0
movq %rax, %r13
movq 0x18(%rbp), %r12
movq %rbp, 0x20(%rsp)
movq 0x20(%rbp), %rax
leaq (%r12,%rax,8), %rax
movq %rax, 0x28(%rsp)
andq $0x0, (%r12)
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
movl %ebx, %edx
movq %r14, %rcx
callq 0x149e69
movq %r12, %rax
xorl %ebp, %ebp
movq 0x8(%rsp), %r12
addq $0x8, %rax
cmpq 0x28(%rsp), %rax
jae 0x149ded
movq %rax, 0x30(%rsp)
cmpq %r12, %rbp
jae 0x149db8
movq 0x10(%rsp), %rax
cmpq %rax, %rbp
cmovbeq %rax, %rbp
movq 0x18(%rsp), %rcx
cmpq %r12, %rax
cmovaeq %r12, %rbp
movq %rcx, %rax
subq %rbp, %rax
movq %r12, %rdx
subq %rbp, %rdx
cmpq %rdx, %rax
cmovbq %rax, %rdx
addq %rdx, %r15
movq %rcx, %rbp
cmpq %r12, %rcx
cmovaeq %r12, %rbp
jae 0x149d65
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
movl %ebx, %edx
movq %r14, %rcx
callq 0x149e69
jmp 0x149d65
movq 0x30(%rsp), %rax
movq %r15, (%rax)
addq 0x8(%rsp), %r12
jmp 0x149d51
leaq 0x1fa065(%rip), %rsi    # 0x343e33
pushq $0x38
popq %rdi
pushq $0x46
popq %rdx
callq 0x93160
movq %r14, 0x10(%rax)
leaq 0x209(%rip), %rcx       # 0x149fed
movq %rcx, (%rax)
movq %r13, 0x8(%rax)
jmp 0x149dfa
movq %r13, %rdi
callq 0x74a09
movq 0x20(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2ee158(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19b1f9(%rip), %rsi    # 0x2e5013
leaq 0x1dd7d1(%rip), %rdx    # 0x3275f2
leaq 0x1f9ff2(%rip), %rcx    # 0x343e1a
leaq 0x1fa004(%rip), %r8     # 0x343e33
pushq $0x67
jmp 0x149e5b
movq 0x2ee12e(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19b1cf(%rip), %rsi    # 0x2e5013
leaq 0x1fa005(%rip), %rdx    # 0x343e50
leaq 0x1f9fc8(%rip), %rcx    # 0x343e1a
leaq 0x1f9fda(%rip), %r8     # 0x343e33
pushq $0x68
popq %r9
xorl %eax, %eax
callq 0x17a50
callq 0x17390