// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
testq %rsi, %rsi
je 0xbfeea
movq %rsi, %r15
movq %rdi, %r14
movq 0xb0(%rdi), %rbx
cmpq %rsi, %rbx
jbe 0xbff18
movl 0xd8(%r14), %r12d
movl 0xec(%r14), %r13d
movq 0x88(%r14), %rdi
movq 0xc0(%r14), %rsi
decq %rsi
movl 0xe8(%r14), %edx
imulq %rdx, %rsi
callq 0xbfacc
subq %rax, %rbx
cmpq %r15, %rbx
jae 0xbfc8c
movq 0xb0(%r14), %r15
jmp 0xbfed8
movq %r15, %rbx
movq %r12, 0x20(%rsp)
imulq %r12, %r13
movq 0x88(%r14), %rdi
movl 0xe8(%r14), %edx
xorl %r15d, %r15d
xorl %esi, %esi
callq 0xbfacc
movq %r13, %rcx
subq %rax, %rcx
movl $0x0, %edx
movl $0x0, %r12d
cmpq %rbx, %rcx
jae 0xbfde7
movq %rbx, %rax
xorl %edx, %edx
divq %r13
movq 0xc0(%r14), %rcx
movq %rax, %r15
addq %rcx, %r15
movq %r13, 0x18(%rsp)
shrq %r15
cmpq %rcx, %rax
jae 0xbfd9f
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq %rbx, %rbp
leaq 0x1(%r15), %rbx
imulq %r13, %rbx
movl 0xe8(%r14), %edx
movq %r13, %r12
movq %rdx, %r13
imulq %r15, %r13
movq 0x88(%r14), %rdi
movq %r13, %rsi
callq 0xbfacc
movq %rbx, %rcx
subq %rax, %rcx
movl 0xe8(%r14), %edx
movq 0x88(%r14), %rdi
cmpq %rbp, %rcx
jae 0xbfd64
addq %r12, %rbx
addq %rdx, %r13
movq %r13, %rsi
callq 0xbfacc
subq %rax, %rbx
movq %r15, %rax
cmpq %rbp, %rbx
movq %rbp, %rbx
movq %r12, %r13
movq 0x10(%rsp), %rcx
jb 0xbfd8e
jmp 0xbfd9f
movq %r15, %rbx
imulq %r12, %rbx
subq %rdx, %r13
movq %r13, %rsi
callq 0xbfacc
subq %rax, %rbx
cmpq %rbp, %rbx
movq %rbp, %rbx
jb 0xbfd97
movq %r15, %rcx
movq 0x18(%rsp), %r13
movq 0x8(%rsp), %rax
leaq (%rcx,%rax), %r15
jmp 0xbfce4
decq %r15
movq 0x18(%rsp), %r13
leaq 0x1(%r15), %rbp
imulq %rbp, %r13
movq 0x80(%r14), %rdi
movl 0xe4(%r14), %edx
movq %rdx, %rsi
imulq %r15, %rsi
callq 0xbfacc
movq %rax, %r12
movq 0x88(%r14), %rdi
movl 0xe8(%r14), %edx
imulq %rdx, %r15
movq %r15, %rsi
callq 0xbfacc
movq %rbp, %rdx
subq %rax, %r13
movq %r13, %r15
movq 0x20(%rsp), %rax
leal 0x1(%rax), %ebp
movl 0xec(%r14), %r13d
imulq %rdx, %r13
cmpq 0xb8(%r14), %r13
jae 0xbfe44
movq %r14, %rdi
movq %r13, %rsi
callq 0xbfb43
movl %eax, %ebp
movl 0xd8(%r14), %eax
movl %eax, %ecx
subl %ebp, %ecx
addq %r15, %rcx
cmpq %rbx, %rcx
jae 0xbfe4b
movq 0x68(%r14), %rdi
movl %ebp, %esi
callq 0x1047ab
movl %eax, %eax
addq %rax, %r12
movl 0xd8(%r14), %eax
subl %ebp, %eax
addq %rax, %r15
incq %r13
jmp 0xbfdfa
movl 0xd8(%r14), %eax
leal 0x1(%rax), %ecx
cmpl %ecx, %ebp
je 0xbff46
movl %eax, %eax
imulq %r13, %rax
testl %ebp, %ebp
je 0xbfecf
movq 0x68(%r14), %rdi
movl %ebp, %esi
movq %rax, 0x10(%rsp)
callq 0x1047ab
movq 0x68(%r14), %rcx
movq %rcx, 0x8(%rsp)
movq 0x70(%r14), %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0xbfacc
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x104561
movq 0xb8(%r14), %rcx
decq %rcx
xorl %edx, %edx
cmpq %r13, %rcx
sete %dl
xorl %ecx, %ecx
subb 0xd8(%r14,%rdx,8), %cl
shlq %cl, %rax
notq %rax
subl %r15d, %ebx
movq %rax, %rdi
movl %ebx, %esi
callq 0xbfbcb
movl %eax, %r15d
movq 0x10(%rsp), %rax
jmp 0xbfed5
notq %r15
addq %rbx, %r15
addq %rax, %r15
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x378077(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x225118(%rip), %rsi    # 0x2e5013
leaq 0x258a29(%rip), %rdx    # 0x31892b
leaq 0x258a81(%rip), %rcx    # 0x31898a
leaq 0x258926(%rip), %r8     # 0x318836
movl $0x308, %r9d            # imm = 0x308
jmp 0xbff72
movq 0x378049(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2250ea(%rip), %rsi    # 0x2e5013
leaq 0x258a27(%rip), %rdx    # 0x318957
leaq 0x258a53(%rip), %rcx    # 0x31898a
leaq 0x2588f8(%rip), %r8     # 0x318836
movl $0x30a, %r9d            # imm = 0x30A
jmp 0xbff72
movq 0x37801b(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2250bc(%rip), %rsi    # 0x2e5013
leaq 0x258a10(%rip), %rdx    # 0x31896e
leaq 0x258a25(%rip), %rcx    # 0x31898a
leaq 0x2588ca(%rip), %r8     # 0x318836
movl $0x361, %r9d            # imm = 0x361
xorl %eax, %eax
callq 0x17a50
callq 0x17390