// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r13
movq (%rdx), %rbp
movl $0x8, %edi
callq 0xd46fc
movq %rax, %rbx
testq %r12, %r12
je 0x15539e
movq %r12, %rdi
callq 0x101a9a
testb %al, %al
jne 0x15567f
testq %r13, %r13
je 0x15567a
testq %r14, %r14
je 0x15567a
movq %rbx, 0x8(%r15)
leaq 0x353(%rip), %rsi       # 0x15570e
movq %r14, %rdi
movq %r15, 0x30(%rsp)
movq %r15, %rdx
movq %r12, %rcx
callq 0x105afd
testl %eax, %eax
je 0x1553da
movl %eax, %r15d
jmp 0x15552b
movq %r12, 0x8(%rsp)
movq %rbx, %rdi
callq 0xd4a9a
testq %rax, %rax
je 0x155684
movq %rbx, %rdi
xorl %esi, %esi
callq 0xd47ba
movq (%rax), %r12
movq %r12, %rdi
callq 0x14b8df
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %r12, %rdi
callq 0x14970e
movl %eax, %r14d
movq %r12, %rdi
callq 0x14b89b
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
callq 0xd4a9a
cmpq $0x2, %rax
jb 0x155528
movq %r13, 0x28(%rsp)
movq %rbp, (%rsp)
movl $0x1, %r13d
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd47ba
movq (%rax), %rbp
movq %rbp, %rdi
callq 0x14b8df
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x117923
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %rbp, %rdi
callq 0x14970e
movl %eax, %r12d
cmpl %r14d, %eax
jne 0x1554a4
movl %r14d, %edi
movl %r12d, %esi
callq 0x121f50
movl %eax, %r14d
jmp 0x1554e7
movq %rbp, %rdi
leaq 0x2561a0(%rip), %rsi    # 0x3ab64e
callq 0x14918c
movl %r12d, %eax
leaq 0x2217c7(%rip), %rcx    # 0x376c84
movsbl (%rax,%rcx), %edx
movl %r14d, %eax
movsbl (%rax,%rcx), %r8d
movq 0x8(%rsp), %rdi
leaq 0x236183(%rip), %rsi    # 0x38b658
movq 0x28(%rsp), %rcx
xorl %eax, %eax
callq 0x1019cf
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %r15d, %r15d
jne 0x155509
movq %rbp, %rdi
callq 0x14b89b
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x120dc8
testl %eax, %eax
jne 0x155675
incq %r13
movq %rbx, %rdi
callq 0xd4a9a
cmpq %rax, %r13
jb 0x15544b
movq (%rsp), %rbp
movq 0x28(%rsp), %r13
jmp 0x15552b
xorl %r15d, %r15d
testl %r15d, %r15d
je 0x15556c
movq %rbx, %rdi
callq 0xd4a9a
testq %rax, %rax
je 0x15565b
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd47ba
movq (%rax), %rdi
callq 0x14c43a
incq %r14
movq %rbx, %rdi
callq 0xd4a9a
cmpq %rax, %r14
jb 0x155544
jmp 0x15565b
movq %r15, 0x8(%rsp)
movq %rbp, (%rsp)
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
leaq 0x2918c5(%rip), %rsi    # 0x3e6e4b
movq 0x20(%rsp), %rdi
movl %r14d, %r8d
callq 0x14952c
movq %rax, %r14
leaq 0x28e7cf(%rip), %rsi    # 0x3e3d6c
movq %rax, %rdi
movq %r13, %rdx
callq 0x14a4d2
leaq 0x235f98(%rip), %rsi    # 0x38b547
movq %r14, %rdi
movq %r13, %rdx
callq 0x14a4d2
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
movq %r13, %rbp
movq %r13, %rsi
callq 0x105a11
testq %rax, %rax
je 0x1555ea
cmpb $0x0, (%rax)
je 0x1555ea
leaq 0x25606f(%rip), %rsi    # 0x3ab64e
movq %r14, %rdi
movq %rax, %rdx
callq 0x14a4d2
movq %rbx, %rdi
callq 0xd4a9a
testq %rax, %rax
je 0x15564a
xorl %r13d, %r13d
leaq 0x235f46(%rip), %r12    # 0x38b547
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd47ba
movq (%rax), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x149997
movq %r15, %rdi
leaq 0x234938(%rip), %rsi    # 0x389f5c
movq %rbp, %rdx
callq 0x14a4d2
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x14a4d2
incq %r13
movq %rbx, %rdi
callq 0xd4a9a
cmpq %rax, %r13
jb 0x155601
movq (%rsp), %rdi
movq %r14, %rsi
callq 0x112923
movq 0x8(%rsp), %r15
movq %rbx, %rdi
callq 0xd4ef4
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x47aa6
callq 0x47a6d
callq 0x47a34
callq 0x47adf