// File: /workspace/github_c_makefile_star2_O1/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 0x130380
movq %rdi, %r14
testq %rdi, %rdi
je 0x130385
movq 0xb0(%r14), %r12
cmpq %rsi, %r12
jbe 0x13038a
movl 0xe8(%r14), %r8d
cmpq $0x41, %r8
jae 0x13038f
movq 0x88(%r14), %r13
movq 0xc0(%r14), %r10
testq %r8, %r8
je 0x12ff9d
leaq -0x1(%r10), %rcx
imulq %r8, %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
movq (%r13,%rdx,8), %rax
shlq %cl, %rax
andl $0x3f, %ecx
leal (%rcx,%r8), %edi
cmpl $0x41, %edi
jb 0x12ff93
movq 0x8(%r13,%rdx,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %rax
movl %r8d, %ecx
negb %cl
shrq %cl, %rax
jmp 0x12ff9f
xorl %eax, %eax
cmpq %rsi, %rax
jb 0x130364
testq %r8, %r8
je 0x12ffbb
movq (%r13), %rax
movl %r8d, %ecx
negb %cl
shrq %cl, %rax
jmp 0x12ffbd
xorl %eax, %eax
movl 0xd8(%r14), %r15d
cmpq %rsi, %rax
movq %rsi, 0x8(%rsp)
jae 0x1300e5
movl 0xec(%r14), %ecx
imull %r15d, %ecx
movq %rsi, %rax
xorl %edx, %edx
divq %rcx
leaq (%rax,%r10), %r9
shrq %r9
cmpq %r10, %rax
jae 0x1300f5
movl $0x40, %edx
subq %r8, %rdx
movq %r9, %rdi
imulq %r8, %rdi
testq %r8, %r8
je 0x13003c
movq %rdi, %rbx
shrq $0x6, %rbx
movq (%r13,%rbx,8), %r11
movl %edi, %ecx
shlq %cl, %r11
movl %edi, %ecx
andl $0x3f, %ecx
leal (%rcx,%r8), %ebp
cmpl $0x41, %ebp
jb 0x130035
movq 0x8(%r13,%rbx,8), %rbx
negb %cl
shrq %cl, %rbx
orq %rbx, %r11
movl %edx, %ecx
shrq %cl, %r11
jmp 0x13003f
xorl %r11d, %r11d
cmpq %rsi, %r11
jae 0x13007f
testq %r8, %r8
je 0x1300ba
addq %r8, %rdi
movq %rdi, %r11
shrq $0x6, %r11
movq (%r13,%r11,8), %rax
movl %edi, %ecx
shlq %cl, %rax
movl %edi, %ecx
andl $0x3f, %ecx
leal (%rcx,%r8), %edi
cmpl $0x41, %edi
jb 0x130078
movq 0x8(%r13,%r11,8), %rdi
negb %cl
shrq %cl, %rdi
orq %rdi, %rax
movl %edx, %ecx
shrq %cl, %rax
jmp 0x1300bc
testq %r8, %r8
je 0x1300c3
subq %r8, %rdi
movq %rdi, %r11
shrq $0x6, %r11
movq (%r13,%r11,8), %r10
movl %edi, %ecx
shlq %cl, %r10
movl %edi, %ecx
andl $0x3f, %ecx
leal (%rcx,%r8), %edi
cmpl $0x41, %edi
jb 0x1300b3
movq 0x8(%r13,%r11,8), %rdi
negb %cl
shrq %cl, %rdi
orq %rdi, %r10
movl %edx, %ecx
shrq %cl, %r10
jmp 0x1300c6
xorl %eax, %eax
cmpq %rsi, %rax
jb 0x1300d1
jmp 0x1300f5
xorl %r10d, %r10d
cmpq %rsi, %r10
jb 0x1300f2
movq %r9, %r10
movq %rax, %r9
movq %r9, %rax
addq %r10, %r9
shrq %r9
cmpq %r10, %rax
jb 0x12fffd
jmp 0x1300f5
xorl %r13d, %r13d
xorl %r9d, %r9d
xorl %ebp, %ebp
jmp 0x130193
decq %r9
movl 0xe4(%r14), %eax
cmpq $0x41, %rax
jae 0x130399
movq %r13, %r11
testq %rax, %rax
je 0x13014d
movq 0x80(%r14), %rdx
movq %r9, %rcx
imulq %rax, %rcx
movq %rcx, %rdi
shrq $0x6, %rdi
movq (%rdx,%rdi,8), %r13
shlq %cl, %r13
andl $0x3f, %ecx
leal (%rcx,%rax), %r10d
cmpl $0x41, %r10d
jb 0x130144
movq 0x8(%rdx,%rdi,8), %rdx
negb %cl
shrq %cl, %rdx
orq %rdx, %r13
negb %al
movl %eax, %ecx
shrq %cl, %r13
jmp 0x130150
xorl %r13d, %r13d
testq %r8, %r8
je 0x13018e
movq %r9, %rcx
imulq %r8, %rcx
movq %rcx, %rax
shrq $0x6, %rax
movq (%r11,%rax,8), %rbp
shlq %cl, %rbp
andl $0x3f, %ecx
leal (%rcx,%r8), %edx
cmpl $0x41, %edx
jb 0x130183
movq 0x8(%r11,%rax,8), %rax
negb %cl
shrq %cl, %rax
orq %rax, %rbp
negb %r8b
movl %r8d, %ecx
shrq %cl, %rbp
jmp 0x130190
xorl %ebp, %ebp
incq %r9
movl 0xec(%r14), %r12d
imulq %r9, %r12
cmpq 0xb8(%r14), %r12
jae 0x13023f
movq %rbp, %rdx
movq 0x78(%r14), %rsi
testq %rsi, %rsi
je 0x130376
movl 0xdc(%r14), %eax
cmpq $0x41, %rax
jae 0x13037b
testq %rax, %rax
je 0x130209
movq %r12, %rcx
imulq %rax, %rcx
movq %rcx, %rdi
shrq $0x6, %rdi
movq (%rsi,%rdi,8), %r15
shlq %cl, %r15
andl $0x3f, %ecx
leal (%rcx,%rax), %r8d
cmpl $0x41, %r8d
jb 0x130200
movq 0x8(%rsi,%rdi,8), %rsi
negb %cl
shrq %cl, %rsi
orq %rsi, %r15
negb %al
movl %eax, %ecx
shrq %cl, %r15
jmp 0x13020c
xorl %r15d, %r15d
movl %r15d, %ebp
addq %rdx, %rbp
cmpq 0x8(%rsp), %rbp
jae 0x130244
movq 0x68(%r14), %rdi
movl %r15d, %esi
callq 0x16c234
movl %eax, %eax
addq %rax, %r13
incq %r12
movq %rbp, %rdx
cmpq 0xb8(%r14), %r12
jb 0x1301ae
jmp 0x130247
incl %r15d
jmp 0x130247
movq %rdx, %rbp
movl 0xd8(%r14), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r15d
je 0x130394
cmpl %ecx, %r15d
jne 0x13026c
notq %rbp
addq 0x8(%rsp), %rbp
jmp 0x13035d
movq %rcx, 0x10(%rsp)
movq 0x68(%r14), %rdi
movl %r15d, %esi
callq 0x16c234
cmpl $0x41, %eax
jae 0x13039e
movq 0x68(%r14), %rdi
xorl %ebx, %ebx
testl %eax, %eax
je 0x1302d2
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 0x1302c4
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 0x1302d9
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
subl %ebp, %r13d
movl $0x38, %ecx
leaq 0x2b428f(%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 0x130340
addq $-0x8, %rcx
addl $-0x8, %ebx
movl %r8d, %esi
cmpl $-0x40, %ebx
jne 0x130313
movl $0x40, %ebp
jmp 0x130358
notl %esi
addl %r13d, %esi
shll $0x8, %esi
orq %rsi, %rdi
leaq 0x2b434e(%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 0x3d297
callq 0x3d1ec
callq 0x3d309
callq 0x3d2d0
callq 0x3d141
callq 0x3d17a
callq 0x3d25e
callq 0x3d1b3
callq 0x3d225