// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xf8, %rsp
movq %rdi, 0xe8(%rsp)
movq %rsi, 0xe0(%rsp)
movq 0xe8(%rsp), %rax
movl 0xd8(%rax), %eax
addl $0x1, %eax
movl %eax, 0xd8(%rsp)
movq $0x0, 0x88(%rsp)
cmpq $0x0, 0xe0(%rsp)
jne 0x13be6e
movq 0x500163(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3da1cc(%rip), %rsi    # 0x516013
leaq 0x40eaad(%rip), %rdx    # 0x54a8fb
leaq 0x40eb05(%rip), %rcx    # 0x54a95a
leaq 0x40e9aa(%rip), %r8     # 0x54a806
movl $0x308, %r9d            # imm = 0x308
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x13be70
jmp 0x13be72
cmpq $0x0, 0xe8(%rsp)
jne 0x13beb5
movq 0x50011c(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3da185(%rip), %rsi    # 0x516013
leaq 0x40e9db(%rip), %rdx    # 0x54a870
leaq 0x40eabe(%rip), %rcx    # 0x54a95a
leaq 0x40e963(%rip), %r8     # 0x54a806
movl $0x309, %r9d            # imm = 0x309
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x13beb7
jmp 0x13beb9
movq 0xe0(%rsp), %rax
movq 0xe8(%rsp), %rcx
cmpq 0xb0(%rcx), %rax
jb 0x13bf0a
movq 0x5000c7(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3da130(%rip), %rsi    # 0x516013
leaq 0x40ea3d(%rip), %rdx    # 0x54a927
leaq 0x40ea69(%rip), %rcx    # 0x54a95a
leaq 0x40e90e(%rip), %r8     # 0x54a806
movl $0x30a, %r9d            # imm = 0x30A
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x13bf0c
movq 0xe8(%rsp), %rax
movl 0xd8(%rax), %eax
movq 0xe8(%rsp), %rcx
movl 0xec(%rcx), %ecx
imulq %rcx, %rax
movq %rax, 0x80(%rsp)
movq 0xe8(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0xe8(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0xe8(%rsp), %rax
movq 0xc0(%rax), %rsi
subq $0x1, %rsi
movq 0xe8(%rsp), %rax
movl 0xe8(%rax), %eax
imulq %rax, %rsi
movq 0xe8(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
movq %rax, %rcx
movq 0x40(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x98(%rsp)
movq 0xe0(%rsp), %rax
cmpq 0x98(%rsp), %rax
jbe 0x13bfd0
movq 0xe8(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0xf0(%rsp)
jmp 0x13c611
movq 0x80(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xe8(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0xe8(%rsp), %rax
movl 0xe8(%rax), %edx
xorl %eax, %eax
movl %eax, %esi
callq 0x13bb30
movq %rax, %rcx
movq 0x38(%rsp), %rax
subq %rcx, %rax
movq %rax, 0xa0(%rsp)
movq 0xe0(%rsp), %rax
cmpq 0xa0(%rsp), %rax
ja 0x13c051
movq $0x0, 0x88(%rsp)
movq $0x0, 0xc0(%rsp)
movq $0x0, 0xc8(%rsp)
jmp 0x13c355
movq 0xe0(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x80(%rsp)
movq %rax, 0xa8(%rsp)
movq 0xe8(%rsp), %rax
movq 0xc0(%rax), %rax
movq %rax, 0xb8(%rsp)
movq 0xa8(%rsp), %rax
addq 0xb8(%rsp), %rax
shrq %rax
movq %rax, 0xb0(%rsp)
movq 0xa8(%rsp), %rax
cmpq 0xb8(%rsp), %rax
jae 0x13c287
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
addq $0x1, %rcx
imulq %rcx, %rax
movq %rax, 0x58(%rsp)
movq 0xb0(%rsp), %rax
movq 0xe8(%rsp), %rcx
movl 0xe8(%rcx), %ecx
imulq %rcx, %rax
movq %rax, 0x78(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xe8(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x78(%rsp), %rsi
movq 0xe8(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
movq %rax, %rcx
movq 0x30(%rsp), %rax
subq %rcx, %rax
cmpq 0xe0(%rsp), %rax
jae 0x13c1ca
movq 0x58(%rsp), %rax
addq 0x80(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x78(%rsp), %rax
movq 0xe8(%rsp), %rcx
movl 0xe8(%rcx), %ecx
addq %rcx, %rax
movq %rax, 0x68(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xe8(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x68(%rsp), %rsi
movq 0xe8(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
movq %rax, %rcx
movq 0x28(%rsp), %rax
subq %rcx, %rax
cmpq 0xe0(%rsp), %rax
jae 0x13c1c0
movq 0xb0(%rsp), %rax
movq %rax, 0xa8(%rsp)
jmp 0x13c1c5
jmp 0x13c287
jmp 0x13c267
movq 0x58(%rsp), %rax
subq 0x80(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x78(%rsp), %rax
movq 0xe8(%rsp), %rcx
movl 0xe8(%rcx), %ecx
subq %rcx, %rax
movq %rax, 0x70(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xe8(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x70(%rsp), %rsi
movq 0xe8(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
movq %rax, %rcx
movq 0x20(%rsp), %rax
subq %rcx, %rax
cmpq 0xe0(%rsp), %rax
jb 0x13c24f
movq 0xb0(%rsp), %rax
movq %rax, 0xb8(%rsp)
jmp 0x13c265
movq 0xb0(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0x13c287
jmp 0x13c267
movq 0xa8(%rsp), %rax
addq 0xb8(%rsp), %rax
shrq %rax
movq %rax, 0xb0(%rsp)
jmp 0x13c09f
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
addq $0x1, %rcx
imulq %rcx, %rax
movq %rax, 0x58(%rsp)
movq 0xe8(%rsp), %rax
movq 0x80(%rax), %rdi
movq 0xb0(%rsp), %rsi
movq 0xe8(%rsp), %rax
movl 0xe4(%rax), %eax
imulq %rax, %rsi
movq 0xe8(%rsp), %rax
movl 0xe4(%rax), %edx
callq 0x13bb30
movq %rax, 0xc8(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xe8(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0xb0(%rsp), %rsi
movq 0xe8(%rsp), %rax
movl 0xe8(%rax), %eax
imulq %rax, %rsi
movq 0xe8(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
movq %rax, %rcx
movq 0x18(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x88(%rsp)
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq 0xe8(%rsp), %rcx
movl 0xec(%rcx), %ecx
imulq %rcx, %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
movq 0xe8(%rsp), %rcx
cmpq 0xb8(%rcx), %rax
jae 0x13c44b
movq 0xe8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x13bc30
movl %eax, 0xd8(%rsp)
movq 0xe0(%rsp), %rax
movq 0x88(%rsp), %rcx
movq 0xe8(%rsp), %rdx
movl 0xd8(%rdx), %edx
subl 0xd8(%rsp), %edx
movl %edx, %edx
addq %rdx, %rcx
cmpq %rcx, %rax
ja 0x13c3e1
jmp 0x13c44b
movq 0xe8(%rsp), %rax
movq 0x68(%rax), %rdi
movl 0xd8(%rsp), %esi
callq 0x1b4bc0
movl %eax, %eax
addq 0xc8(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0xe8(%rsp), %rax
movl 0xd8(%rax), %eax
subl 0xd8(%rsp), %eax
movl %eax, %eax
addq 0x88(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0xd0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xd0(%rsp)
jmp 0x13c377
movq 0xd0(%rsp), %rax
movq 0xe8(%rsp), %rcx
movl 0xd8(%rcx), %ecx
imulq %rcx, %rax
movq %rax, 0x90(%rsp)
movl 0xd8(%rsp), %eax
movq 0xe8(%rsp), %rcx
movl 0xd8(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x13c4c1
movq 0x4ffb10(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3d9b79(%rip), %rsi    # 0x516013
leaq 0x40e49d(%rip), %rdx    # 0x54a93e
leaq 0x40e4b2(%rip), %rcx    # 0x54a95a
leaq 0x40e357(%rip), %r8     # 0x54a806
movl $0x361, %r9d            # imm = 0x361
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x13c4c3
cmpl $0x0, 0xd8(%rsp)
jne 0x13c4f6
movq 0xe0(%rsp), %rax
subq 0x88(%rsp), %rax
subq $0x1, %rax
addq 0x90(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0x13c601
movq 0xe8(%rsp), %rax
movq 0x68(%rax), %rdi
movl 0xd8(%rsp), %esi
callq 0x1b4bc0
movl %eax, 0xdc(%rsp)
movq 0xe8(%rsp), %rax
movq 0x68(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0xd8(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0xe8(%rsp), %rax
movq 0x70(%rax), %rdi
movq 0xc8(%rsp), %rsi
movl 0xdc(%rsp), %edx
callq 0x13bb30
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
movq %rax, %rdx
callq 0x1b4820
movq %rax, 0x60(%rsp)
movq 0xd0(%rsp), %rax
movq 0xe8(%rsp), %rcx
movq 0xb8(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x13c5ac
movq 0xe8(%rsp), %rax
movl 0xd8(%rax), %eax
movl $0x40, %ecx
subq %rax, %rcx
movq 0x60(%rsp), %rax
shlq %cl, %rax
movq %rax, 0x60(%rsp)
jmp 0x13c5cf
movq 0xe8(%rsp), %rax
movl 0xe0(%rax), %eax
movl $0x40, %ecx
subq %rax, %rcx
movq 0x60(%rsp), %rax
shlq %cl, %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
xorq $-0x1, %rdi
movq 0xe0(%rsp), %rax
subq 0x88(%rsp), %rax
movl %eax, %esi
callq 0x13bd00
movl %eax, %eax
addq 0x90(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rax
addq $0xf8, %rsp
retq
nopw %cs:(%rax,%rax)