// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/extended/wtree_encseq.c
// Function: gt_wtree_encseq_rank_rec
static GtUword gt_wtree_encseq_rank_rec(GtWtreeEncseq *we,
                                        GtUword pos,
                                        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,
          rank;
  gt_log_log("alphabet: %u-%u-%u, sym: " GT_WU,
             alpha_start, middle, alpha_end, (GtUword) sym);
  gt_log_log("pos: "GT_WU"", pos);
  gt_assert(pos < node_size);

  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) {
      rank = gt_compressed_bitsequence_rank_0(we->c_bits, node_start + pos) -
        zero_rank_prefix;
      alpha_end = middle;
      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);
      rank = gt_compressed_bitsequence_rank_1(we->c_bits, node_start + pos) -
        one_rank_prefix;
      alpha_start = middle + 1;
      node_size =
        gt_compressed_bitsequence_rank_1(we->c_bits,
                                         node_start + node_size - 1) -
        one_rank_prefix;
      node_start +=
        we->parent_instance.members->length + left_child_size;
    }
    gt_log_log("bit: %d, nodesize: "GT_WU"", bit, node_size);
    if (node_size != 0 && rank != 0) {
      pos = rank - 1;
      return gt_wtree_encseq_rank_rec(we, pos, sym,
                                      node_start, node_size, alpha_start,
                                      alpha_end);
    }
    return 0;
  }
  gt_log_log("found: rank="GT_WU"", pos + 1);
  return pos + 1; /* convert position to count */
}

// Assembly:
subq $0x68, %rsp
movl 0x70(%rsp), %eax
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movl %r9d, 0x34(%rsp)
movl 0x34(%rsp), %eax
addl 0x70(%rsp), %eax
shrl %eax
movl %eax, 0x30(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movl 0x34(%rsp), %esi
movl 0x30(%rsp), %edx
movl 0x70(%rsp), %ecx
movq 0x48(%rsp), %r8
leaq 0x37744b(%rip), %rdi    # 0x56f419
movb $0x0, %al
callq 0xe7740
movq 0x50(%rsp), %rsi
leaq 0x35ff65(%rip), %rdi    # 0x557f46
movb $0x0, %al
callq 0xe7740
movq 0x50(%rsp), %rax
cmpq 0x38(%rsp), %rax
jb 0x1f802c
movq 0x443fa5(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x31e00e(%rip), %rsi    # 0x516013
leaq 0x3773cd(%rip), %rdx    # 0x56f3d9
leaq 0x377423(%rip), %rcx    # 0x56f436
leaq 0x37736f(%rip), %r8     # 0x56f389
movl $0x97, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x1f802e
movl 0x34(%rsp), %eax
cmpl 0x70(%rsp), %eax
jae 0x1f81fa
movl 0x30(%rsp), %edx
movq 0x48(%rsp), %rax
movl %eax, %esi
xorl %eax, %eax
movl $0x1, %ecx
cmpl %esi, %edx
cmovbl %ecx, %eax
movl %eax, 0x2c(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0x1f807b
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0x40(%rsp), %rsi
subq $0x1, %rsi
callq 0x13b2c0
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0x40(%rsp), %rsi
addq 0x38(%rsp), %rsi
subq $0x1, %rsi
callq 0x13b2c0
subq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x2c(%rsp)
jne 0x1f80f7
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0x40(%rsp), %rsi
addq 0x50(%rsp), %rsi
callq 0x13b2c0
subq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x70(%rsp)
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rsp)
jmp 0x1f8189
cmpq $0x0, 0x40(%rsp)
je 0x1f811b
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0x40(%rsp), %rsi
subq $0x1, %rsi
callq 0x13b130
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0x40(%rsp), %rsi
addq 0x50(%rsp), %rsi
callq 0x13b130
subq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0x40(%rsp), %rsi
addq 0x38(%rsp), %rsi
subq $0x1, %rsi
callq 0x13b130
subq 0x18(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
addq 0x10(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0x2c(%rsp), %esi
movq 0x38(%rsp), %rdx
leaq 0x3772b6(%rip), %rdi    # 0x56f44f
movb $0x0, %al
callq 0xe7740
cmpq $0x0, 0x38(%rsp)
je 0x1f81ef
cmpq $0x0, 0x8(%rsp)
je 0x1f81ef
movq 0x8(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r8
movl 0x34(%rsp), %r9d
movl 0x70(%rsp), %eax
movl %eax, (%rsp)
callq 0x1f7f70
movq %rax, 0x60(%rsp)
jmp 0x1f821f
movq $0x0, 0x60(%rsp)
jmp 0x1f821f
movq 0x50(%rsp), %rsi
addq $0x1, %rsi
leaq 0x37725c(%rip), %rdi    # 0x56f466
movb $0x0, %al
callq 0xe7740
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
nopl (%rax)