// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/hcr.c
// Function: gt_hcr_encoder_new
GtHcrEncoder *gt_hcr_encoder_new(GtStrArray *files, GtAlphabet *alpha,
                                 bool descs, GtQualRange qrange, GtTimer *timer,
                                 GtError *err)
{
  GtBaseQualDistr *bqd;
  GtHcrEncoder *hcr_enc;
  GtSeqIterator *seqit;
  GtStrArray *file;
  int had_err = 0,
      status;
  GtUword len1,
                len2,
                i,
                num_of_reads = 0;
  const GtUchar *seq,
                *qual;
  char *desc;

  gt_error_check(err);
  gt_assert(alpha && files);

  if (timer != NULL)
    gt_timer_show_progress(timer, "get <base,qual> distr", stdout);

  if (qrange.start != GT_UNDEF_UINT)
    if (qrange.start == qrange.end) {
      gt_error_set(err, "qrange.start must unequal qrange.end");
      return NULL;
    }

  hcr_enc = gt_malloc(sizeof (GtHcrEncoder));
  hcr_enc->files = files;
  hcr_enc->num_of_files = gt_str_array_size(files);
  hcr_enc->num_of_reads = 0;
  hcr_enc->page_sampling = false;
  hcr_enc->regular_sampling = false;
  hcr_enc->sampling_rate = 0;
  hcr_enc->pagesize = gt_pagesize();
  if (descs) {
    hcr_enc->encdesc_encoder = gt_encdesc_encoder_new();
    if (timer != NULL)
      gt_encdesc_encoder_set_timer(hcr_enc->encdesc_encoder, timer);
  }
  else
    hcr_enc->encdesc_encoder = NULL;

  hcr_enc->seq_encoder = gt_malloc(sizeof (GtHcrSeqEncoder));
  hcr_enc->seq_encoder->alpha = alpha;
  hcr_enc->seq_encoder->sampling = NULL;
  hcr_enc->seq_encoder->fileinfos = gt_calloc((size_t) hcr_enc->num_of_files,
                                   sizeof (*(hcr_enc->seq_encoder->fileinfos)));
  hcr_enc->seq_encoder->qrange = qrange;
  bqd = hcr_base_qual_distr_new(alpha, qrange);

  /* check if reads in the same file are of same length and get
     <base, quality> pair distribution */
  for (i = 0; i < hcr_enc->num_of_files; i++) {
    file = gt_str_array_new();
    gt_str_array_add(file, gt_str_array_get_str(files, i));
    seqit = gt_seq_iterator_fastq_new(file, err);
    if (!seqit) {
      gt_error_set(err, "cannot initialize GtSeqIteratorFastQ object");
      had_err = -1;
    }
    if (!had_err) {
      gt_seq_iterator_set_symbolmap(seqit, gt_alphabet_symbolmap(alpha));
      gt_seq_iterator_set_quality_buffer(seqit, &qual);
      status = gt_seq_iterator_next(seqit, &seq, &len1, &desc, err);

      if (status == 1) {
        num_of_reads = 1UL;
        while (!had_err) {
          status = gt_seq_iterator_next(seqit, &seq, &len2, &desc, err);
          if (status == -1)
            had_err = -1;
          if (status != 1)
            break;
          if (len2 != len1) {
            gt_error_set(err, "reads have to be of equal length");
            had_err = -1;
            break;
          }
          if (hcr_base_qual_distr_add(bqd, qual, seq, len1) != 0)
            had_err = -1;
          len1 = len2;
          num_of_reads++;
        }
      }
      else if (status == -1)
        had_err = -1;

      if (!had_err) {
        if (i == 0)
          hcr_enc->seq_encoder->fileinfos[i].readnum = num_of_reads;
        else
          hcr_enc->seq_encoder->fileinfos[i].readnum =
            hcr_enc->seq_encoder->fileinfos[i - 1].readnum + num_of_reads;
        hcr_enc->seq_encoder->fileinfos[i].readlength = len1;
      }
    }
    hcr_enc->num_of_reads += num_of_reads;
    gt_str_array_delete(file);
    gt_seq_iterator_delete(seqit);
  }
  if (!had_err)
    hcr_base_qual_distr_trim(bqd);

  if (!had_err) {
    if (timer != NULL)
      gt_timer_show_progress(timer, "build huffman tree for sequences and"
                             " qualities", stdout);
    hcr_enc->seq_encoder->huffman =
      gt_huffman_new(bqd,
                     hcr_base_qual_distr_func,
                     (GtUword) bqd->ncols * bqd->nrows);
  }
  if (!had_err) {
    hcr_enc->seq_encoder->qual_offset = bqd->qual_offset;
    hcr_base_qual_distr_delete(bqd);
    return hcr_enc;
  }
  return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %r13
movq %r8, %r15
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, (%rsp)
movq %rdi, 0x18(%rsp)
testq %r9, %r9
je 0xeac57
movq %r13, %rdi
callq 0x89eb7
testb %al, %al
jne 0xeb159
cmpq $0x0, 0x18(%rsp)
je 0xeb12b
cmpq $0x0, (%rsp)
je 0xeb12b
movq %rbx, %r14
shrq $0x20, %r14
testq %r15, %r15
je 0xeac93
movq 0x34d22f(%rip), %rax    # 0x437eb0
movq (%rax), %rdx
leaq 0x237fb5(%rip), %rsi    # 0x322c40
movq %r15, %rdi
callq 0xaf86f
cmpl $-0x1, %ebx
setne %al
cmpl %r14d, %ebx
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xeacbf
leaq 0x237fa9(%rip), %rsi    # 0x322c56
xorl %r14d, %r14d
movq %r13, %rdi
xorl %eax, %eax
callq 0x89dbb
jmp 0xeb119
leaq 0x237d92(%rip), %rsi    # 0x322a58
pushq $0x40
popq %rdi
movl $0x46b, %edx            # imm = 0x46B
callq 0x93160
movq %rax, %r12
movq 0x18(%rsp), %rdi
movq %rdi, 0x10(%rax)
callq 0xae61c
movq %rax, 0x20(%r12)
andq $0x0, 0x18(%r12)
andw $0x0, 0x38(%r12)
andq $0x0, 0x28(%r12)
callq 0x6be41
movq %rax, 0x30(%r12)
testb %bpl, %bpl
je 0xead26
callq 0xd1220
movq %rax, (%r12)
testq %r15, %r15
je 0xead2b
movq %rax, %rdi
movq %r15, %rsi
callq 0xd1280
jmp 0xead2b
andq $0x0, (%r12)
movq %r15, 0x48(%rsp)
leaq 0x237d21(%rip), %rbp    # 0x322a58
pushq $0x50
popq %rdi
movq %rbp, %rsi
movl $0x47b, %edx            # imm = 0x47B
callq 0x93160
movq %rax, 0x8(%r12)
movq (%rsp), %r15
movq %r15, 0x10(%rax)
andq $0x0, 0x20(%rax)
movq 0x20(%r12), %rdi
pushq $0x10
popq %rsi
movq %rbp, %rdx
movl $0x47f, %ecx            # imm = 0x47F
callq 0x9334a
movq %r12, 0x8(%rsp)
movq 0x8(%r12), %rcx
movq %rax, 0x8(%rcx)
movl %ebx, (%rcx)
movl %r14d, 0x4(%rcx)
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
movq %rbp, %r12
movq %rbp, %rdx
movl $0xe5, %ecx
callq 0x9334a
movq %rax, %rbp
movl $0x400, %edi            # imm = 0x400
movq %r12, %rsi
movl $0xe7, %edx
callq 0x93160
movq %rax, (%rbp)
movq %r15, %rdi
callq 0x56cd2
movl %eax, %edi
shlq $0x7, %rdi
pushq $0x8
popq %rsi
movq %r12, %rdx
movl $0xe7, %ecx
callq 0x9334a
movq (%rbp), %rcx
movq %rax, (%rcx)
xorl %r15d, %r15d
cmpq $0x7f, %r15
je 0xeae04
movq (%rbp), %rax
movq (%rax,%r15,8), %r12
movq (%rsp), %rdi
callq 0x56cd2
movl %eax, %eax
leaq (%r12,%rax,8), %rax
movq (%rbp), %rcx
movq %rax, 0x8(%rcx,%r15,8)
incq %r15
jmp 0xeadd9
movq (%rsp), %r15
movq %r15, %rdi
callq 0x56cd2
movl %eax, 0x10(%rbp)
movl $0x80, 0x14(%rbp)
andl $0x0, 0x28(%rbp)
movq %r15, %rdi
callq 0x56cd2
decl %eax
movl %eax, 0x20(%rbp)
movabsq $0x7f00000000, %rax     # imm = 0x7F00000000
movq %rax, 0x18(%rbp)
movl %ebx, 0x24(%rbp)
movl %r14d, 0x2c(%rbp)
movq %r15, 0x8(%rbp)
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %ebx, %ebx
movq 0x8(%rsp), %r14
movq %r13, 0x50(%rsp)
cmpq 0x20(%r14), %r12
jae 0xeb0b8
callq 0xae154
movq %r13, %r14
movq %rax, %r13
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xae3f2
movq %r13, %rdi
movq %rax, %rsi
callq 0xae31d
movq %r13, 0x60(%rsp)
movq %r13, %rdi
movq %r14, %r13
movq %r14, %rsi
callq 0xa6e33
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0xeb014
testl %r15d, %r15d
jne 0xeb025
movq (%rsp), %rdi
callq 0x56c48
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0xa61a8
movq %r14, %rdi
leaq 0x70(%rsp), %rsi
callq 0xa6240
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0x68(%rsp), %rcx
movq %r13, %r8
callq 0xa62e5
movl %eax, %r15d
cmpl $-0x1, %eax
movq 0x8(%rsp), %r14
je 0xeb02e
cmpl $0x1, %r15d
jne 0xeb05d
movl $0x0, 0x14(%rsp)
pushq $0x1
popq %rbx
movq %r12, 0x58(%rsp)
cmpl $0x0, 0x14(%rsp)
jne 0xeb04e
movq 0x20(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x68(%rsp), %rcx
movq %r13, %r8
callq 0xa62e5
cmpl $-0x1, %eax
sete %cl
cmpl $0x1, %eax
jne 0xeb054
movq %rbx, 0x30(%rsp)
movq 0x40(%rsp), %rbx
cmpq 0x28(%rsp), %rbx
jne 0xeb099
xorl %eax, %eax
movb %cl, %al
negl %eax
movl %eax, 0x14(%rsp)
movq 0x70(%rsp), %r13
movq 0x38(%rsp), %r12
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0xeafee
movq 0x8(%rbp), %r15
movzbl (%r12,%r14), %esi
movq %r15, %rdi
callq 0x5728b
movsbl %al, %esi
movq %r15, %rdi
callq 0x57552
movzbl (%r13,%r14), %ecx
movl 0x24(%rbp), %edx
cmpl %ecx, %edx
movl %ecx, %esi
cmoval %edx, %esi
cmpl $-0x1, %edx
cmovel %ecx, %esi
movl 0x2c(%rbp), %edx
cmpl %edx, %esi
movl %edx, %ecx
cmovbl %esi, %ecx
cmpl $-0x1, %edx
cmovel %esi, %ecx
cmpb $-0x2, %al
jne 0xeafca
movl 0x20(%rbp), %eax
jmp 0xeafcd
movzbl %al, %eax
movq (%rbp), %rdx
movq (%rdx,%rcx,8), %rdx
incq (%rdx,%rax,8)
cmpl 0x18(%rbp), %ecx
jbe 0xeafe1
movl %ecx, 0x18(%rbp)
cmpl 0x1c(%rbp), %ecx
jae 0xeafe9
movl %ecx, 0x1c(%rbp)
incq %r14
jmp 0xeaf7a
movq 0x40(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rbx
incq %rbx
movq 0x50(%rsp), %r13
movq 0x8(%rsp), %r14
movq 0x58(%rsp), %r12
jmp 0xeaf18
movq %r13, %rdi
leaq 0x237c5d(%rip), %rsi    # 0x322c7b
xorl %eax, %eax
callq 0x89dbb
pushq $-0x1
popq %r15
movq 0x8(%rsp), %r14
addq %rbx, 0x18(%r14)
movq 0x60(%rsp), %rdi
callq 0xae662
movq 0x20(%rsp), %rdi
callq 0xa6389
incq %r12
jmp 0xeae56
pushq $-0x1
popq %r15
jmp 0xeb02e
pushq $-0x1
popq %r15
cmpl $-0x1, %eax
je 0xeb02e
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
testq %r12, %r12
je 0xeb080
movq %r12, %rcx
shlq $0x4, %rcx
movq -0x8(%rax,%rcx), %rdx
addq %rbx, %rdx
movq %rdx, 0x8(%rax,%rcx)
jmp 0xeb084
movq %rbx, 0x8(%rax)
movq 0x28(%rsp), %rcx
movq %r12, %rdx
shlq $0x4, %rdx
movq %rcx, (%rax,%rdx)
xorl %r15d, %r15d
jmp 0xeb02e
movq %r13, %rdi
leaq 0x237c04(%rip), %rsi    # 0x322ca7
xorl %eax, %eax
callq 0x89dbb
pushq $-0x1
popq %r15
movq 0x30(%rsp), %rbx
jmp 0xeb02e
testl %r15d, %r15d
je 0xeb0c2
xorl %r14d, %r14d
jmp 0xeb119
movq %rbp, %rdi
callq 0xeb191
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xeb0ea
movq 0x34cdd5(%rip), %rax    # 0x437eb0
movq (%rax), %rdx
leaq 0x237be3(%rip), %rsi    # 0x322cc8
callq 0xaf86f
movl 0x10(%rbp), %eax
movl 0x14(%rbp), %edx
imulq %rax, %rdx
leaq 0x182(%rip), %rsi       # 0xeb27d
movq %rbp, %rdi
callq 0xf04b4
movq 0x8(%r14), %rcx
movq %rax, 0x18(%rcx)
movl 0x28(%rbp), %eax
movl %eax, 0x48(%rcx)
movq %rbp, %rdi
callq 0xeb294
movq %r14, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x34ce36(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1f9ed7(%rip), %rsi    # 0x2e5013
leaq 0x237aee(%rip), %rdx    # 0x322c31
leaq 0x237ad4(%rip), %rcx    # 0x322c1e
leaq 0x237907(%rip), %r8     # 0x322a58
movl $0x460, %r9d            # imm = 0x460
jmp 0xeb185
movq 0x34ce08(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1f9ea9(%rip), %rsi    # 0x2e5013
leaq 0x1fa04e(%rip), %rdx    # 0x2e51bf
leaq 0x237aa6(%rip), %rcx    # 0x322c1e
leaq 0x2378d9(%rip), %r8     # 0x322a58
movl $0x45f, %r9d            # imm = 0x45F
xorl %eax, %eax
callq 0x17a50
callq 0x17390