// File: /workspace/github_c_makefile_star2_O3/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
testq %rdi, %rdi
je 0x170941
movq %rsi, %r13
testq %rsi, %rsi
je 0x170946
movq %rdx, %rbp
movq %rdi, %r15
testq %rdx, %rdx
je 0x17075e
movq %rbp, %rdi
callq 0xfcc32
testb %al, %al
jne 0x17094b
leaq 0x221291(%rip), %rsi    # 0x3919f6
movl $0x18, %edi
movl $0x28, %edx
callq 0x104226
movq %rax, %rbx
movq %r13, %rdi
callq 0xe7bac
movq %rax, 0x10(%rbx)
movq $0x0, 0x8(%rbx)
movq %r13, (%rbx)
movq %r15, %rdi
callq 0x170bdd
cltq
cmpq %rax, 0x10(%rbx)
jne 0x170863
leaq -0x6c0ff(%rip), %rdx    # 0x1046aa
movl $0x1, %edi
movq %rdx, %rsi
callq 0x1008fc
movq %rax, %r12
cmpq $0x0, 0x10(%rbx)
je 0x170879
movq %rbp, 0x8(%rsp)
xorl %ebp, %ebp
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
movq %rbp, %rdx
callq 0xec19e
movq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0xe42d3
movq %rax, %r14
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x17080d
xorl %ecx, %ecx
cmpb $0x20, (%r14,%rcx)
je 0x170808
incq %rcx
cmpq %rcx, %rax
jne 0x1707f7
jmp 0x17080d
movb $0x0, (%r14,%rcx)
movq %r12, %rdi
movq %r14, %rsi
callq 0x100add
testq %rax, %rax
jne 0x1708d8
movl $0x8, %edi
leaq 0x2211c9(%rip), %rsi    # 0x3919f6
movl $0x50, %edx
callq 0x104226
movq %rbp, (%rax)
movq %r12, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x100b18
incq %rbp
movq 0x10(%rbx), %rdi
cmpq %rdi, %rbp
jb 0x1707cb
shlq $0x3, %rdi
movq 0x8(%rsp), %rbp
jmp 0x17087b
leaq 0x2211b2(%rip), %rsi    # 0x391a1c
movq %rbp, %rdi
xorl %eax, %eax
callq 0xfcb67
jmp 0x170905
xorl %edi, %edi
leaq 0x221174(%rip), %rsi    # 0x3919f6
movl $0x59, %edx
callq 0x104226
movq %rax, 0x8(%rbx)
cmpl $0x0, 0x10(%rbx)
jle 0x1708ce
xorl %r14d, %r14d
movq %r15, %rdi
movl %r14d, %esi
callq 0x170bb6
movq %rax, %r13
movq %r12, %rdi
movq %rax, %rsi
callq 0x100add
testq %rax, %rax
je 0x1708e9
movq (%rax), %rax
movq 0x8(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
movslq 0x10(%rbx), %rax
cmpq %rax, %r14
jl 0x170899
movq %r12, %rdi
callq 0x10109b
jmp 0x17092f
leaq 0x2211aa(%rip), %rsi    # 0x391a89
movq 0x8(%rsp), %rdi
movq %r14, %rdx
jmp 0x1708f6
leaq 0x2211c3(%rip), %rsi    # 0x391ab3
movq %rbp, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xfcb67
movq %r12, %rdi
callq 0x10109b
movq 0x8(%rbx), %rdi
leaq 0x2210e6(%rip), %r14    # 0x3919f6
movq %r14, %rsi
movl $0x8b, %edx
callq 0x1045eb
movq %rbx, %rdi
movq %r14, %rsi
movl $0x8c, %edx
callq 0x1045eb
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x52ba6
callq 0x52b6f
callq 0x52b38