// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/extended/hcr.c
// Function: gt_hcr_decoder_decode
int gt_hcr_decoder_decode(GtHcrDecoder *hcr_dec, GtUword readnum,
                          char *seq, char *qual, GtStr *desc, GtError *err)
{
  int had_err = 0;
  GtUword nearestsample = 0,
                reads_to_read = 0,
                idx,
                current_read = hcr_dec->seq_dec->cur_read ;
  size_t startofnearestsample = 0;
  GtSampling *sampling;
  HcrHuffDataIterator *data_iter;
  GtHuffmanDecoder *huff_dec;

  gt_error_check(err);
  gt_assert(hcr_dec);
  gt_assert(readnum < hcr_dec->seq_dec->num_of_reads);
  gt_assert(seq != NULL && qual != NULL);

  if (current_read == readnum)
    had_err = hcr_next_seq_qual(hcr_dec->seq_dec, seq, qual, err) == -1 ?
      -1 : 0;
  else {
    sampling = hcr_dec->seq_dec->sampling;
    data_iter = hcr_dec->seq_dec->data_iter;
    huff_dec = hcr_dec->seq_dec->huff_dec;

    if (sampling != NULL) {
      gt_sampling_get_page(sampling,
                           readnum,
                           &nearestsample,
                           &startofnearestsample);
      /* nearestsample <= cur_read < readnum: current sample is the right one */
      if (nearestsample <= current_read && current_read <= readnum)
        reads_to_read = readnum - current_read;
      else { /* reset decoder to new sample */
        reset_data_iterator_to_pos(data_iter, startofnearestsample);
        had_err = gt_huffman_decoder_get_new_mem_chunk(huff_dec, err);
        reads_to_read = readnum - nearestsample;
        hcr_dec->seq_dec->cur_read = nearestsample;
      }
      gt_log_log("reads to read: "GT_WU", nearest sample: "GT_WU"",
                 reads_to_read,nearestsample);
      gt_log_log("start of nearest: "GT_WU"", (GtUword) startofnearestsample);
    }
    else {
      if (current_read <= readnum)
        reads_to_read = readnum - current_read;
      else {
        reset_data_iterator_to_start(data_iter);
        had_err = gt_huffman_decoder_get_new_mem_chunk(huff_dec, err);
        reads_to_read = readnum;
        hcr_dec->seq_dec->cur_read = 0;
      }
    }

    for (idx = 0; !had_err && idx < reads_to_read; idx++)
      had_err = hcr_next_seq_qual(hcr_dec->seq_dec, seq,qual, err) == -1 ?
        -1 : 0;

    if (!had_err)
      had_err = hcr_next_seq_qual(hcr_dec->seq_dec, seq, qual, err) == -1 ?
        -1 : 0;
  }
  if (had_err)
    gt_assert(gt_error_is_set(err));

  if (!had_err && hcr_dec->encdesc != NULL)
    had_err = gt_encdesc_decode(hcr_dec->encdesc, readnum, desc, err);
  if (had_err)
    gt_assert(gt_error_is_set(err));

  return had_err;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movq %r8, 0x60(%rsp)
movq %r9, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x58(%rax), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x186380
movq 0x58(%rsp), %rdi
callq 0xd8a60
testb $0x1, %al
jne 0x186348
jmp 0x186380
movq 0x4b5c51(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x38fcba(%rip), %rsi    # 0x516013
leaq 0x38fe5f(%rip), %rdx    # 0x5161bf
leaq 0x3ce9d7(%rip), %rcx    # 0x554d3e
leaq 0x3ce97d(%rip), %r8     # 0x554ceb
movl $0x3c6, %r9d            # imm = 0x3C6
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x186382
jmp 0x186384
cmpq $0x0, 0x80(%rsp)
jne 0x1863c7
movq 0x4b5c0a(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x38fc73(%rip), %rsi    # 0x516013
leaq 0x3ce96e(%rip), %rdx    # 0x554d15
leaq 0x3ce990(%rip), %rcx    # 0x554d3e
leaq 0x3ce936(%rip), %r8     # 0x554ceb
movl $0x3c7, %r9d            # imm = 0x3C7
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x1863c9
jmp 0x1863cb
movq 0x78(%rsp), %rax
movq 0x80(%rsp), %rcx
movq 0x8(%rcx), %rcx
cmpq 0x60(%rcx), %rax
jb 0x18641a
movq 0x4b5bb7(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x38fc20(%rip), %rsi    # 0x516013
leaq 0x3ce95a(%rip), %rdx    # 0x554d54
leaq 0x3ce93d(%rip), %rcx    # 0x554d3e
leaq 0x3ce8e3(%rip), %r8     # 0x554ceb
movl $0x3c8, %r9d            # imm = 0x3C8
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x18641c
jmp 0x18641e
cmpq $0x0, 0x70(%rsp)
je 0x18642e
cmpq $0x0, 0x68(%rsp)
jne 0x186466
movq 0x4b5b6b(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x38fbd4(%rip), %rsi    # 0x516013
leaq 0x3ce937(%rip), %rdx    # 0x554d7d
leaq 0x3ce8f1(%rip), %rcx    # 0x554d3e
leaq 0x3ce897(%rip), %r8     # 0x554ceb
movl $0x3c9, %r9d            # imm = 0x3C9
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x186468
movq 0x30(%rsp), %rax
cmpq 0x78(%rsp), %rax
jne 0x1864ac
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x58(%rsp), %rcx
callq 0x1867a0
movl %eax, %edx
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $-0x1, %edx
cmovel %ecx, %eax
movl %eax, 0x54(%rsp)
jmp 0x1866b6
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x38(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x48(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x1865ac
movq 0x20(%rsp), %rdi
movq 0x78(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x1d0450
movq 0x48(%rsp), %rax
cmpq 0x30(%rsp), %rax
ja 0x186539
movq 0x30(%rsp), %rax
cmpq 0x78(%rsp), %rax
ja 0x186539
movq 0x78(%rsp), %rax
subq 0x30(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x18657f
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x186b50
movq 0x10(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x192880
movl %eax, 0x54(%rsp)
movq 0x78(%rsp), %rax
subq 0x48(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rcx
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x58(%rax)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
leaq 0x3ce809(%rip), %rdi    # 0x554d99
movb $0x0, %al
callq 0xe7740
movq 0x28(%rsp), %rsi
leaq 0x3ce81e(%rip), %rdi    # 0x554dc1
movb $0x0, %al
callq 0xe7740
jmp 0x186606
movq 0x30(%rsp), %rax
cmpq 0x78(%rsp), %rax
ja 0x1865c9
movq 0x78(%rsp), %rax
subq 0x30(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x186604
movq 0x18(%rsp), %rdi
callq 0x186c70
movq 0x10(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x192880
movl %eax, 0x54(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rax
movq $0x0, 0x58(%rax)
jmp 0x186606
movq $0x0, 0x38(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x54(%rsp)
movb %al, 0xf(%rsp)
jne 0x18662d
movq 0x38(%rsp), %rax
cmpq 0x40(%rsp), %rax
setb %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x186637
jmp 0x18667a
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x58(%rsp), %rcx
callq 0x1867a0
movl %eax, %edx
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $-0x1, %edx
cmovel %ecx, %eax
movl %eax, 0x54(%rsp)
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x18660f
cmpl $0x0, 0x54(%rsp)
jne 0x1866b4
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x58(%rsp), %rcx
callq 0x1867a0
movl %eax, %edx
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $-0x1, %edx
cmovel %ecx, %eax
movl %eax, 0x54(%rsp)
jmp 0x1866b6
cmpl $0x0, 0x54(%rsp)
je 0x186709
jmp 0x1866bf
movq 0x58(%rsp), %rdi
callq 0xd8a60
testb $0x1, %al
jne 0x186705
movq 0x4b58cc(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x38f935(%rip), %rsi    # 0x516013
leaq 0x3b38a2(%rip), %rdx    # 0x539f87
leaq 0x3ce652(%rip), %rcx    # 0x554d3e
leaq 0x3ce5f8(%rip), %r8     # 0x554ceb
movl $0x3f9, %r9d            # imm = 0x3F9
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x186707
jmp 0x186709
cmpl $0x0, 0x54(%rsp)
jne 0x186741
movq 0x80(%rsp), %rax
cmpq $0x0, (%rax)
je 0x186741
movq 0x80(%rsp), %rax
movq (%rax), %rdi
movq 0x78(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x58(%rsp), %rcx
callq 0x161ca0
movl %eax, 0x54(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x186794
jmp 0x18674a
movq 0x58(%rsp), %rdi
callq 0xd8a60
testb $0x1, %al
jne 0x186790
movq 0x4b5841(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x38f8aa(%rip), %rsi    # 0x516013
leaq 0x3b3817(%rip), %rdx    # 0x539f87
leaq 0x3ce5c7(%rip), %rcx    # 0x554d3e
leaq 0x3ce56d(%rip), %r8     # 0x554ceb
movl $0x3fe, %r9d            # imm = 0x3FE
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x186792
jmp 0x186794
movl 0x54(%rsp), %eax
addq $0x88, %rsp
retq