// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/wtree_encseq.c
// Function: gt_wtree_encseq_select_rec
static GtUword gt_wtree_encseq_select_rec(GtWtreeEncseq *we,
                                          GtUword i,
                                          GtWtreeSymbol sym,
                                          GtUword node_start,
                                          GtUword node_size,
                                          unsigned int alpha_start,
                                          unsigned int alpha_end)
{
  unsigned int middle = GT_DIV2(alpha_start + alpha_end);
  int bit;
  GtUword zero_rank_prefix = 0,
          one_rank_prefix = 0,
          left_child_size, child_start;

  if (alpha_start < alpha_end) {
    bit = middle < (unsigned int) sym ? 1 : 0;
    if (node_start != 0)
      zero_rank_prefix =
        gt_compressed_bitsequence_rank_0(we->c_bits, node_start - 1);
    left_child_size =
      gt_compressed_bitsequence_rank_0(we->c_bits, node_start + node_size - 1) -
      zero_rank_prefix;

    if (bit == 0) {
      alpha_end = middle;
      child_start = node_start + we->parent_instance.members->length;
      node_size = left_child_size;
    }
    else {
      if (node_start != 0)
        one_rank_prefix =
          gt_compressed_bitsequence_rank_1(we->c_bits, node_start - 1);
      alpha_start = middle + 1;
      node_size =
        gt_compressed_bitsequence_rank_1(we->c_bits,
                                         node_start + node_size - 1) -
        one_rank_prefix;
      child_start =
        node_start + we->parent_instance.members->length + left_child_size;
    }
    if (node_size != 0) {
      i = gt_wtree_encseq_select_rec(we, i, sym, child_start, node_size,
                                     alpha_start, alpha_end);
      if (i < node_size) {
        return (bit == 0 ?
                gt_compressed_bitsequence_select_0(we->c_bits,
                                                   zero_rank_prefix + i + 1) :
                gt_compressed_bitsequence_select_1(we->c_bits,
                                                   one_rank_prefix + i + 1)) -
          node_start;
      }
    }
    return ULONG_MAX;
  }
  if (i <= node_size)
    return i - 1;
  return ULONG_MAX;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r13
movl 0x70(%rsp), %r12d
cmpl %r12d, %r9d
jae 0x184ed7
movl %r9d, %ebp
movq %rdi, %r14
movq %rsi, 0x30(%rsp)
movq %rdx, 0x20(%rsp)
leal (%r12,%rbp), %eax
shrl %eax
movq %rax, 0x18(%rsp)
testq %rcx, %rcx
movq %rcx, 0x8(%rsp)
je 0x184eee
movq 0x38(%r14), %rdi
leaq -0x1(%rcx), %rbx
movq %rbx, %rsi
callq 0x12a011
movq %rax, %r15
jmp 0x184ef8
leaq -0x1(%rsi), %rax
cmpq %r13, %rsi
movq $-0x1, %r13
cmovbeq %rax, %r13
jmp 0x184ff8
movq $-0x1, %rbx
xorl %r15d, %r15d
movq 0x38(%r14), %rdi
addq %rbx, %r13
movq %r13, %rsi
callq 0x12a011
movq %r14, %rcx
movq %rax, %r14
subq %r15, %r14
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rsi
cmpl %edx, %esi
movq %rcx, 0x10(%rsp)
movq %r15, 0x28(%rsp)
jae 0x184f4b
cmpq $0x0, 0x8(%rsp)
je 0x184f61
movq 0x10(%rsp), %r15
movq 0x38(%r15), %rdi
movq %rbx, %rsi
callq 0x129f92
movq 0x18(%rsp), %rsi
movq %rax, %rbx
jmp 0x184f68
movq 0x8(%rcx), %rax
movq (%rax), %rcx
addq 0x8(%rsp), %rcx
movl $0x1, %ebx
movl %esi, %r12d
jmp 0x184f94
xorl %ebx, %ebx
movq 0x10(%rsp), %r15
leal 0x1(%rsi), %ebp
movq 0x38(%r15), %rdi
movq %r13, %rsi
callq 0x129f92
subq %rbx, %rax
movq 0x8(%r15), %rdx
addq 0x8(%rsp), %r14
movq %r14, %rcx
addq (%rdx), %rcx
incq %rbx
movq %rax, %r14
movq 0x20(%rsp), %rdx
movq $-0x1, %r13
testq %r14, %r14
je 0x184ff8
movq %rbx, %r15
movl %r12d, (%rsp)
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
movq %rdx, %r12
movq %r14, %r8
movl %ebp, %r9d
callq 0x184e82
cmpq %r14, %rax
jae 0x184ff8
movq 0x38(%rbx), %rdi
cmpl %r12d, 0x18(%rsp)
jae 0x184fdf
movq %r15, %rsi
addq %rax, %rsi
callq 0x12a097
jmp 0x184ff0
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x12a536
movq %rax, %r13
subq 0x8(%rsp), %r13
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq