// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbx
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %r12
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq 0x8(%rdi), %rcx
movq 0x58(%rcx), %rcx
movq %rax, 0x20(%rsp)
testq %r9, %r9
je 0x156849
movq %rbx, %rdi
movq %rbx, 0x10(%rsp)
movq %r15, %rbx
movq %rcx, %r15
callq 0x101a9a
movq %r15, %rcx
movq %rbx, %r15
movq 0x10(%rsp), %rbx
testb %al, %al
jne 0x156a4a
testq %r12, %r12
je 0x156a3b
movq 0x8(%r12), %rdi
cmpq %r14, 0x60(%rdi)
jbe 0x156a40
testq %rbp, %rbp
je 0x156a45
testq %r13, %r13
je 0x156a45
cmpq %rcx, %r14
movq %r14, 0x18(%rsp)
je 0x1569c6
movq 0x28(%rdi), %rdx
movq 0x38(%rdi), %rax
movq 0x48(%rdi), %rdi
testq %rax, %rax
movq %r15, 0x30(%rsp)
je 0x15692f
movq %rdi, 0x28(%rsp)
movq %rdx, 0x10(%rsp)
leaq 0x8(%rsp), %rdx
movq %rcx, %r15
leaq 0x20(%rsp), %rcx
movq %rax, %rdi
movq %r14, %rsi
callq 0x17941b
cmpq %r15, %r14
jb 0x1568cf
movq %r15, %rcx
xorl %r14d, %r14d
cmpq %r15, 0x8(%rsp)
jbe 0x1568fc
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdi
callq 0x156c4f
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x15bf13
movl %eax, %r14d
movq 0x8(%rsp), %rcx
movq 0x8(%r12), %rax
movq %rcx, 0x58(%rax)
movq 0x18(%rsp), %r15
subq %rcx, %r15
movq 0x8(%rsp), %rdx
leaq 0x2351ad(%rip), %rdi    # 0x38babd
movq %r15, %rsi
xorl %eax, %eax
callq 0x108e02
movq 0x20(%rsp), %rsi
leaq 0x2351bf(%rip), %rdi    # 0x38bae5
xorl %eax, %eax
callq 0x108e02
jmp 0x156971
movq %r14, %r15
subq %rcx, %r15
jae 0x15696e
testq %rdi, %rdi
je 0x156a54
movq %rdx, %r15
movq 0x10(%rdi), %rsi
callq 0x156c4f
movq %r15, %rdi
movq %rbx, %rsi
callq 0x15bf13
movl %eax, %r14d
movq 0x8(%r12), %rax
movq $0x0, 0x58(%rax)
movq 0x18(%rsp), %r15
jmp 0x156971
xorl %r14d, %r14d
testl %r14d, %r14d
sete %al
jne 0x1569b8
testq %r15, %r15
je 0x1569b8
movl $0x1, %r14d
movq 0x8(%r12), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x156a59
cmpl $-0x1, %eax
je 0x1569a8
leaq 0x1(%r14), %rcx
cmpq %r15, %r14
movq %rcx, %r14
jb 0x156984
xorl %r14d, %r14d
cmpl $-0x1, %eax
setne %al
sete %r14b
negl %r14d
testb %al, %al
movq 0x30(%rsp), %r15
je 0x1569e1
movq 0x8(%r12), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x156a59
xorl %r14d, %r14d
cmpl $-0x1, %eax
sete %r14b
negl %r14d
testl %r14d, %r14d
je 0x1569f7
movq %rbx, %rdi
callq 0x101a9a
testb %al, %al
jne 0x156a18
callq 0x481ae
movq (%r12), %rdi
testq %rdi, %rdi
je 0x156a15
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x143049
movl %eax, %r14d
jmp 0x156a18
xorl %r14d, %r14d
testl %r14d, %r14d
je 0x156a29
movq %rbx, %rdi
callq 0x101a9a
testb %al, %al
je 0x156a4f
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x48220
callq 0x48103
callq 0x4813c
callq 0x480ca
callq 0x481e7
callq 0x48175