// File: /workspace/github_c_makefile_star2_O2/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 0x12ce48
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 0x12ce5c
movq 0x38(%r14), %rdi
leaq -0x1(%rcx), %rbx
movq %rbx, %rsi
callq 0xbf6f8
movq %rax, %r15
jmp 0x12ce62
leaq -0x1(%rsi), %rax
cmpq %r13, %rsi
pushq $-0x1
popq %r13
cmovbeq %rax, %r13
jmp 0x12cf5d
pushq $-0x1
popq %rbx
xorl %r15d, %r15d
movq 0x38(%r14), %rdi
addq %rbx, %r13
movq %r13, %rsi
callq 0xbf6f8
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 0x12ceb5
cmpq $0x0, 0x8(%rsp)
je 0x12cec9
movq 0x10(%rsp), %r15
movq 0x38(%r15), %rdi
movq %rbx, %rsi
callq 0xbf619
movq 0x18(%rsp), %rsi
movq %rax, %rbx
jmp 0x12ced0
movq 0x8(%rcx), %rax
movq (%rax), %rcx
addq 0x8(%rsp), %rcx
pushq $0x1
popq %rbx
movl %esi, %r12d
jmp 0x12cefc
xorl %ebx, %ebx
movq 0x10(%rsp), %r15
leal 0x1(%rsi), %ebp
movq 0x38(%r15), %rdi
movq %r13, %rsi
callq 0xbf619
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
pushq $-0x1
popq %r13
testq %r14, %r14
je 0x12cf5d
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 0x12cdf3
cmpq %r14, %rax
jae 0x12cf5d
movq 0x38(%rbx), %rdi
cmpl %r12d, 0x18(%rsp)
jae 0x12cf44
movq %r15, %rsi
addq %rax, %rsi
callq 0xbf7de
jmp 0x12cf55
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0xbfc1c
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