// File: /workspace/github_c_makefile_star2_O2/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)
testq %rdi, %rdi
je 0xf11df
movq %rdx, %r14
testq %rdx, %rdx
je 0xf11df
movq %rsi, %r15
movq %rdi, %r12
movq %rsi, %rdi
callq 0x586b1
cmpq $0x8, %rax
jne 0xf11df
movq 0x28(%r12), %rcx
movq 0x40(%r12), %rdx
leaq -0x1(%rdx), %rax
cmpq %rax, %rcx
jne 0xf0f84
movq 0x38(%r12), %rax
leaq 0x7fffffbf(%rax), %rsi
shrq $0x20, %rsi
jne 0xf0f62
pushq $0x40
popq %rbx
subl %eax, %ebx
cmpq $0x40, %rax
sete %al
testl %ebx, %ebx
setg %sil
orb %al, %sil
jne 0xf0f87
movq 0x346fff(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1f7e44(%rip), %rsi    # 0x2e8db7
leaq 0x233778(%rip), %rdx    # 0x3246f2
movl $0x201, %ecx            # imm = 0x201
jmp 0xf11d0
pushq $0x40
popq %rbx
xorl %eax, %eax
cmpq %rdx, %rcx
jne 0xf0fbd
xorl %ecx, %ecx
cmpq $0x0, 0x10(%r12)
je 0xf116a
cmpl $0x0, 0x48(%r12)
je 0xf116a
leaq 0x2339b3(%rip), %rsi    # 0x324962
movq (%rsp), %rdi
xorl %eax, %eax
callq 0x89dbb
pushq $-0x1
popq %rax
movq %r15, 0x8(%rsp)
leaq 0x40(%r12), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x30(%r12), %rbp
leaq 0x38(%r12), %r15
pushq $0x40
popq %r8
xorl %r13d, %r13d
testl %eax, %eax
jne 0xf1160
cmpq %r14, %r13
jae 0xf1160
movq 0x18(%r12), %rsi
testq %rsi, %rsi
je 0xf117b
movq (%rbp), %rcx
movslq %ebx, %rax
cmpq %rax, %rcx
jne 0xf1096
movq 0x28(%r12), %rdx
movq 0x40(%r12), %rax
leaq 0x1(%rdx), %rcx
movq %rcx, 0x28(%r12)
leaq -0x2(%rax), %rdi
cmpq %rdi, %rdx
jne 0xf1057
movq (%r15), %rdx
leaq 0x7fffffbf(%rdx), %rdi
shrq $0x20, %rdi
jne 0xf11b3
movl %r8d, %ebx
subl %edx, %ebx
cmpq $0x40, %rdx
sete %dl
testl %ebx, %ebx
setg %dil
orb %dl, %dil
je 0xf11b3
cmpq %rax, %rcx
jne 0xf10c7
movq 0x10(%r12), %rax
testq %rax, %rax
je 0xf1168
movq 0x20(%r12), %r8
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq *%rax
movl %eax, 0x48(%r12)
cmpl $-0x1, %eax
je 0xf10d7
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0xf10ee
jmp 0xf116a
movq 0x20(%rsi), %rax
testq %rax, %rax
je 0xf10ce
movq (%r12), %rdx
movq 0x28(%r12), %rdi
movq (%rdx,%rdi,8), %rdx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x30(%r12)
shlq %cl, %rdx
testq %rdx, %rdx
js 0xf111d
movq %rax, 0x18(%r12)
movq %rax, %rsi
jmp 0xf1126
andq $0x0, (%rbp)
jmp 0xf1126
incq %rcx
movq %rcx, (%rbp)
jmp 0xf1126
movq (%rsp), %rdi
leaq 0x23372b(%rip), %rsi    # 0x32480d
xorl %eax, %eax
callq 0x89dbb
movl 0x48(%r12), %eax
andq $0x0, 0x28(%r12)
cmpq $0x1, 0x40(%r12)
pushq $0x40
popq %r8
movl %r8d, %ebx
jne 0xf1109
movl %r8d, %ebx
subl (%r15), %ebx
andq $0x0, (%rbp)
testl %eax, %eax
jne 0xf0fdd
movq 0x18(%r12), %rsi
jmp 0xf1126
movq 0x28(%rsi), %rsi
movq %rsi, 0x18(%r12)
xorl %eax, %eax
cmpq $0x0, 0x20(%rsi)
jne 0xf0fdd
addq $0x18, %rsi
movq 0x8(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x5851d
pushq $0x40
popq %r8
incq %r13
movq 0x8(%r12), %rax
movq 0x10(%rax), %rax
movq %rax, 0x18(%r12)
xorl %eax, %eax
jmp 0xf0fdd
cmpl $0x1, %eax
adcl $0x0, %eax
jmp 0xf116c
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x346de6(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1f3e87(%rip), %rsi    # 0x2e5013
leaq 0x2337e8(%rip), %rdx    # 0x32497b
leaq 0x2337b0(%rip), %rcx    # 0x32494a
leaq 0x233551(%rip), %r8     # 0x3246f2
movl $0x212, %r9d            # imm = 0x212
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x346dae(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1f7bf3(%rip), %rsi    # 0x2e8db7
leaq 0x233527(%rip), %rdx    # 0x3246f2
movl $0x219, %ecx            # imm = 0x219
xorl %eax, %eax
callq 0x17a50
pushq $0x1
popq %rdi
callq 0x178f0
movq 0x346d82(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1f3e23(%rip), %rsi    # 0x2e5013
leaq 0x2336f8(%rip), %rdx    # 0x3248ef
leaq 0x23374c(%rip), %rcx    # 0x32494a
leaq 0x2334ed(%rip), %r8     # 0x3246f2
movl $0x1fe, %r9d            # imm = 0x1FE
jmp 0xf11a7