// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/extended/samfile_encseq_mapping.c
// Function: gt_samfile_encseq_mapping_new
GtSamfileEncseqMapping *gt_samfile_encseq_mapping_new(
    /*const*/ GtSamfileIterator *samfile_iterator, const GtEncseq *encseq,
    GtError *err)
{
  GtSamfileEncseqMapping *samfile_encseq_mapping;
  bool haserr = false;
  gt_assert(samfile_iterator != NULL);
  gt_assert(encseq != NULL);
  gt_error_check(err);
  samfile_encseq_mapping = gt_malloc(sizeof (GtSamfileEncseqMapping));
  samfile_encseq_mapping->nof_sequences = gt_encseq_num_of_sequences(encseq);
  samfile_encseq_mapping->samfile2encseq = NULL;
  samfile_encseq_mapping->encseq = encseq;
  if ((GtUword)gt_samfile_iterator_number_of_references(samfile_iterator)
      != samfile_encseq_mapping->nof_sequences)
  {
    gt_error_set(err, "The number of sequences in the encoded sequence "
        "is not the same as the number of references in the SAM file.");
    haserr = true;
  }
  else
  {
    GtHashmap *seqid2seqnum;
    GtUword i, cnum, dlen, *stored, *seqnum;
    int32_t refnum;
    const char *d;
    char *seqid = NULL;
    seqid2seqnum = gt_hashmap_new(GT_HASH_STRING, gt_free_func, gt_free_func);
    for (i = 0; i < samfile_encseq_mapping->nof_sequences; i++)
    {

      d = gt_encseq_description(encseq, &dlen, i);
      seqid = gt_cstr_dup_nt(d, dlen);
      for (cnum = 0; cnum < dlen; cnum++)
      {
        if (seqid[cnum] == ' ')
        {
          seqid[cnum] = '\0';
          break;
        }
      }
      if ((stored = gt_hashmap_get(seqid2seqnum, seqid)) != NULL)
      {
        gt_error_set(err, "The encseq identifier '%s' is not unique!", seqid);
        haserr = true;
        break;
      }
      else
      {
        seqnum = gt_malloc(sizeof (GtUword));
        *seqnum = i;
        gt_hashmap_add(seqid2seqnum, seqid, seqnum);
      }
    }
    if (!haserr)
    {
      samfile_encseq_mapping->samfile2encseq = gt_malloc(
          sizeof (*samfile_encseq_mapping->samfile2encseq) *
          samfile_encseq_mapping->nof_sequences);
      for (refnum = 0; refnum < (int32_t)samfile_encseq_mapping->nof_sequences;
          refnum++)
      {
        d = gt_samfile_iterator_reference_name(samfile_iterator, refnum);
        if ((seqnum = gt_hashmap_get(seqid2seqnum, d)) == NULL)
        {
          gt_error_set(err,
              "The SAM identifier '%s' was not found in the encseq!", d);
          haserr = true;
          break;
        }
        samfile_encseq_mapping->samfile2encseq[refnum] = *seqnum;
      }
    }
    gt_hashmap_delete(seqid2seqnum);
  }
  if (haserr)
  {
    gt_samfile_encseq_mapping_delete(samfile_encseq_mapping);
    return NULL;
  }
  else
    return samfile_encseq_mapping;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, 0x8(%rsp)
testq %rdi, %rdi
je 0x178cf3
movq %rsi, %r13
testq %rsi, %rsi
je 0x178cf8
movq %rdx, %r14
testq %rdx, %rdx
je 0x178afc
movq %r14, %rdi
callq 0x101a9a
testb %al, %al
jne 0x178cfd
leaq 0x222313(%rip), %rsi    # 0x39ae16
movl $0x18, %edi
movl $0x28, %edx
callq 0x1092b2
movq %rax, %rbx
movq %r13, %rdi
callq 0xec1e8
movq %rax, 0x10(%rbx)
movq $0x0, 0x8(%rbx)
movq %r13, (%rbx)
movq 0x8(%rsp), %rdi
callq 0x178f8f
cltq
cmpq %rax, 0x10(%rbx)
jne 0x178bf7
leaq -0x6f41a(%rip), %rdx    # 0x10972f
movl $0x1, %edi
movq %rdx, %rsi
callq 0x105830
movq %rax, %r12
cmpq $0x0, 0x10(%rbx)
je 0x178c0d
movq %r14, (%rsp)
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0xf079f
movq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0xe87a3
movq %rax, %r15
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x178baf
xorl %ecx, %ecx
cmpb $0x20, (%r15,%rcx)
je 0x178baa
incq %rcx
cmpq %rcx, %rax
jne 0x178b99
jmp 0x178baf
movb $0x0, (%r15,%rcx)
movq %r12, %rdi
movq %r15, %rsi
callq 0x105a11
testq %rax, %rax
jne 0x178c11
movl $0x8, %edi
leaq 0x22224b(%rip), %rsi    # 0x39ae16
movl $0x50, %edx
callq 0x1092b2
movq %rbp, (%rax)
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x105a4c
incq %rbp
cmpq 0x10(%rbx), %rbp
jb 0x178b6f
xorl %ebp, %ebp
movq (%rsp), %r14
jmp 0x178c2c
leaq 0x22223e(%rip), %rsi    # 0x39ae3c
movq %r14, %rdi
xorl %eax, %eax
callq 0x1019cf
jmp 0x178cb7
xorl %ebp, %ebp
jmp 0x178c2c
leaq 0x222291(%rip), %rsi    # 0x39aea9
movq (%rsp), %r14
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1019cf
movb $0x1, %bpl
testb %bpl, %bpl
jne 0x178caa
movq 0x10(%rbx), %rdi
shlq $0x3, %rdi
leaq 0x2221d6(%rip), %rsi    # 0x39ae16
movl $0x59, %edx
callq 0x1092b2
movq %rax, 0x8(%rbx)
cmpl $0x0, 0x10(%rbx)
jle 0x178caa
movq %r14, %r13
xorl %r14d, %r14d
movq 0x8(%rsp), %rdi
movl %r14d, %esi
callq 0x178f68
movq %rax, %r15
movq %r12, %rdi
movq %rax, %rsi
callq 0x105a11
testq %rax, %rax
je 0x178c93
movq (%rax), %rax
movq 0x8(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
movslq 0x10(%rbx), %rax
cmpq %rax, %r14
jl 0x178c5a
jmp 0x178caa
leaq 0x222239(%rip), %rsi    # 0x39aed3
movq %r13, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1019cf
movb $0x1, %bpl
movq %r12, %rdi
callq 0x105f7d
testb %bpl, %bpl
je 0x178ce1
movq 0x8(%rbx), %rdi
leaq 0x222154(%rip), %r14    # 0x39ae16
movq %r14, %rsi
movl $0x8b, %edx
callq 0x109670
movq %rbx, %rdi
movq %r14, %rsi
movl $0x8c, %edx
callq 0x109670
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x53b0d
callq 0x53ad6
callq 0x53a9f