// File: /workspace/github_c_makefile_star2_O3/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, %ebp
movl $0x1, %eax
movl %ebp, %ecx
shlq %cl, %rax
movq %rax, 0x10(%rsp)
testq %rdi, %rdi
je 0x19ebb5
cmpl $0x40, %ebp
jae 0x19ebba
movl %esi, %r15d
movq %rdi, %r12
callq 0xe7b9c
movq %rax, %r14
movq %r12, %rdi
callq 0xeacd6
testb %al, %al
je 0x19ea55
movl %ebp, %ecx
movq %r14, %rbx
incq %rbx
xorps %xmm0, %xmm0
movq %rbx, 0x20(%rsp)
shrq %cl, %rbx
movq %rsp, %rax
movaps %xmm0, (%rax)
leaq 0x40(,%rbx,8), %rdi
incq %rbx
leaq 0x20510a(%rip), %rsi    # 0x3a3abc
movl $0x31, %edx
callq 0x104226
movq %rax, %r13
addq $0x38, %rax
movq %rax, 0x18(%r13)
movl %ebp, 0x34(%r13)
movq 0x10(%rsp), %rax
movq %rax, 0x28(%r13)
movl %r15d, 0x30(%r13)
movq %rbx, 0x20(%r13)
movq %r12, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0xe91b2
movq %rax, 0x10(%r13)
movq %r12, 0x8(%r13)
leaq 0x1f5(%rip), %rax       # 0x19ebed
movq %rax, (%r13)
andl $-0x3, %r15d
xorl %esi, %esi
cmpl $0x1, %r15d
setne %sil
movq %r12, %rdi
callq 0xeae2c
movq %rax, %r12
movq 0x18(%r13), %rbp
movq %r13, 0x28(%rsp)
movq 0x20(%r13), %rbx
movq $0x0, (%rbp)
movq %rax, %rdi
movq %rsp, %rsi
callq 0xeae9a
testb %al, %al
je 0x19ea82
cmpl $0x1, %r15d
jne 0x19ea93
movq %r14, %rcx
subq (%rsp), %rcx
movq %r14, %rax
subq 0x8(%rsp), %rax
movq %rcx, 0x8(%rsp)
jmp 0x19ea8f
leaq 0x205060(%rip), %rsi    # 0x3a3abc
movl $0x38, %edi
movl $0x46, %edx
callq 0x104226
movq %r14, 0x10(%rax)
leaq 0x220(%rip), %rcx       # 0x19ec96
movq %rcx, (%rax)
movq %r12, 0x8(%rax)
jmp 0x19eba6
movq 0x20(%rsp), %r13
movq %r13, 0x8(%rsp)
movq %r14, %rax
movq %rax, (%rsp)
movl %r15d, 0x1c(%rsp)
cmpq $0x2, %rbx
jl 0x19eb99
leaq (,%rbx,8), %rax
addq %rbp, %rax
movq %rax, 0x30(%rsp)
addq $0x8, %rbp
xorl %eax, %eax
movq 0x10(%rsp), %r15
xorl %ecx, %ecx
cmpq %r15, %rax
jae 0x19eb76
movq (%rsp), %rdx
cmpq %rdx, %rax
cmovbeq %rdx, %rax
cmpq %r15, %rdx
cmovaeq %r15, %rax
movq 0x8(%rsp), %r13
movq %r13, %rdx
subq %rax, %rdx
movq %r15, %rbx
subq %rax, %rbx
cmpq %rbx, %rdx
cmovbq %rdx, %rbx
addq %rcx, %rbx
cmpq %r15, %r13
cmovaeq %r15, %r13
jae 0x19eb7b
movq %r12, %rdi
movq %rsp, %rsi
callq 0xeae9a
testb %al, %al
je 0x19eb2a
cmpl $0x1, 0x1c(%rsp)
jne 0x19eb3b
movq %r14, %rcx
subq (%rsp), %rcx
movq %r14, %rax
subq 0x8(%rsp), %rax
movq %rcx, 0x8(%rsp)
jmp 0x19eb37
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r14, %rax
movq %rax, (%rsp)
movq (%rsp), %rcx
cmpq %rcx, %r13
cmovbeq %rcx, %r13
movq 0x8(%rsp), %rax
cmpq %r15, %rcx
cmovaeq %r15, %r13
movq %rax, %rcx
subq %r13, %rcx
movq %r15, %rdx
subq %r13, %rdx
cmpq %rdx, %rcx
cmovbq %rcx, %rdx
addq %rdx, %rbx
cmpq %r15, %rax
cmovaeq %r15, %rax
movq %rax, %r13
jb 0x19eafe
jmp 0x19eb7e
movq %rcx, %rbx
jmp 0x19eb7e
movq %r13, %rax
movq %rbx, (%rbp)
addq 0x10(%rsp), %r15
addq $0x8, %rbp
movq %rbx, %rcx
cmpq 0x30(%rsp), %rbp
jb 0x19eabf
movq %r12, %rdi
callq 0xeb455
movq 0x28(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x60691
callq 0x6065a