// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movq %rsi, 0x90(%rsp)
movq 0x98(%rsp), %rax
movl 0xd8(%rax), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
movq $0x0, 0x48(%rsp)
cmpq $0x0, 0x90(%rsp)
jne 0x13b50b
movq 0x500ac6(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3dab2f(%rip), %rsi    # 0x516013
leaq 0x40f410(%rip), %rdx    # 0x54a8fb
leaq 0x40f412(%rip), %rcx    # 0x54a904
leaq 0x40f30d(%rip), %r8     # 0x54a806
movl $0x293, %r9d            # imm = 0x293
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x13b50d
jmp 0x13b50f
cmpq $0x0, 0x98(%rsp)
jne 0x13b552
movq 0x500a7f(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3daae8(%rip), %rsi    # 0x516013
leaq 0x40f33e(%rip), %rdx    # 0x54a870
leaq 0x40f3cb(%rip), %rcx    # 0x54a904
leaq 0x40f2c6(%rip), %r8     # 0x54a806
movl $0x294, %r9d            # imm = 0x294
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x13b554
jmp 0x13b556
movq 0x90(%rsp), %rax
movq 0x98(%rsp), %rcx
cmpq 0xb0(%rcx), %rax
jb 0x13b5a7
movq 0x500a2a(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3daa93(%rip), %rsi    # 0x516013
leaq 0x40f3a0(%rip), %rdx    # 0x54a927
leaq 0x40f376(%rip), %rcx    # 0x54a904
leaq 0x40f271(%rip), %r8     # 0x54a806
movl $0x295, %r9d            # imm = 0x295
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x13b5a9
movq 0x90(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x98(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x98(%rsp), %rax
movq 0xc0(%rax), %rsi
subq $0x1, %rsi
movq 0x98(%rsp), %rax
movl 0xe8(%rax), %eax
imulq %rax, %rsi
movq 0x98(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jbe 0x13b626
movq 0x98(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0xa0(%rsp)
jmp 0x13bb1e
movq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x98(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x98(%rsp), %rax
movl 0xe8(%rax), %edx
xorl %eax, %eax
movl %eax, %esi
callq 0x13bb30
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
ja 0x13b686
movq $0x0, 0x48(%rsp)
movq $0x0, 0x70(%rsp)
movq $0x0, 0x78(%rsp)
jmp 0x13b8a4
movq 0x90(%rsp), %rax
movq 0x98(%rsp), %rcx
movl 0xd8(%rcx), %ecx
movq 0x98(%rsp), %rdx
imull 0xec(%rdx), %ecx
movl %ecx, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, 0x58(%rsp)
movq 0x98(%rsp), %rax
movq 0xc0(%rax), %rax
movq %rax, 0x68(%rsp)
movq 0x58(%rsp), %rax
addq 0x68(%rsp), %rax
shrq %rax
movq %rax, 0x60(%rsp)
movq 0x58(%rsp), %rax
cmpq 0x68(%rsp), %rax
jae 0x13b81a
movq 0x60(%rsp), %rax
movq 0x98(%rsp), %rcx
movl 0xe8(%rcx), %ecx
imulq %rcx, %rax
movq %rax, 0x40(%rsp)
movq 0x98(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x40(%rsp), %rsi
movq 0x98(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
cmpq 0x90(%rsp), %rax
jae 0x13b799
movq 0x40(%rsp), %rax
movq 0x98(%rsp), %rcx
movl 0xe8(%rcx), %ecx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0x98(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x30(%rsp), %rsi
movq 0x98(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
cmpq 0x90(%rsp), %rax
jae 0x13b792
movq 0x60(%rsp), %rax
movq %rax, 0x58(%rsp)
jmp 0x13b797
jmp 0x13b81a
jmp 0x13b803
movq 0x40(%rsp), %rax
movq 0x98(%rsp), %rcx
movl 0xe8(%rcx), %ecx
subq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x98(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x38(%rsp), %rsi
movq 0x98(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
cmpq 0x90(%rsp), %rax
jb 0x13b7f1
movq 0x60(%rsp), %rax
movq %rax, 0x68(%rsp)
jmp 0x13b801
movq 0x60(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x13b81a
jmp 0x13b803
movq 0x58(%rsp), %rax
addq 0x68(%rsp), %rax
shrq %rax
movq %rax, 0x60(%rsp)
jmp 0x13b6dd
movq 0x98(%rsp), %rax
movq 0x80(%rax), %rdi
movq 0x60(%rsp), %rsi
movq 0x98(%rsp), %rax
movl 0xe4(%rax), %eax
imulq %rax, %rsi
movq 0x98(%rsp), %rax
movl 0xe4(%rax), %edx
callq 0x13bb30
movq %rax, 0x78(%rsp)
movq 0x98(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x60(%rsp), %rsi
movq 0x98(%rsp), %rax
movl 0xe8(%rax), %eax
imulq %rax, %rsi
movq 0x98(%rsp), %rax
movl 0xe8(%rax), %edx
callq 0x13bb30
movq %rax, 0x48(%rsp)
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq 0x98(%rsp), %rcx
movl 0xec(%rcx), %ecx
imulq %rcx, %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
movq 0x98(%rsp), %rcx
cmpq 0xb8(%rcx), %rax
jae 0x13b968
movq 0x98(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x13bc30
movl %eax, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq 0x48(%rsp), %rcx
movl 0x88(%rsp), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
ja 0x13b91a
jmp 0x13b968
movq 0x98(%rsp), %rax
movq 0x68(%rax), %rdi
movl 0x88(%rsp), %esi
callq 0x1b4bc0
movl %eax, %eax
addq 0x78(%rsp), %rax
movq %rax, 0x78(%rsp)
movl 0x88(%rsp), %eax
addq 0x48(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x80(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x80(%rsp)
jmp 0x13b8c3
jmp 0x13b96a
movl 0x88(%rsp), %eax
movq 0x98(%rsp), %rcx
movl 0xd8(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x13b9be
movq 0x500613(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3da67c(%rip), %rsi    # 0x516013
leaq 0x40efa0(%rip), %rdx    # 0x54a93e
leaq 0x40ef5f(%rip), %rcx    # 0x54a904
leaq 0x40ee5a(%rip), %r8     # 0x54a806
movl $0x2dc, %r9d            # imm = 0x2DC
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x13b9c0
movq 0x80(%rsp), %rax
movq 0x98(%rsp), %rcx
movl 0xd8(%rcx), %ecx
imulq %rcx, %rax
movq %rax, 0x50(%rsp)
movl 0x88(%rsp), %eax
movq 0x98(%rsp), %rcx
cmpl 0xd8(%rcx), %eax
jne 0x13ba16
movq 0x90(%rsp), %rax
subq 0x48(%rsp), %rax
subq $0x1, %rax
addq 0x50(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0x13bb11
movq 0x98(%rsp), %rax
movq 0x68(%rax), %rdi
movl 0x88(%rsp), %esi
callq 0x1b4bc0
movl %eax, 0x8c(%rsp)
movq 0x98(%rsp), %rax
movq 0x68(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x98(%rsp), %rax
movq 0x70(%rax), %rdi
movq 0x78(%rsp), %rsi
movl 0x8c(%rsp), %edx
callq 0x13bb30
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
movq %rax, %rdx
callq 0x1b4820
movq %rax, 0x28(%rsp)
movq 0x80(%rsp), %rax
movq 0x98(%rsp), %rcx
movq 0xb8(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x13bac9
movq 0x98(%rsp), %rax
movl 0xd8(%rax), %eax
movl $0x40, %ecx
subq %rax, %rcx
movq 0x28(%rsp), %rax
shlq %cl, %rax
movq %rax, 0x28(%rsp)
jmp 0x13baec
movq 0x98(%rsp), %rax
movl 0xe0(%rax), %eax
movl $0x40, %ecx
subq %rax, %rcx
movq 0x28(%rsp), %rax
shlq %cl, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0x90(%rsp), %rax
subq 0x48(%rsp), %rax
movl %eax, %esi
callq 0x13bd00
movl %eax, %eax
addq 0x50(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
addq $0xa8, %rsp
retq
nop