// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/compressed_bitsequence.c
// Function: gt_compressed_bitsequence_select_1
GtUword gt_compressed_bitsequence_select_1(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,
          position,
          rank_sum = 0,
          start, start_l, start_r;
  uint64_t block;

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

  /* if larger then max rank1 */
  if (num > (GtUword) gt_compressed_bitsequence_get_variable_field(
                      cbs->superblockranks,
                      (cbs->num_of_superblocks - 1) * cbs->superblockranks_bits,
                      cbs->superblockranks_bits))
    return cbs->num_of_bits;
  if (num <= (GtUword)
      gt_compressed_bitsequence_get_variable_field(cbs->superblockranks, 0,
                                                   cbs->superblockranks_bits)) {
    rank_sum = 0;
    containing_s_block = 0;
    blocks_offset_pos = 0;
  }
  else {
    /* binary search for superblock */
    start_s_block = num / (cbs->blocksize * cbs->superblocksize);
    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) {
      start = middle_s_block * cbs->superblockranks_bits;
      if ((GtUword) gt_compressed_bitsequence_get_variable_field(
                                                    cbs->superblockranks, start,
                                                    cbs->superblockranks_bits)
          < num) {
        start_r = start + cbs->superblockranks_bits;
        if ((GtUword) gt_compressed_bitsequence_get_variable_field(
                                                  cbs->superblockranks, start_r,
                                                  cbs->superblockranks_bits)
            < num)
          start_s_block = middle_s_block;
        else
          break;
      }
      else {
        start_l = start - cbs->superblockranks_bits;
        if ((GtUword) 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);
    }
    blocks_offset_pos = (GtUword)
      gt_compressed_bitsequence_get_variable_field(
                                   cbs->superblockoffsets,
                                   middle_s_block * cbs->superblockoffsets_bits,
                                   cbs->superblockoffsets_bits);
    rank_sum = (GtUword) 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 + class)
      break;
    blocks_offset_pos += gt_popcount_tab_offset_bits(cbs->popcount_tab, class);
    rank_sum += class;
  }
  gt_assert(class != cbs->blocksize + 1);
  position = block_idx * cbs->blocksize;
  if (class == cbs->blocksize) {
    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);

    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 0x12a4ae
movq %rsi, %rbx
movq %rdi, %r15
movq 0xb0(%rdi), %r14
cmpq %rsi, %r14
jbe 0x12a4b3
movl 0xe8(%r15), %edi
cmpq $0x41, %rdi
jae 0x12a4b8
testq %rdi, %rdi
je 0x12a492
movq 0x88(%r15), %r8
movq 0xc0(%r15), %r10
leaq -0x1(%r10), %rcx
imulq %rdi, %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
movq (%r8,%rdx,8), %rax
shlq %cl, %rax
andl $0x3f, %ecx
leal (%rcx,%rdi), %esi
cmpl $0x41, %esi
jb 0x12a11a
movq 0x8(%r8,%rdx,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %rax
movq %rdi, %rcx
negq %rcx
shrq %cl, %rax
cmpq %rbx, %rax
jb 0x12a492
movl $0x40, %esi
subq %rdi, %rsi
movq (%r8), %rax
movl %esi, %ecx
shrq %cl, %rax
movl 0xec(%r15), %r9d
cmpq %rbx, %rax
jae 0x12a231
movl 0xd8(%r15), %ecx
imull %r9d, %ecx
movq %rbx, %rax
xorl %edx, %edx
divq %rcx
leaq (%rax,%r10), %r14
shrq %r14
cmpq %r10, %rax
jae 0x12a241
movq %rbx, %r12
movq %r14, %rdx
imulq %rdi, %rdx
movq %rdx, %rbx
shrq $0x6, %rbx
movq (%r8,%rbx,8), %r11
movl %edx, %ecx
shlq %cl, %r11
movl %edx, %ecx
andl $0x3f, %ecx
leal (%rcx,%rdi), %ebp
cmpl $0x41, %ebp
jb 0x12a1a3
movq 0x8(%r8,%rbx,8), %rbx
negb %cl
shrq %cl, %rbx
orq %rbx, %r11
movl %esi, %ecx
shrq %cl, %r11
movq %r12, %rbx
cmpq %r12, %r11
jae 0x12a1e9
addq %rdi, %rdx
movq %rdx, %r11
shrq $0x6, %r11
movq (%r8,%r11,8), %rax
movl %edx, %ecx
shlq %cl, %rax
movl %edx, %ecx
andl $0x3f, %ecx
leal (%rcx,%rdi), %edx
cmpl $0x41, %edx
jb 0x12a1dd
movq 0x8(%r8,%r11,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %rax
movl %esi, %ecx
shrq %cl, %rax
cmpq %rbx, %rax
jb 0x12a226
jmp 0x12a241
subq %rdi, %rdx
movq %rdx, %r11
shrq $0x6, %r11
movq (%r8,%r11,8), %r10
movl %edx, %ecx
shlq %cl, %r10
movl %edx, %ecx
andl $0x3f, %ecx
leal (%rcx,%rdi), %edx
cmpl $0x41, %edx
jb 0x12a216
movq 0x8(%r8,%r11,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %r10
movl %esi, %ecx
shrq %cl, %r10
cmpq %rbx, %r10
jb 0x12a23e
movq %r14, %r10
movq %rax, %r14
movq %r14, %rax
addq %r10, %r14
jmp 0x12a163
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %edx, %edx
jmp 0x12a2cd
decq %r14
movl 0xe4(%r15), %eax
cmpq $0x41, %rax
jae 0x12a4c2
testq %rax, %rax
je 0x12a296
movq 0x80(%r15), %rdx
movq %r14, %rcx
imulq %rax, %rcx
movq %rcx, %r10
shrq $0x6, %r10
movq (%rdx,%r10,8), %r12
shlq %cl, %r12
andl $0x3f, %ecx
leal (%rcx,%rax), %r11d
cmpl $0x41, %r11d
jb 0x12a28d
movq 0x8(%rdx,%r10,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %r12
negb %al
movl %eax, %ecx
shrq %cl, %r12
jmp 0x12a299
xorl %r12d, %r12d
movq %rdi, %rcx
imulq %r14, %rcx
movq %rcx, %rax
shrq $0x6, %rax
movq (%r8,%rax,8), %rdx
shlq %cl, %rdx
andl $0x3f, %ecx
addl %ecx, %edi
cmpl $0x41, %edi
jb 0x12a2c5
movq 0x8(%r8,%rax,8), %rax
negb %cl
shrq %cl, %rax
orq %rax, %rdx
movl %esi, %ecx
shrq %cl, %rdx
incq %r14
imulq %r9, %r14
cmpq 0xb8(%r15), %r14
jae 0x12a4bd
movq 0x78(%r15), %rsi
testq %rsi, %rsi
je 0x12a4a4
movl 0xdc(%r15), %eax
cmpq $0x41, %rax
jae 0x12a4a9
testq %rax, %rax
je 0x12a339
movq %r14, %rcx
imulq %rax, %rcx
movq %rcx, %rdi
shrq $0x6, %rdi
movq (%rsi,%rdi,8), %r13
shlq %cl, %r13
andl $0x3f, %ecx
leal (%rcx,%rax), %r8d
cmpl $0x41, %r8d
jb 0x12a330
movq 0x8(%rsi,%rdi,8), %rsi
negb %cl
shrq %cl, %rsi
orq %rsi, %r13
negb %al
movl %eax, %ecx
shrq %cl, %r13
jmp 0x12a33c
xorl %r13d, %r13d
movl %r13d, %ebp
addq %rdx, %rbp
cmpq %rbx, %rbp
jae 0x12a36d
movq 0x68(%r15), %rdi
movl %r13d, %esi
callq 0x1643ab
movl %eax, %eax
addq %rax, %r12
incq %r14
movq %rbp, %rdx
cmpq 0xb8(%r15), %r14
jb 0x12a2de
jmp 0x12a370
movq %rdx, %rbp
movl 0xd8(%r15), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r13d
je 0x12a4bd
cmpl %ecx, %r13d
jne 0x12a393
notq %rbp
addq %rbx, %rbp
jmp 0x12a48b
movq %rcx, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movq 0x68(%r15), %rdi
movl %r13d, %esi
callq 0x1643ab
cmpl $0x41, %eax
jae 0x12a4c7
movq 0x68(%r15), %rdi
xorl %ebx, %ebx
testl %eax, %eax
je 0x12a3f9
movq 0x70(%r15), %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 0x12a3f0
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 0x12a3fb
xorl %edx, %edx
movl %r13d, %esi
callq 0x164278
movq 0xb8(%r15), %rcx
decq %rcx
xorl %edx, %edx
cmpq %rcx, %r14
sete %dl
movb 0xd8(%r15,%rdx,8), %dl
xorl %ecx, %ecx
subb %dl, %cl
shlq %cl, %rax
movq 0x8(%rsp), %rcx
subl %ebp, %ecx
movq %rcx, 0x8(%rsp)
movl $0x38, %ecx
leaq 0x2b0a64(%rip), %rdx    # 0x3daea0
xorl %esi, %esi
movq %rax, %rdi
shrq %cl, %rdi
movzbl %dil, %edi
movzbl (%rdx,%rdi), %r8d
addl %esi, %r8d
cmpl 0x8(%rsp), %r8d
jae 0x12a46d
addq $-0x8, %rcx
addl $-0x8, %ebx
movl %r8d, %esi
cmpl $-0x40, %ebx
jne 0x12a43e
movl $0x40, %ebp
jmp 0x12a486
notl %esi
addl 0x8(%rsp), %esi
shll $0x8, %esi
orq %rsi, %rdi
leaq 0x2b0b20(%rip), %rax    # 0x3dafa0
movzbl (%rax,%rdi), %ebp
subl %ebx, %ebp
movq 0x10(%rsp), %rcx
imulq %rcx, %r14
addq %rbp, %r14
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3c8c4
callq 0x3c819
callq 0x3c8fd
callq 0x3c76e
callq 0x3c7a7
callq 0x3c88b
callq 0x3c7e0
callq 0x3c852