// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, (%rsp)
movq (%rdx), %r15
pushq $0x8
popq %rdi
callq 0x5809c
movq %rax, %rbx
testq %r13, %r13
je 0xe8a24
movq %r13, %rdi
callq 0x89eb7
testb %al, %al
jne 0xe8d0f
cmpq $0x0, (%rsp)
je 0xe8ce1
testq %r14, %r14
je 0xe8ce1
movq %rbx, 0x8(%r12)
leaq 0x412(%rip), %rsi       # 0xe8e56
movq %r14, %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x8f56e
movl %eax, %ebp
testl %eax, %eax
jne 0xe8b92
movq %r13, 0x30(%rsp)
movq %r12, 0x20(%rsp)
movq %r15, 0x28(%rsp)
movq %rbx, %rdi
callq 0x586a4
testq %rax, %rax
je 0xe8d3d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x581aa
movq (%rax), %r15
movq %r15, %rdi
callq 0xdd1f4
leaq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq %rdx, 0x8(%rcx)
movq %r15, %rdi
callq 0xd9d99
movl %eax, %r14d
movq %r15, %rdi
callq 0xdd14a
movq %rax, 0x8(%rsp)
pushq $0x1
popq %r12
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x586a4
cmpq %rax, %r12
jae 0xe8b8e
movq %rbx, %rdi
movq %r12, %rsi
callq 0x581aa
movq (%rax), %r13
movq %r13, %rdi
callq 0xdd1f4
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xa33f9
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %r13, %rdi
callq 0xd9d99
cmpl %r14d, %eax
jne 0xe8b44
movl %r14d, %edi
movl %r14d, %esi
callq 0xae73c
movl %eax, %r14d
testl %ebp, %ebp
jne 0xe8b86
movq %r13, %rdi
callq 0xdd14a
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0xad39b
xorl %ebp, %ebp
testl %eax, %eax
je 0xe8b86
jmp 0xe8cb0
movl %eax, %r15d
movq %r13, %rdi
leaq 0x25988d(%rip), %rsi    # 0x3423de
callq 0xd9628
movl %r15d, %eax
leaq 0x2251f4(%rip), %rcx    # 0x30dd54
movsbl (%rax,%rcx), %edx
movl %r14d, %eax
movsbl (%rax,%rcx), %r8d
movq 0x30(%rsp), %rdi
leaq 0x239b29(%rip), %rsi    # 0x3226a1
movq (%rsp), %rcx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x1
popq %rbp
incq %r12
jmp 0xe8abb
testl %ebp, %ebp
je 0xe8bbe
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x586a4
cmpq %rax, %r14
jae 0xe8c97
movq %rbx, %rdi
movq %r14, %rsi
callq 0x581aa
movq (%rax), %rdi
callq 0xde013
incq %r14
jmp 0xe8b95
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
leaq 0x294f4c(%rip), %rsi    # 0x37db1b
movq 0x8(%rsp), %rdi
movl %r14d, %r8d
callq 0xd9acb
movq %rax, %r14
leaq 0x291e51(%rip), %rsi    # 0x37aa37
movq %rax, %rdi
movq (%rsp), %r15
movq %r15, %rdx
callq 0xdb38d
leaq 0x239994(%rip), %rsi    # 0x322590
movq %r14, %rdi
movq %r15, %rdx
callq 0xdb38d
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdi
movq %r15, %rsi
callq 0x8f482
testq %rax, %rax
je 0xe8c34
cmpb $0x0, (%rax)
je 0xe8c34
leaq 0x2597b5(%rip), %rsi    # 0x3423de
movq %r14, %rdi
movq %rax, %rdx
callq 0xdb38d
xorl %r12d, %r12d
movq (%rsp), %r13
movq %rbx, %rdi
callq 0x586a4
cmpq %rax, %r12
jae 0xe8c8a
movq %rbx, %rdi
movq %r12, %rsi
callq 0x581aa
movq (%rax), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xda055
movq %r15, %rdi
leaq 0x238343(%rip), %rsi    # 0x320fae
movq %r13, %rdx
callq 0xdb38d
movq %r15, %rdi
leaq 0x239913(%rip), %rsi    # 0x322590
movq %r13, %rdx
callq 0xdb38d
incq %r12
jmp 0xe8c3b
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x9e2d1
movq %rbx, %rdi
callq 0x58eb9
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x34f2b1(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fc352(%rip), %rsi    # 0x2e5013
leaq 0x239a23(%rip), %rdx    # 0x3226eb
leaq 0x2399ad(%rip), %rcx    # 0x32267c
leaq 0x23974a(%rip), %r8     # 0x322420
movl $0x14b, %r9d            # imm = 0x14B
jmp 0xe8d69
movq 0x34f280(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fc321(%rip), %rsi    # 0x2e5013
leaq 0x221677(%rip), %rdx    # 0x30a370
leaq 0x23997c(%rip), %rcx    # 0x32267c
leaq 0x239719(%rip), %r8     # 0x322420
movl $0x12c, %r9d            # imm = 0x12C
jmp 0xe8d69
movq 0x34f252(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fc2f3(%rip), %rsi    # 0x2e5013
leaq 0x1fc498(%rip), %rdx    # 0x2e51bf
leaq 0x23994e(%rip), %rcx    # 0x32267c
leaq 0x2396eb(%rip), %r8     # 0x322420
movl $0x12b, %r9d            # imm = 0x12B
jmp 0xe8d69
movq 0x34f224(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1fc2c5(%rip), %rsi    # 0x2e5013
leaq 0x239937(%rip), %rdx    # 0x32268c
leaq 0x239920(%rip), %rcx    # 0x32267c
leaq 0x2396bd(%rip), %r8     # 0x322420
movl $0x130, %r9d            # imm = 0x130
xorl %eax, %eax
callq 0x17a50
callq 0x17390