// File: /workspace/github_c_makefile_star2_O1/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 0x1308cd
movq %rdi, %r14
testq %rdi, %rdi
je 0x1308d2
movq 0xb0(%r14), %r12
cmpq %rsi, %r12
jbe 0x1308d7
movl 0xe8(%r14), %r10d
cmpq $0x41, %r10
jae 0x1308dc
movq 0x88(%r14), %r9
movq 0xc0(%r14), %r11
testq %r10, %r10
je 0x13049d
leaq -0x1(%r11), %rcx
imulq %r10, %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
movq (%r9,%rdx,8), %rax
shlq %cl, %rax
andl $0x3f, %ecx
leal (%rcx,%r10), %edi
cmpl $0x41, %edi
jb 0x130493
movq 0x8(%r9,%rdx,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %rax
movl %r10d, %ecx
negb %cl
shrq %cl, %rax
jmp 0x13049f
xorl %eax, %eax
movq %r12, %rcx
subq %rax, %rcx
cmpq %rsi, %rcx
jb 0x1308b1
movl 0xd8(%r14), %r15d
movl 0xec(%r14), %edx
movq %rdx, %rbp
imulq %r15, %rbp
testq %r10, %r10
je 0x1304d5
movq (%r9), %rax
movl %r10d, %ecx
negb %cl
shrq %cl, %rax
jmp 0x1304d7
xorl %eax, %eax
movq %rbp, %rcx
subq %rax, %rcx
cmpq %rsi, %rcx
movq %rsi, 0x8(%rsp)
jae 0x13061f
movq %rdx, 0x10(%rsp)
movq %rsi, %rax
xorl %edx, %edx
divq %rbp
leaq (%rax,%r11), %rdi
shrq %rdi
cmpq %r11, %rax
jae 0x13062f
movl $0x40, %edx
subq %r10, %rdx
movq %rdi, %r8
imulq %r10, %r8
testq %r10, %r10
je 0x130556
movq %r8, %rbx
shrq $0x6, %rbx
movq (%r9,%rbx,8), %r12
movl %r8d, %ecx
shlq %cl, %r12
movl %r8d, %ecx
andl $0x3f, %ecx
leal (%rcx,%r10), %r13d
cmpl $0x41, %r13d
jb 0x13054a
movq 0x8(%r9,%rbx,8), %rbx
negb %cl
shrq %cl, %rbx
orq %rbx, %r12
movq 0x8(%rsp), %rsi
movl %edx, %ecx
shrq %cl, %r12
jmp 0x130559
xorl %r12d, %r12d
leaq 0x1(%rdi), %rbx
imulq %rbp, %rbx
movq %rbx, %rcx
subq %r12, %rcx
cmpq %rsi, %rcx
jae 0x1305a9
testq %r10, %r10
je 0x1305e6
addq %r10, %r8
movq %r8, %r12
shrq $0x6, %r12
movq (%r9,%r12,8), %rax
movl %r8d, %ecx
shlq %cl, %rax
movl %r8d, %ecx
andl $0x3f, %ecx
leal (%rcx,%r10), %r8d
cmpl $0x41, %r8d
jb 0x1305a2
movq 0x8(%r9,%r12,8), %r8
negb %cl
shrq %cl, %r8
orq %r8, %rax
movl %edx, %ecx
shrq %cl, %rax
jmp 0x1305e8
testq %r10, %r10
je 0x1305f8
subq %r10, %r8
movq %r8, %rbx
shrq $0x6, %rbx
movq (%r9,%rbx,8), %r11
movl %r8d, %ecx
shlq %cl, %r11
movl %r8d, %ecx
andl $0x3f, %ecx
leal (%rcx,%r10), %r8d
cmpl $0x41, %r8d
jb 0x1305df
movq 0x8(%r9,%rbx,8), %r8
negb %cl
shrq %cl, %r8
orq %r8, %r11
movl %edx, %ecx
shrq %cl, %r11
jmp 0x1305fb
xorl %eax, %eax
addq %rbp, %rbx
subq %rax, %rbx
movq %rdi, %rax
cmpq %rsi, %rbx
jb 0x13060d
jmp 0x13062f
xorl %r11d, %r11d
movq %rdi, %rcx
imulq %rbp, %rcx
subq %r11, %rcx
cmpq %rsi, %rcx
jb 0x13062c
movq %rdi, %r11
leaq (%r11,%rax), %rdi
shrq %rdi
cmpq %r11, %rax
jb 0x130510
jmp 0x13062f
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r13d, %r13d
jmp 0x1306dd
decq %rdi
movl 0xe4(%r14), %eax
cmpq $0x41, %rax
jae 0x1308eb
leaq 0x1(%rdi), %r12
testq %rax, %rax
je 0x130688
movq 0x80(%r14), %rdx
movq %rdi, %rcx
imulq %rax, %rcx
movq %rcx, %r8
shrq $0x6, %r8
movq (%rdx,%r8,8), %r13
shlq %cl, %r13
andl $0x3f, %ecx
leal (%rcx,%rax), %r11d
cmpl $0x41, %r11d
jb 0x13067f
movq 0x8(%rdx,%r8,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %r13
negb %al
movl %eax, %ecx
shrq %cl, %r13
jmp 0x13068b
xorl %r13d, %r13d
imulq %r12, %rbp
testq %r10, %r10
je 0x1306d3
imulq %r10, %rdi
movq %rdi, %rdx
shrq $0x6, %rdx
movq (%r9,%rdx,8), %rax
movl %edi, %ecx
shlq %cl, %rax
movl %edi, %ecx
andl $0x3f, %ecx
leal (%rcx,%r10), %edi
cmpl $0x41, %edi
jb 0x1306c3
movq 0x8(%r9,%rdx,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %rax
movq 0x10(%rsp), %rdx
negb %r10b
movl %r10d, %ecx
shrq %cl, %rax
jmp 0x1306da
xorl %eax, %eax
movq 0x10(%rsp), %rdx
subq %rax, %rbp
imulq %rdx, %r12
cmpq 0xb8(%r14), %r12
jae 0x13078e
movq 0x78(%r14), %rdx
testq %rdx, %rdx
je 0x1308c3
movl 0xdc(%r14), %eax
cmpq $0x41, %rax
jae 0x1308c8
testq %rax, %rax
je 0x130747
movq %r12, %rcx
imulq %rax, %rcx
movq %rcx, %rsi
shrq $0x6, %rsi
movq (%rdx,%rsi,8), %r15
shlq %cl, %r15
andl $0x3f, %ecx
leal (%rcx,%rax), %edi
cmpl $0x41, %edi
jb 0x13073e
movq 0x8(%rdx,%rsi,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %r15
negb %al
movl %eax, %ecx
shrq %cl, %r15
jmp 0x13074a
xorl %r15d, %r15d
movl 0xd8(%r14), %eax
subl %r15d, %eax
addq %rbp, %rax
cmpq 0x8(%rsp), %rax
jae 0x130791
movq 0x68(%r14), %rdi
movl %r15d, %esi
callq 0x16c234
movl %eax, %eax
addq %rax, %r13
movl 0xd8(%r14), %eax
subl %r15d, %eax
addq %rax, %rbp
incq %r12
cmpq 0xb8(%r14), %r12
jb 0x1306ee
jmp 0x130791
incl %r15d
movl 0xd8(%r14), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r15d
je 0x1308e1
testl %r15d, %r15d
je 0x13080f
movq %rcx, 0x10(%rsp)
movq 0x68(%r14), %rdi
movl %r15d, %esi
callq 0x16c234
cmpl $0x41, %eax
jae 0x1308e6
movq 0x68(%r14), %rdi
xorl %ebx, %ebx
testl %eax, %eax
je 0x13081c
movq 0x70(%r14), %r8
movl %r13d, %esi
movq %r13, %r9
shrq $0x6, %r9
movq (%r8,%r9,8), %rdx
movl %r13d, %ecx
shlq %cl, %rdx
andl $0x3f, %esi
movl %eax, %ecx
addl %esi, %ecx
cmpl $0x41, %ecx
jb 0x130801
movq 0x8(%r8,%r9,8), %r8
negb %sil
movl %esi, %ecx
shrq %cl, %r8
orq %r8, %rdx
movq 0x8(%rsp), %r13
negb %al
movl %eax, %ecx
shrq %cl, %rdx
jmp 0x130823
notq %rbp
addq 0x8(%rsp), %rbp
jmp 0x1308aa
xorl %edx, %edx
movq 0x8(%rsp), %r13
movl %r15d, %esi
callq 0x16c104
movq 0xb8(%r14), %rcx
decq %rcx
xorl %edx, %edx
cmpq %rcx, %r12
sete %dl
movb 0xd8(%r14,%rdx,8), %dl
xorl %ecx, %ecx
subb %dl, %cl
shlq %cl, %rax
notq %rax
subl %ebp, %r13d
movl $0x38, %ecx
leaq 0x2b3d42(%rip), %rdx    # 0x3e45a0
xorl %esi, %esi
movq %rax, %rdi
shrq %cl, %rdi
movzbl %dil, %edi
movzbl (%rdx,%rdi), %r8d
addl %esi, %r8d
cmpl %r13d, %r8d
jae 0x13088d
addq $-0x8, %rcx
addl $-0x8, %ebx
movl %r8d, %esi
cmpl $-0x40, %ebx
jne 0x130860
movl $0x40, %ebp
jmp 0x1308a5
notl %esi
addl %r13d, %esi
shll $0x8, %esi
orq %rsi, %rdi
leaq 0x2b3e01(%rip), %rax    # 0x3e46a0
movzbl (%rax,%rdi), %ebp
subl %ebx, %ebp
movq 0x10(%rsp), %rcx
imulq %rcx, %r12
addq %rbp, %r12
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3d543
callq 0x3d498
callq 0x3d5b5
callq 0x3d57c
callq 0x3d3ed
callq 0x3d426
callq 0x3d50a
callq 0x3d4d1
callq 0x3d45f