// File: /workspace/github_c_makefile_star2_O1/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, %r14
movl 0x70(%rsp), %r12d
cmpl %r12d, %r9d
jae 0x18d489
movl %r9d, %ebp
movq %rcx, %r13
movq %rdi, %r15
movq %rsi, 0x30(%rsp)
movq %rdx, 0x18(%rsp)
leal (%r12,%rbp), %eax
shrl %eax
movq %rax, 0x8(%rsp)
testq %rcx, %rcx
je 0x18d4a0
movq 0x38(%r15), %rdi
leaq -0x1(%r13), %rsi
callq 0x12fe86
movq %rax, %rbx
jmp 0x18d4a2
leaq -0x1(%rsi), %rax
cmpq %r14, %rsi
movq $-0x1, %r14
cmovbeq %rax, %r14
jmp 0x18d595
xorl %ebx, %ebx
movq 0x38(%r15), %rdi
leaq (%r14,%r13), %rsi
decq %rsi
movq %rsi, 0x28(%rsp)
callq 0x12fe86
movq %r13, %r14
movq %rax, %r13
subq %rbx, %r13
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rsi
cmpl %edx, %esi
movq %rbx, 0x20(%rsp)
movq %r14, 0x10(%rsp)
jae 0x18d4f4
testq %r14, %r14
je 0x18d508
movq 0x38(%r15), %rdi
leaq -0x1(%r14), %rsi
callq 0x12fe07
movq 0x8(%rsp), %rsi
movq %rax, %rbx
jmp 0x18d50a
movq 0x8(%r15), %rax
movq (%rax), %rcx
addq %r14, %rcx
movl $0x1, %ebx
movl %esi, %r12d
jmp 0x18d536
xorl %ebx, %ebx
leal 0x1(%rsi), %ebp
movq 0x38(%r15), %rdi
movq 0x28(%rsp), %rsi
callq 0x12fe07
subq %rbx, %rax
movq 0x8(%r15), %rdx
addq %r14, %r13
movq %r13, %rcx
addq (%rdx), %rcx
incq %rbx
movq %rax, %r13
movq 0x18(%rsp), %rdx
movq $-0x1, %r14
testq %r13, %r13
je 0x18d595
movl %r12d, (%rsp)
movq %r15, %rdi
movq 0x30(%rsp), %rsi
movq %rdx, %r12
movq %r13, %r8
movl %ebp, %r9d
callq 0x18d439
cmpq %r13, %rax
jae 0x18d595
movq 0x38(%r15), %rdi
cmpl %r12d, 0x8(%rsp)
jae 0x18d579
addq %rax, %rbx
movq %rbx, %rsi
callq 0x12ff0c
jmp 0x18d58a
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x13040d
movq %rax, %r14
movq 0x10(%rsp), %rbx
subq %rbx, %r14
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq