// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %edx, %r13d
movl $0x1, %eax
movl %r13d, %ecx
shlq %cl, %rax
movq %rax, 0x18(%rsp)
testq %rdi, %rdi
je 0x1a7304
cmpl $0x40, %r13d
jae 0x1a7309
movl %esi, %ebp
movq %rdi, %r12
callq 0xec1d8
movq %rax, %r14
movq %r12, %rdi
callq 0xef27f
testb %al, %al
je 0x1a71cb
movl %r13d, %ecx
movq %r14, 0x10(%rsp)
incq %r14
xorps %xmm0, %xmm0
movq %r14, %rbx
shrq %cl, %rbx
movq %rsp, %rax
movaps %xmm0, (%rax)
leaq 0x40(,%rbx,8), %rdi
incq %rbx
leaq 0x205f14(%rip), %rsi    # 0x3ad02d
movl $0x31, %edx
callq 0x1092b2
movq %rax, %r15
addq $0x38, %rax
movq %rax, 0x18(%r15)
movl %r13d, 0x34(%r15)
movq 0x18(%rsp), %rax
movq %rax, 0x28(%r15)
movl %ebp, 0x30(%r15)
movq %rbx, 0x20(%r15)
movq %r12, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0xed76d
movq %rax, 0x10(%r15)
movq %r12, 0x8(%r15)
leaq 0x1de(%rip), %rax       # 0x1a733c
movq %rax, (%r15)
andl $-0x3, %ebp
xorl %esi, %esi
cmpl $0x1, %ebp
setne %sil
movq %r12, %rdi
callq 0xef3d9
movq 0x18(%r15), %rcx
movq %r15, 0x38(%rsp)
movq 0x20(%r15), %rbx
movq %rcx, %r15
movq $0x0, (%rcx)
movq %rax, 0x30(%rsp)
movq %rax, %rdi
movq %rsp, %rsi
callq 0xef451
testb %al, %al
movl %ebp, 0x24(%rsp)
je 0x1a71f8
cmpl $0x1, %ebp
movq %r14, %rdx
movq 0x10(%rsp), %rsi
jne 0x1a7209
movq %rsi, %rax
subq (%rsp), %rax
movq %rsi, %rcx
subq 0x8(%rsp), %rcx
movq %rax, 0x8(%rsp)
movq %rcx, (%rsp)
jmp 0x1a7209
leaq 0x205e5b(%rip), %rsi    # 0x3ad02d
movl $0x38, %edi
movl $0x46, %edx
callq 0x1092b2
movq %r14, 0x10(%rax)
leaq 0x1f9(%rip), %rcx       # 0x1a73e5
movq %rcx, (%rax)
movq %r12, 0x8(%rax)
jmp 0x1a72f5
movq %r14, 0x8(%rsp)
movq 0x10(%rsp), %rsi
movq %rsi, (%rsp)
movq %r14, %rdx
cmpq $0x2, %rbx
jl 0x1a72e6
leaq (%r15,%rbx,8), %rax
movq %rax, 0x40(%rsp)
addq $0x8, %r15
movq %r15, 0x28(%rsp)
xorl %ebx, %ebx
movq 0x18(%rsp), %r12
xorl %r13d, %r13d
cmpq %r12, %rbx
jae 0x1a72c5
movq (%rsp), %rax
cmpq %rax, %rbx
cmovbeq %rax, %rbx
cmpq %r12, %rax
cmovaeq %r12, %rbx
movq 0x8(%rsp), %r14
movq %r14, %rax
subq %rbx, %rax
movq %r12, %rbp
subq %rbx, %rbp
cmpq %rbp, %rax
cmovbq %rax, %rbp
movq %r12, %rbx
cmpq %r12, %r14
cmovbq %r14, %rbx
jae 0x1a72b9
movq %rdx, %r15
movq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0xef451
testb %al, %al
je 0x1a72a8
cmpl $0x1, 0x24(%rsp)
movq %r15, %rdx
jne 0x1a72b9
movq 0x10(%rsp), %rcx
movq %rcx, %rax
subq (%rsp), %rax
subq 0x8(%rsp), %rcx
movq %rax, 0x8(%rsp)
movq %rcx, (%rsp)
jmp 0x1a72b9
movq %r15, %rdx
movq %r15, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
addq %rbp, %r13
cmpq %r12, %r14
jb 0x1a7238
movq 0x28(%rsp), %rax
movq %r13, (%rax)
addq 0x18(%rsp), %r12
addq $0x8, %rax
movq %rax, 0x28(%rsp)
cmpq 0x40(%rsp), %rax
jb 0x1a722f
movq 0x30(%rsp), %rdi
callq 0xefa48
movq 0x38(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x61b73
callq 0x61b3c