// File: /workspace/github_c_makefile_star2_O3/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 %rdi, %r12
xorl %eax, %eax
movq %rax, 0x18(%rsp)
movq 0x8(%rdi), %rdi
movq 0x58(%rdi), %r14
movq %rax, 0x10(%rsp)
testq %r9, %r9
movq %rsi, (%rsp)
je 0x14ef99
movq %rbx, %rdi
callq 0xfcc32
testb %al, %al
jne 0x14f19d
movq 0x8(%r12), %rdi
movq (%rsp), %rsi
cmpq %rsi, 0x60(%rdi)
jbe 0x14f18e
testq %rbp, %rbp
je 0x14f193
testq %r13, %r13
je 0x14f193
cmpq %r14, %rsi
jne 0x14efcd
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x14f1ac
jmp 0x14f134
movq %r15, 0x30(%rsp)
movq 0x28(%rdi), %rcx
movq 0x38(%rdi), %rax
movq 0x48(%rdi), %rdi
testq %rax, %rax
je 0x14f08f
movq %rdi, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
leaq 0x18(%rsp), %r15
leaq 0x10(%rsp), %rcx
movq %rax, %rdi
movq (%rsp), %rsi
movq %r15, %rdx
callq 0x17106b
movq (%rsp), %rsi
movq (%r15), %rdx
cmpq %r14, %rdx
setbe %al
cmpq %r14, %rsi
setae %cl
movl $0x0, 0xc(%rsp)
testb %al, %cl
jne 0x14f05e
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x14f390
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x154654
movq (%rsp), %rsi
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rdx
movq 0x8(%r12), %rax
movq %rdx, 0x58(%rax)
movq %rdx, %r14
movq %rsi, %r15
subq %r14, %r15
leaq 0x23368f(%rip), %rdi    # 0x3826fa
movq %r15, %rsi
xorl %eax, %eax
callq 0x103d72
movq 0x10(%rsp), %rsi
leaq 0x2336a1(%rip), %rdi    # 0x382722
xorl %eax, %eax
callq 0x103d72
movl 0xc(%rsp), %r14d
jmp 0x14f0d0
movq %rsi, %r15
subq %r14, %r15
jae 0x14f0cd
testq %rdi, %rdi
je 0x14f1a7
movq %rcx, %r14
movq 0x10(%rdi), %rsi
callq 0x14f390
movq %r14, %rdi
movq %rbx, %rsi
callq 0x154654
movl %eax, %r14d
movq 0x8(%r12), %rax
movq $0x0, 0x58(%rax)
movq (%rsp), %r15
jmp 0x14f0d0
xorl %r14d, %r14d
testl %r14d, %r14d
jne 0x14f117
testq %r15, %r15
je 0x14f117
movl $0x1, %r14d
movq 0x8(%r12), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x14f1ac
cmpl $-0x1, %eax
je 0x14f104
leaq 0x1(%r14), %rcx
cmpq %r15, %r14
movq %rcx, %r14
jb 0x14f0e0
xorl %r14d, %r14d
cmpl $-0x1, %eax
sete %al
jne 0x14f11c
movb %al, %r14b
negl %r14d
jmp 0x14f162
testl %r14d, %r14d
jne 0x14f162
movq 0x8(%r12), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x14f1ac
movq 0x30(%rsp), %r15
cmpl $-0x1, %eax
je 0x14f15c
movq (%r12), %rdi
xorl %ebp, %ebp
testq %rdi, %rdi
je 0x14f17d
movq (%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x13c5f7
movl %eax, %r14d
testl %eax, %eax
jne 0x14f16e
jmp 0x14f17d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0xfcc32
testb %al, %al
je 0x14f1a2
movq %rbx, %rdi
callq 0xfcc32
movl %r14d, %ebp
testb %al, %al
je 0x14f198
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x472c8
callq 0x47301
callq 0x473ac
callq 0x4728f
callq 0x47373
callq 0x4733a