// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/huffcode.c
// Function: gt_huffman_decoder_next
int gt_huffman_decoder_next(GtHuffmanDecoder *huff_decoder,
                            GtArray *symbols,
                            GtUword symbols_to_read,
                            GtError *err)
{
  int had_err = 0,
      bits_to_read = GT_INTWORDSIZE;
  GtUword read_symbols = 0;

  gt_assert((symbols_to_read > 0) && huff_decoder &&
            (gt_array_elem_size(symbols) == sizeof (GtUword)));

  if (huff_decoder->cur_bitseq == huff_decoder->length - 1)
    gt_safe_assign(bits_to_read, (GT_INTWORDSIZE - huff_decoder->pad_length));

  /* reached end of data in a previous call, didn't get reset */
  if (huff_decoder->cur_bitseq == huff_decoder->length) {
    if (!huff_decoder->mem_func)
      return 0;  /*EOF*/
    else if (huff_decoder->mem_func_stat == 0)
      return 0;
    else {
      had_err = -1;
      gt_error_set(err, "huff decoder reached EOF");
    }
  }

  while (!had_err && read_symbols < symbols_to_read) {

    /* huffman was initialized with empty dist */
    gt_assert(huff_decoder->cur_node != NULL);

    if (!had_err && huff_decoder->cur_bit == (GtUword) bits_to_read) {
      huff_decoder->cur_bitseq++;

      if (huff_decoder->cur_bitseq == huff_decoder->length - 1)
        gt_safe_assign(bits_to_read,
                       (GT_INTWORDSIZE - huff_decoder->pad_length));

      /* no next bitseq ask for more if possible */
      if (huff_decoder->cur_bitseq == huff_decoder->length ) {
        if (!huff_decoder->mem_func) {
          return 0;  /*EOF*/
        }

        huff_decoder->mem_func_stat =
          huff_decoder->mem_func(&huff_decoder->bitsequence,
                                 &huff_decoder->length,
                                 &huff_decoder->cur_bit,
                                 &huff_decoder->pad_length,
                                 huff_decoder->info);
        if (huff_decoder->mem_func_stat == -1) {
          gt_error_set(err, "error calling mem_func");
          had_err = huff_decoder->mem_func_stat;
        }
        else if (huff_decoder->mem_func_stat == 0) {
          return huff_decoder->mem_func_stat; /*EOF*/
        }

        huff_decoder->cur_bitseq = 0;
        bits_to_read = GT_INTWORDSIZE;
        if (huff_decoder->cur_bitseq == huff_decoder->length - 1)
          bits_to_read -= huff_decoder->pad_length;
      }
      huff_decoder->cur_bit = 0;
    }

    /* read the next bit */
    else if (!had_err) {
      /* nothing to do if huffman tree has only one node, just advance the bits
       */
      if (huff_decoder->cur_node->leftchild == NULL)
        huff_decoder->cur_bit++;
      else {
        if (GT_ISBITSET(huff_decoder->bitsequence[huff_decoder->cur_bitseq],
                        huff_decoder->cur_bit++))
          huff_decoder->cur_node = huff_decoder->cur_node->rightchild;
        else
          huff_decoder->cur_node = huff_decoder->cur_node->leftchild;
      }
    }

    /* symbol found, reset huffman */
    if (!had_err && huff_decoder->cur_node->leftchild == NULL) {
      gt_array_add(symbols, huff_decoder->cur_node->symbol.symbol);
      read_symbols++;
      huff_decoder->cur_node = huff_decoder->huffman->root_huffman_tree;
    }
  }
  if (!had_err) {
    /* all read, but not eof */
    return 1;
  }
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, (%rsp)
movq %rsi, 0x8(%rsp)
testq %rdi, %rdi
je 0x154918
movq %rdx, %r15
testq %rdx, %rdx
je 0x154918
movq %rdi, %r14
movq 0x8(%rsp), %rdi
callq 0xd24ed
cmpq $0x8, %rax
jne 0x154918
movq 0x28(%r14), %rax
movq 0x40(%r14), %rcx
leaq -0x1(%rcx), %rdx
movl $0x40, %r12d
cmpq %rdx, %rax
jne 0x154744
movq 0x38(%r14), %rdx
leaq 0x7fffffbf(%rdx), %rsi
shrq $0x20, %rsi
jne 0x15491d
subl %edx, %r12d
cmpq $0x40, %rdx
sete %dl
testl %r12d, %r12d
setg %sil
orb %dl, %sil
je 0x15491d
cmpq %rcx, %rax
jne 0x15477d
xorl %ecx, %ecx
cmpq $0x0, 0x10(%r14)
je 0x1548fd
cmpl $0x0, 0x48(%r14)
je 0x1548fd
leaq 0x22fdf2(%rip), %rsi    # 0x38455a
movq (%rsp), %rdi
xorl %eax, %eax
callq 0xfcb67
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1548f3
leaq 0x40(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x30(%r14), %rbp
leaq 0x38(%r14), %rbx
xorl %r13d, %r13d
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0x15490e
movq (%rbp), %rcx
movslq %r12d, %rax
cmpq %rax, %rcx
jne 0x154837
movq 0x28(%r14), %rdx
movq 0x40(%r14), %rax
leaq 0x1(%rdx), %rcx
movq %rcx, 0x28(%r14)
leaq -0x2(%rax), %rdi
cmpq %rdi, %rdx
jne 0x1547fb
movq (%rbx), %rdx
leaq 0x7fffffbf(%rdx), %rdi
shrq $0x20, %rdi
jne 0x154913
movl $0x40, %r12d
subl %edx, %r12d
cmpq $0x40, %rdx
sete %dl
testl %r12d, %r12d
setg %dil
orb %dl, %dil
je 0x154913
cmpq %rax, %rcx
jne 0x154864
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x1548fb
movq 0x20(%r14), %r8
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq *%rax
movl %eax, 0x48(%r14)
cmpl $-0x1, %eax
je 0x154877
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0x15488d
jmp 0x1548fd
movq 0x20(%rsi), %rax
testq %rax, %rax
je 0x15486e
movq (%r14), %rdx
movq 0x28(%r14), %rdi
movq (%rdx,%rdi,8), %rdx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x30(%r14)
shlq %cl, %rdx
testq %rdx, %rdx
js 0x1548b7
movq %rax, 0x18(%r14)
movq %rax, %rsi
jmp 0x1548bf
movq $0x0, (%rbp)
jmp 0x1548bf
incq %rcx
movq %rcx, (%rbp)
jmp 0x1548bf
movq (%rsp), %rdi
leaq 0x22fb83(%rip), %rsi    # 0x384405
xorl %eax, %eax
callq 0xfcb67
movl 0x48(%r14), %eax
movq $0x0, 0x28(%r14)
movl $0x40, %r12d
cmpq $0x1, 0x40(%r14)
jne 0x1548a5
subl (%rbx), %r12d
movq $0x0, (%rbp)
testl %eax, %eax
jne 0x1548f3
movq 0x18(%r14), %rsi
jmp 0x1548bf
movq 0x28(%rsi), %rsi
movq %rsi, 0x18(%r14)
cmpq $0x0, 0x20(%rsi)
jne 0x1548e8
addq $0x18, %rsi
movl $0x8, %edx
movq 0x8(%rsp), %rdi
callq 0xd2410
incq %r13
movq 0x8(%r14), %rax
movq 0x10(%rax), %rax
movq %rax, 0x18(%r14)
cmpq %r15, %r13
jb 0x154791
xorl %eax, %eax
cmpl $0x1, %eax
adcl $0x0, %eax
jmp 0x1548ff
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4926b
callq 0x4923e
callq 0x491d8
callq 0x49211