// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/compressed_bitsequence.c
// Function: gt_compressed_bitsequence_select_0
GtUword gt_compressed_bitsequence_select_0(GtCompressedBitsequence *cbs,
                                           GtUword num)
{
  unsigned int block_offset_bits,
               class = cbs->blocksize + 1;
  GtUword block_idx,
          blocks_offset_pos,
          containing_s_block,
          end_s_block, middle_s_block, start_s_block,
          first_0_superblock_rank,
          max_0_rank,
          position,
          rank_sum = 0,
          s_block_bits,
          start, start_l, start_r;
  uint64_t block;

  gt_assert(num != 0);
  gt_assert(cbs != NULL);
  gt_assert(num < cbs->num_of_bits);

  s_block_bits = (GtUword) cbs->blocksize * cbs->superblocksize;
  max_0_rank = cbs->num_of_bits - gt_compressed_bitsequence_get_variable_field(
                      cbs->superblockranks,
                      (cbs->num_of_superblocks - 1) * cbs->superblockranks_bits,
                      cbs->superblockranks_bits);
  if (num > max_0_rank)
    return cbs->num_of_bits;

  first_0_superblock_rank =
    s_block_bits - gt_compressed_bitsequence_get_variable_field(
                                                     cbs->superblockranks, 0,
                                                     cbs->superblockranks_bits);
  if (num <= first_0_superblock_rank) {
    rank_sum = 0;
    containing_s_block = 0;
    blocks_offset_pos = 0;
  }
  else {
    GtUword middle_s_block_max,
            middle_s_block_r_max,
            middle_s_block_l_max;
    /* search for superblock */
    start_s_block = num / s_block_bits; /* cannot be smaller than this */
    end_s_block = cbs->num_of_superblocks;
    middle_s_block = GT_DIV2(start_s_block + end_s_block);
    while (start_s_block < end_s_block) {
      middle_s_block_max = s_block_bits * (middle_s_block+1);
      start = middle_s_block * cbs->superblockranks_bits;
      if ((middle_s_block_max -
            gt_compressed_bitsequence_get_variable_field(
                                                  cbs->superblockranks, start,
                                                  cbs->superblockranks_bits))
          < num) {
        middle_s_block_r_max = middle_s_block_max + s_block_bits;
        start_r = start + cbs->superblockranks_bits;
        if ((middle_s_block_r_max -
              gt_compressed_bitsequence_get_variable_field(
                                                  cbs->superblockranks, start_r,
                                                  cbs->superblockranks_bits))
            < num)
          start_s_block = middle_s_block;
        else
          break;
      }
      else {
        middle_s_block_l_max = middle_s_block_max - s_block_bits;
        start_l = start - cbs->superblockranks_bits;
        if ((middle_s_block_l_max -
               gt_compressed_bitsequence_get_variable_field(
                                                  cbs->superblockranks, start_l,
                                                  cbs->superblockranks_bits))
            >= num)
          end_s_block = middle_s_block;
        else {
          middle_s_block--;
          break;
        }
      }
      middle_s_block = GT_DIV2(start_s_block + end_s_block);
    }
    middle_s_block_max = s_block_bits * (middle_s_block + 1);
    blocks_offset_pos = (GtUword)
      gt_compressed_bitsequence_get_variable_field(
                                   cbs->superblockoffsets,
                                   middle_s_block * cbs->superblockoffsets_bits,
                                   cbs->superblockoffsets_bits);
    rank_sum = (GtUword)
      middle_s_block_max - gt_compressed_bitsequence_get_variable_field(
                                     cbs->superblockranks,
                                     middle_s_block * cbs->superblockranks_bits,
                                     cbs->superblockranks_bits);
    containing_s_block = middle_s_block+1;
  }

  /* search within superblock */
  for (block_idx = containing_s_block * cbs->superblocksize;
       block_idx < cbs->num_of_blocks;
       block_idx++) {
    class = gt_compressed_bitsequence_get_class(cbs, block_idx);
    if (num <= rank_sum + (cbs->blocksize - class))
      break;
    blocks_offset_pos += gt_popcount_tab_offset_bits(cbs->popcount_tab, class);
    rank_sum += cbs->blocksize - class;
  }
  position = block_idx * cbs->blocksize;
  gt_assert(class != cbs->blocksize + 1);
  if (class == 0)
    position += num - rank_sum - 1;
  else {
    block_offset_bits = gt_popcount_tab_offset_bits(cbs->popcount_tab, class);

    /* search within block */
    block = (uint64_t)
      gt_popcount_tab_get(cbs->popcount_tab, class, (GtUword)
                          gt_compressed_bitsequence_get_variable_field(
                                              cbs->c_offsets, blocks_offset_pos,
                                              block_offset_bits));
    if (block_idx != cbs->num_of_blocks - 1)
      block <<= ((sizeof (block) * CHAR_BIT) - cbs->blocksize);
    else
      block <<= ((sizeof (block) * CHAR_BIT) - cbs->last_block_len);

    /* invert because we search for 0 */
    position +=
      gt_compressed_bitsequence_select_1_word(~block,
                                              (unsigned int) (num - rank_sum));
  }

  return position;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rsi, %rsi
je 0x12a9f1
movq %rsi, %rbp
movq %rdi, %r14
movq 0xb0(%rdi), %r15
cmpq %rsi, %r15
jbe 0x12a9f6
movl 0xe8(%r14), %esi
cmpq $0x41, %rsi
jae 0x12a9fb
movl 0xd8(%r14), %eax
movq %rax, 0x8(%rsp)
movl 0xec(%r14), %r13d
movq 0x88(%r14), %r10
movq 0xc0(%r14), %r11
testq %rsi, %rsi
je 0x12a5f0
leaq -0x1(%r11), %rcx
imulq %rsi, %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
movq (%r10,%rdx,8), %rax
shlq %cl, %rax
andl $0x3f, %ecx
leal (%rcx,%rsi), %edi
cmpl $0x41, %edi
jb 0x12a5c8
movq 0x8(%r10,%rdx,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %rax
movq %rsi, %rcx
negq %rcx
shrq %cl, %rax
movq %r15, %rcx
subq %rax, %rcx
cmpq %rbp, %rcx
jb 0x12a9d0
movl $0x40, %ecx
subq %rsi, %rcx
movq (%r10), %rax
shrq %cl, %rax
jmp 0x12a5f2
xorl %eax, %eax
movq %r13, %rbx
imulq 0x8(%rsp), %rbx
movq %rbx, %rcx
subq %rax, %rcx
cmpq %rbp, %rcx
jae 0x12a73c
movq %r13, 0x10(%rsp)
movq %rbp, %rax
xorl %edx, %edx
divq %rbx
leaq (%rax,%r11), %rdi
shrq %rdi
cmpq %r11, %rax
jae 0x12a751
movl $0x40, %edx
subq %rsi, %rdx
leaq 0x1(%rdi), %r15
imulq %rbx, %r15
testq %rsi, %rsi
je 0x12a6c1
movq %rbp, %r9
movq %rdi, %r8
imulq %rsi, %r8
movq %r8, %r13
shrq $0x6, %r13
movq (%r10,%r13,8), %r12
movl %r8d, %ecx
shlq %cl, %r12
movl %r8d, %ecx
andl $0x3f, %ecx
leal (%rcx,%rsi), %ebp
cmpl $0x41, %ebp
jb 0x12a676
movq 0x8(%r10,%r13,8), %r13
negb %cl
shrq %cl, %r13
orq %r13, %r12
movq %r9, %rbp
movl %edx, %ecx
shrq %cl, %r12
movq %r15, %rcx
subq %r12, %rcx
cmpq %r9, %rcx
jae 0x12a6e2
addq %rsi, %r8
movq %r8, %rax
shrq $0x6, %rax
movq (%r10,%rax,8), %r12
movl %r8d, %ecx
shlq %cl, %r12
movl %r8d, %ecx
andl $0x3f, %ecx
leal (%rcx,%rsi), %r8d
cmpl $0x41, %r8d
jb 0x12a6ba
movq 0x8(%r10,%rax,8), %rax
negb %cl
shrq %cl, %rax
orq %rax, %r12
movl %edx, %ecx
shrq %cl, %r12
jmp 0x12a6d2
movl $0x0, %r12d
movl $0x0, %r13d
cmpq %rbp, %r15
jae 0x12a718
addq %rbx, %r15
subq %r12, %r15
movq %rdi, %rax
cmpq %rbp, %r15
jb 0x12a72a
jmp 0x12a751
subq %rsi, %r8
movq %r8, %r11
shrq $0x6, %r11
movq (%r10,%r11,8), %r13
movl %r8d, %ecx
shlq %cl, %r13
movl %r8d, %ecx
andl $0x3f, %ecx
leal (%rcx,%rsi), %r8d
cmpl $0x41, %r8d
jb 0x12a713
movq 0x8(%r10,%r11,8), %r8
negb %cl
shrq %cl, %r8
orq %r8, %r13
movl %edx, %ecx
shrq %cl, %r13
movq %rdi, %rcx
imulq %rbx, %rcx
subq %r13, %rcx
cmpq %rbp, %rcx
jb 0x12a74e
movq %rdi, %r11
leaq (%r11,%rax), %rdi
shrq %rdi
cmpq %r11, %rax
jb 0x12a62f
jmp 0x12a751
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x8(%rsp), %r9
jmp 0x12a802
decq %rdi
movl 0xe4(%r14), %eax
cmpq $0x41, %rax
jae 0x12aa05
leaq 0x1(%rdi), %r15
testq %rax, %rax
movq 0x10(%rsp), %r13
je 0x12a7af
movq 0x80(%r14), %rdx
movq %rdi, %rcx
imulq %rax, %rcx
movq %rcx, %r8
shrq $0x6, %r8
movq (%rdx,%r8,8), %r12
shlq %cl, %r12
andl $0x3f, %ecx
leal (%rcx,%rax), %r11d
cmpl $0x41, %r11d
jb 0x12a7a6
movq 0x8(%rdx,%r8,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %r12
negb %al
movl %eax, %ecx
shrq %cl, %r12
jmp 0x12a7b2
xorl %r12d, %r12d
imulq %r15, %rbx
testq %rsi, %rsi
je 0x12a7f8
imulq %rsi, %rdi
movq %rdi, %rdx
shrq $0x6, %rdx
movq (%r10,%rdx,8), %rax
movl %edi, %ecx
shlq %cl, %rax
movl %edi, %ecx
andl $0x3f, %ecx
leal (%rcx,%rsi), %edi
cmpl $0x41, %edi
jb 0x12a7e9
movq 0x8(%r10,%rdx,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %rax
movq 0x8(%rsp), %r9
negb %sil
movl %esi, %ecx
shrq %cl, %rax
jmp 0x12a7ff
xorl %eax, %eax
movq 0x8(%rsp), %r9
subq %rax, %rbx
imulq %r13, %r15
cmpq 0xb8(%r14), %r15
jae 0x12a9ec
movq 0x78(%r14), %rdx
testq %rdx, %rdx
je 0x12a9e2
movl 0xdc(%r14), %eax
cmpq $0x41, %rax
jae 0x12a9e7
testq %rax, %rax
je 0x12a86c
movq %r15, %rcx
imulq %rax, %rcx
movq %rcx, %rsi
shrq $0x6, %rsi
movq (%rdx,%rsi,8), %r13
shlq %cl, %r13
andl $0x3f, %ecx
leal (%rcx,%rax), %edi
cmpl $0x41, %edi
jb 0x12a863
movq 0x8(%rdx,%rsi,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %r13
negb %al
movl %eax, %ecx
shrq %cl, %r13
jmp 0x12a86f
xorl %r13d, %r13d
movl %r9d, %eax
subl %r13d, %eax
addq %rbx, %rax
cmpq %rbp, %rax
jae 0x12a8ae
movq 0x68(%r14), %rdi
movl %r13d, %esi
callq 0x1643ab
movl %eax, %eax
addq %rax, %r12
movl 0xd8(%r14), %r9d
movl %r9d, %eax
subl %r13d, %eax
addq %rax, %rbx
incq %r15
cmpq 0xb8(%r14), %r15
jb 0x12a813
leal 0x1(%r9), %eax
cmpl %eax, %r13d
je 0x12a9ec
testl %r13d, %r13d
je 0x12a926
movq %r9, 0x8(%rsp)
movq %rbp, 0x10(%rsp)
movq 0x68(%r14), %rdi
movl %r13d, %esi
callq 0x1643ab
cmpl $0x41, %eax
jae 0x12aa00
movq 0x68(%r14), %rdi
xorl %ebp, %ebp
testl %eax, %eax
je 0x12a931
movq 0x70(%r14), %r8
movl %r12d, %esi
movq %r12, %r9
shrq $0x6, %r9
movq (%r8,%r9,8), %rdx
movl %r12d, %ecx
shlq %cl, %rdx
andl $0x3f, %esi
movl %eax, %ecx
addl %esi, %ecx
cmpl $0x41, %ecx
jb 0x12a91d
movq 0x8(%r8,%r9,8), %r8
negb %sil
movl %esi, %ecx
shrq %cl, %r8
orq %r8, %rdx
negb %al
movl %eax, %ecx
shrq %cl, %rdx
jmp 0x12a933
notq %rbx
addq %rbp, %rbx
jmp 0x12a9c6
xorl %edx, %edx
movl %r13d, %esi
callq 0x164278
movq 0xb8(%r14), %rcx
decq %rcx
xorl %edx, %edx
cmpq %rcx, %r15
sete %dl
movb 0xd8(%r14,%rdx,8), %dl
xorl %ecx, %ecx
subb %dl, %cl
shlq %cl, %rax
notq %rax
movq 0x10(%rsp), %rcx
subl %ebx, %ecx
movq %rcx, 0x10(%rsp)
movl $0x38, %ecx
leaq 0x2b0529(%rip), %rdx    # 0x3daea0
xorl %esi, %esi
movq 0x8(%rsp), %r9
movq %rax, %rdi
shrq %cl, %rdi
movzbl %dil, %edi
movzbl (%rdx,%rdi), %r8d
addl %esi, %r8d
cmpl 0x10(%rsp), %r8d
jae 0x12a9ad
addq $-0x8, %rcx
addl $-0x8, %ebp
movl %r8d, %esi
cmpl $-0x40, %ebp
jne 0x12a97e
movl $0x40, %ebx
jmp 0x12a9c6
notl %esi
addl 0x10(%rsp), %esi
shll $0x8, %esi
orq %rsi, %rdi
leaq 0x2b05e0(%rip), %rax    # 0x3dafa0
movzbl (%rax,%rdi), %ebx
subl %ebp, %ebx
movl %r9d, %eax
imulq %rax, %r15
addq %rbx, %r15
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3cb37
callq 0x3ca8c
callq 0x3cafe
callq 0x3cb70
callq 0x3c9e1
callq 0x3ca1a
callq 0x3cac5
callq 0x3ca53