// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/gtf_parser.c
// Function: construct_genes
static int construct_genes(GT_UNUSED void *key, void *value, void *data,
                           GtError *err)
{
  GtHashmap *transcript_id_hash = (GtHashmap*) value;
  ConstructionInfo *cinfo = (ConstructionInfo*) data;
  GtQueue *genome_nodes = cinfo->genome_nodes;
  const char *gname;
  GtArray *mRNAs = gt_array_new(sizeof (GtGenomeNode*));
  GtGenomeNode *gene_node, *gn;
  GtStrand gene_strand;
  GtRange gene_range;
  GtStr *gene_seqid;
  GtUword i;
  int had_err = 0;

  gt_error_check(err);
  gt_assert(key && value && data);
  cinfo->mRNAs = mRNAs;
  had_err = gt_hashmap_foreach(transcript_id_hash, construct_mRNAs, cinfo, err);
  if (!had_err) {
    gt_assert(gt_array_size(mRNAs)); /* at least one mRNA constructed */

    /* determine the range and the strand of the gene */
    gn = *(GtGenomeNode**) gt_array_get(mRNAs, 0);
    gene_range = gt_genome_node_get_range(gn);
    gene_strand = gt_feature_node_get_strand((GtFeatureNode*) gn);
    gene_seqid = gt_genome_node_get_seqid(gn);
    for (i = 1; i < gt_array_size(mRNAs); i++) {
      GtRange range;
      GtStrand strand;
      gn = *(GtGenomeNode**) gt_array_get(mRNAs, i);
      range = gt_genome_node_get_range(gn);
      gene_range = gt_range_join(&gene_range, &range);
      strand = gt_feature_node_get_strand((GtFeatureNode*) gn);
      if (strand != gene_strand) {
        GT_UNUSED const char *transcript_name =
                gt_feature_node_get_attribute((GtFeatureNode*) gn, GT_GFF_NAME);
        gt_error_set(err, "transcript on strand %c encountered, but the "
                          "parent gene %s has strand %c",
                     GT_STRAND_CHARS[strand],
                     (const char*) key,
                     GT_STRAND_CHARS[gene_strand]);
        had_err = -1;
      } else {
        gene_strand = gt_strand_join(gene_strand, strand);
      }
      gt_assert(had_err || gt_str_cmp(gene_seqid,
                                      gt_genome_node_get_seqid(gn)) == 0);
    }
  }

  if (!had_err) {
    gene_node = gt_feature_node_new(gene_seqid, gt_ft_gene, gene_range.start,
                                    gene_range.end, gene_strand);
    gt_feature_node_add_attribute((GtFeatureNode*) gene_node, "ID", key);
    gt_feature_node_add_attribute((GtFeatureNode*) gene_node, "gene_id", key);

    if ((gname = gt_hashmap_get(cinfo->gene_id_to_name_mapping,
                              (const char*) key)) && strlen(gname) > 0) {
      gt_feature_node_add_attribute((GtFeatureNode*) gene_node, GT_GFF_NAME,
                                      gname);
    }

    /* register children */
    for (i = 0; i < gt_array_size(mRNAs); i++) {
      gn = *(GtGenomeNode**) gt_array_get(mRNAs, i);
      gt_feature_node_add_child((GtFeatureNode*) gene_node,
                                (GtFeatureNode*) gn);
      gt_feature_node_add_attribute((GtFeatureNode*) gn, "Parent", key);
      gt_feature_node_add_attribute((GtFeatureNode*) gn, "gene_id", key);
    }

    /* store the gene */
    gt_queue_add(genome_nodes, gene_node);
  } else {
    for (i = 0; i < gt_array_size(mRNAs); i++) {
      gt_genome_node_delete(*(GtGenomeNode**) gt_array_get(mRNAs, i));
    }
  }

  /* free */
  gt_array_delete(mRNAs);

  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %rbp
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r12
movq (%rdx), %r15
movl $0x8, %edi
callq 0xd214c
movq %rax, %rbx
testq %rbp, %rbp
je 0x14dc1e
movq %rbp, %rdi
callq 0xfcc32
testb %al, %al
jne 0x14dee3
testq %r12, %r12
je 0x14dede
testq %r14, %r14
je 0x14dede
movq %rbx, 0x8(%r13)
leaq 0x337(%rip), %rsi       # 0x14df72
movq %r14, %rdi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x100bc9
movl %eax, %r14d
testl %eax, %eax
je 0x14dc8c
movq %rbx, %rdi
callq 0xd24e0
testq %rax, %rax
je 0x14debf
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd2207
movq (%rax), %rdi
callq 0x1451a0
incq %r15
movq %rbx, %rdi
callq 0xd24e0
cmpq %rax, %r15
jb 0x14dc64
jmp 0x14debf
movq %rbp, 0x30(%rsp)
movq %rbx, %rdi
callq 0xd24e0
testq %rax, %rax
je 0x14dee8
movq %rbx, %rdi
xorl %esi, %esi
callq 0xd2207
movq (%rax), %r14
movq %r14, %rdi
callq 0x144679
movq %rax, (%rsp)
movq %rdx, 0x8(%rsp)
movq %r14, %rdi
callq 0x1424d6
movl %eax, %ebp
movq %r14, %rdi
callq 0x144635
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0xd24e0
cmpq $0x2, %rax
movq %r15, 0x28(%rsp)
jb 0x14dde0
movq %r13, 0x20(%rsp)
movq %r12, 0x18(%rsp)
movl $0x1, %r12d
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r12, %rsi
callq 0xd2207
movq (%rax), %r13
movq %r13, %rdi
callq 0x144679
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq %rsp, %rdi
leaq 0x38(%rsp), %rsi
callq 0x112343
movq %rax, (%rsp)
movq %rdx, 0x8(%rsp)
movq %r13, %rdi
callq 0x1424d6
cmpl %ebp, %eax
jne 0x14dd74
movl %ebp, %edi
movl %ebp, %esi
callq 0x11c208
movl %eax, %ebp
testl %r14d, %r14d
jne 0x14ddb9
movq %r13, %rdi
callq 0x144635
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x11b146
xorl %r14d, %r14d
testl %eax, %eax
je 0x14ddb9
jmp 0x14ded9
movl %eax, %r15d
movq %r13, %rdi
leaq 0x25436d(%rip), %rsi    # 0x3a20ee
callq 0x141f50
movl %r15d, %eax
leaq 0x21fca4(%rip), %rcx    # 0x36da34
movsbl (%rax,%rcx), %edx
movl %ebp, %eax
movsbl (%rax,%rcx), %r8d
movq 0x30(%rsp), %rdi
leaq 0x2344ee(%rip), %rsi    # 0x382295
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0xfcb67
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
incq %r12
movq %rbx, %rdi
callq 0xd24e0
cmpq %rax, %r12
jb 0x14dd01
testl %r14d, %r14d
movq 0x18(%rsp), %r12
movq 0x20(%rsp), %r13
jne 0x14dc50
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
leaq 0x28f95b(%rip), %rsi    # 0x3dd74b
movq 0x10(%rsp), %rdi
movl %ebp, %r8d
callq 0x1422f4
movq %rax, %r14
leaq 0x28c810(%rip), %rsi    # 0x3da617
movq %rax, %rdi
movq %r12, %rdx
callq 0x14329d
leaq 0x23436b(%rip), %rsi    # 0x382184
movq %r14, %rdi
movq %r12, %rdx
callq 0x14329d
movq 0x10(%r13), %rdi
movq %r12, %r13
movq %r12, %rsi
callq 0x100add
testq %rax, %rax
je 0x14de4f
cmpb $0x0, (%rax)
je 0x14de4f
leaq 0x2542aa(%rip), %rsi    # 0x3a20ee
movq %r14, %rdi
movq %rax, %rdx
callq 0x14329d
movq %rbx, %rdi
callq 0xd24e0
testq %rax, %rax
je 0x14deaf
xorl %r12d, %r12d
leaq 0x23431e(%rip), %rbp    # 0x382184
movq %rbx, %rdi
movq %r12, %rsi
callq 0xd2207
movq (%rax), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x14275f
movq %r15, %rdi
leaq 0x232d15(%rip), %rsi    # 0x380b9e
movq %r13, %rdx
callq 0x14329d
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x14329d
incq %r12
movq %rbx, %rdi
callq 0xd24e0
cmpq %rax, %r12
jb 0x14de66
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x10d65b
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0xd2938
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x46c6b
callq 0x46c32
callq 0x46bf9
callq 0x46ca4