// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rcx, %r13
movq %rdx, %rbp
andq $0x0, 0x18(%rsp)
movq %rsi, %r15
movq %rdi, (%rsp)
movq 0x8(%rdi), %rdi
movq 0x58(%rdi), %r12
andq $0x0, 0x8(%rsp)
testq %r9, %r9
je 0xea216
movq %rbx, %rdi
callq 0x89eb7
testb %al, %al
jne 0xea492
movq (%rsp), %rax
movq 0x8(%rax), %rdi
cmpq %r15, 0x60(%rdi)
jbe 0xea402
testq %rbp, %rbp
je 0xea433
testq %r13, %r13
je 0xea433
cmpq %r12, %r15
jne 0xea24a
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0xea526
jmp 0xea3a4
movq 0x28(%rdi), %rcx
movq 0x38(%rdi), %rax
movq 0x48(%rdi), %rdi
testq %rax, %rax
movq %r14, 0x30(%rsp)
movq %r15, 0x10(%rsp)
je 0xea303
movq %rdi, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
leaq 0x18(%rsp), %r14
leaq 0x8(%rsp), %rcx
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x11436c
movq (%r14), %rdx
cmpq %r12, %rdx
setbe %al
cmpq %r12, %r15
setae %cl
xorl %r14d, %r14d
testb %al, %cl
jne 0xea2d4
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0xea72b
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0xf0e27
movl %eax, %r14d
movq 0x18(%rsp), %rdx
movq (%rsp), %rax
movq 0x8(%rax), %rax
movq %rdx, 0x58(%rax)
movq %rdx, %r12
movq %r12, %rax
movq %rbx, %r12
subq %rax, %r15
leaq 0x238822(%rip), %rdi    # 0x322b06
movq %r15, %rsi
xorl %eax, %eax
callq 0x92a82
movq 0x8(%rsp), %rsi
leaq 0x238834(%rip), %rdi    # 0x322b2e
xorl %eax, %eax
callq 0x92a82
jmp 0xea348
subq %r12, %r15
jae 0xea342
testq %rdi, %rdi
je 0xea4f8
movq %rcx, %r15
movq 0x10(%rdi), %rsi
callq 0xea72b
movq %r15, %rdi
movq %rbx, %r12
movq %rbx, %rsi
callq 0xf0e27
movl %eax, %r14d
movq (%rsp), %rax
movq 0x8(%rax), %rax
andq $0x0, 0x58(%rax)
movq 0x10(%rsp), %r15
jmp 0xea348
movq %rbx, %r12
xorl %r14d, %r14d
xorl %ebx, %ebx
testl %r14d, %r14d
jne 0xea37c
cmpq %r15, %rbx
jae 0xea37c
movq (%rsp), %rax
movq 0x8(%rax), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0xea526
xorl %r14d, %r14d
cmpl $-0x1, %eax
sete %r14b
negl %r14d
incq %rbx
jmp 0xea34a
testl %r14d, %r14d
movq %r12, %rbx
jne 0xea3d2
movq (%rsp), %rax
movq 0x8(%rax), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0xea526
movq 0x30(%rsp), %r14
movq 0x10(%rsp), %r15
cmpl $-0x1, %eax
je 0xea3ce
movq (%rsp), %rax
movq (%rax), %rdi
xorl %ebp, %ebp
testq %rdi, %rdi
je 0xea3f1
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0xd2e46
movl %eax, %r14d
testl %eax, %eax
jne 0xea3e2
jmp 0xea3f1
pushq $-0x1
popq %r14
movq %rbx, %rdi
callq 0x89eb7
testb %al, %al
je 0xea4c0
movq %rbx, %rdi
callq 0x89eb7
movl %r14d, %ebp
testb %al, %al
je 0xea464
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x34db5f(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fac00(%rip), %rsi    # 0x2e5013
leaq 0x2386a7(%rip), %rdx    # 0x322ac1
leaq 0x23868a(%rip), %rcx    # 0x322aab
leaq 0x238630(%rip), %r8     # 0x322a58
movl $0x3c8, %r9d            # imm = 0x3C8
jmp 0xea4ec
movq 0x34db2e(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fabcf(%rip), %rsi    # 0x2e5013
leaq 0x23869f(%rip), %rdx    # 0x322aea
leaq 0x238659(%rip), %rcx    # 0x322aab
leaq 0x2385ff(%rip), %r8     # 0x322a58
movl $0x3c9, %r9d            # imm = 0x3C9
jmp 0xea4ec
movq 0x34dafd(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fab9e(%rip), %rsi    # 0x2e5013
leaq 0x21e5f9(%rip), %rdx    # 0x308a75
leaq 0x238628(%rip), %rcx    # 0x322aab
leaq 0x2385ce(%rip), %r8     # 0x322a58
movl $0x3fe, %r9d            # imm = 0x3FE
jmp 0xea4ec
movq 0x34dacf(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fab70(%rip), %rsi    # 0x2e5013
leaq 0x1fad15(%rip), %rdx    # 0x2e51bf
leaq 0x2385fa(%rip), %rcx    # 0x322aab
leaq 0x2385a0(%rip), %r8     # 0x322a58
movl $0x3c6, %r9d            # imm = 0x3C6
jmp 0xea4ec
movq 0x34daa1(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fab42(%rip), %rsi    # 0x2e5013
leaq 0x21e59d(%rip), %rdx    # 0x308a75
leaq 0x2385cc(%rip), %rcx    # 0x322aab
leaq 0x238572(%rip), %r8     # 0x322a58
movl $0x3f9, %r9d            # imm = 0x3F9
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x34da69(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fab0a(%rip), %rsi    # 0x2e5013
leaq 0x238b37(%rip), %rdx    # 0x323047
leaq 0x238b82(%rip), %rcx    # 0x323099
leaq 0x23853a(%rip), %r8     # 0x322a58
movl $0x2a3, %r9d            # imm = 0x2A3
jmp 0xea4ec