// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/anno_db_gfflike.c
// Function: get_nodes_for_stmt
static int get_nodes_for_stmt(GtFeatureIndexGFFlike *fi,
                              GtArray *results,
                              GtRDBStmt *stmt,
                              GtError *err)
{
  GtRDBStmt *attr_stmt, *parent_stmt;
  int had_err = 0;
  GtUword i;
  GtArray *nodes;
  bool is_child;
  gt_assert(fi && results && stmt);
  attr_stmt = fi->stmts[GT_PSTMT_GET_ATTRIBUTE_SELECT];
  parent_stmt = fi->stmts[GT_PSTMT_GET_PARENTS_SELECT];
  nodes = gt_array_new(sizeof (GtUword));
  HashElemInfo node_hashtype = {
    gt_ht_ptr_elem_hash,
    { NULL },
    sizeof (GtGenomeNode*),
    gt_ht_ptr_elem_cmp,
    NULL,
    NULL };
  GtHashtable *seen_as_children = gt_hashtable_new(node_hashtype);

  while (!had_err && gt_rdb_stmt_exec(stmt, err) == 0) {
    GtUword id = GT_UNDEF_UWORD, multi_rep = GT_UNDEF_UWORD, *idp;
    int phase, is_multi = 0, strand = GT_STRAND_UNKNOWN;
    GtGenomeNode *newgn;
    GtFeatureNode *newfn;
    GtStr *seqid_str, *source_str, *type_str;
    double score;
    GtRange rng;

    seqid_str = gt_str_new();
    source_str = gt_str_new();
    type_str = gt_str_new();

    gt_rdb_stmt_get_ulong(stmt, 0, &id, err);
    gt_rdb_stmt_get_string(stmt, 1, seqid_str, err);
    gt_rdb_stmt_get_string(stmt, 2, source_str, err);
    gt_rdb_stmt_get_string(stmt, 3, type_str, err);
    gt_rdb_stmt_get_ulong(stmt, 4, &rng.start, err);
    gt_rdb_stmt_get_ulong(stmt, 5, &rng.end, err);
    gt_rdb_stmt_get_double(stmt, 6, &score, err);
    gt_rdb_stmt_get_int(stmt, 7, &strand, err);
    gt_rdb_stmt_get_int(stmt, 8, &phase, err);
    gt_rdb_stmt_get_int(stmt, 9, &is_multi, err);
    if (is_multi)
      gt_rdb_stmt_get_ulong(stmt, 10, &multi_rep, err);

    /* did we hand out or store this node already? -> reuse reference */
    if ((ul_node_gt_hashmap_get(fi->cache_id2node, id)) != NULL) {

      gt_array_add(nodes, id);

    } else {     /* otherwise build new nodes from database info */

      /* create new node */
      newgn = gt_feature_node_new(seqid_str, gt_str_get(type_str), rng.start,
                                  rng.end,strand);
      newfn = gt_feature_node_cast(newgn);
      gt_feature_node_set_phase(newfn, phase);
      gt_feature_node_set_source(newfn, source_str);
      if (score != GT_UNDEF_DOUBLE)
        gt_feature_node_set_score(newfn, score);

      /* cache node */
      ul_node_gt_hashmap_add(fi->cache_id2node, id, newfn);
      if (!(idp = node_ul_gt_hashmap_get(fi->cache_node2id, newfn)))
      {
        node_ul_gt_hashmap_add(fi->cache_node2id, newfn, id);
      }

      /* assign attributes */
      gt_rdb_stmt_reset(attr_stmt, err);
      gt_rdb_stmt_bind_ulong(attr_stmt, 0, id, err);
      while (gt_rdb_stmt_exec(attr_stmt, err) == 0) {
        GtStr *key, *value;
        key = gt_str_new();
        value = gt_str_new();
        gt_rdb_stmt_get_string(attr_stmt, 0, key, err);
        gt_rdb_stmt_get_string(attr_stmt, 1, value, err);
        gt_feature_node_set_attribute(newfn, gt_str_get(key),
                                      gt_str_get(value));
        gt_str_delete(key);
        gt_str_delete(value);
      }

      /* is this a multi-feature? */
      if (is_multi) {
        if (multi_rep == 0UL) {
          gt_feature_node_make_multi_representative(newfn);
        } else {
          GtFeatureNode *rep;
          rep = *(GtFeatureNode**) ul_node_gt_hashmap_get(fi->cache_id2node,
                                                          multi_rep);
          gt_assert(rep);
          gt_feature_node_set_multi_representative(newfn, rep);
        }
      }
      gt_array_add(nodes, id);
    }
    gt_str_delete(seqid_str);
    gt_str_delete(source_str);
    gt_str_delete(type_str);
  }

  /* rebuild DAG */
  for (i=0;i<gt_array_size(nodes);i++) {
    GtUword id = *(GtUword*) gt_array_get(nodes, i);
    is_child = false;
    GtFeatureNode *newfn = *(GtFeatureNode**)
                                  ul_node_gt_hashmap_get(fi->cache_id2node, id);
    gt_assert(newfn);
    /* assign parents */
    gt_rdb_stmt_reset(parent_stmt, err);
    gt_rdb_stmt_bind_ulong(parent_stmt, 0, id, err);
    while (gt_rdb_stmt_exec(parent_stmt, err) == 0) {
      GtUword par_id;
      GtFeatureNode *parent;
      is_child = true;
      gt_rdb_stmt_get_ulong(parent_stmt, 0, &par_id, err);
      parent = *(GtFeatureNode**) ul_node_gt_hashmap_get(fi->cache_id2node,
                                                       par_id);
      gt_assert(parent);
      /* if a child has multiple parents, increase refcount */
      if (gt_hashtable_get(seen_as_children, &newfn)) {
        gt_genome_node_ref((GtGenomeNode*) newfn);
      }
      gt_feature_node_add_child(parent, newfn);
      gt_hashtable_add(seen_as_children, &newfn);
    }
    if (!is_child) {
      GtGenomeNode *newgn = (GtGenomeNode*) newfn;
      gt_array_add(results, newgn);
    }
  }
  for (i=0;i<gt_array_size(nodes);i++) {
    GtUword id = *(GtUword*) gt_array_get(nodes, i);
    GtFeatureNode *newfn = *(GtFeatureNode**)
                                  ul_node_gt_hashmap_get(fi->cache_id2node, id);
    gt_feature_node_set_observer(newfn, fi->obs);
  }
  gt_array_delete(nodes);
  gt_hashtable_delete(seen_as_children);
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, 0x80(%rsp)
movq %rdi, 0x40(%rsp)
testq %rdi, %rdi
je 0xb7dff
cmpq $0x0, 0x80(%rsp)
je 0xb7dff
testq %rdx, %rdx
je 0xb7dff
movq %rcx, %r12
movq %rdx, 0xa8(%rsp)
movq 0x40(%rsp), %rax
movq 0xd0(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0xd8(%rax), %rbp
pushq $0x8
popq %rdi
callq 0x5809c
movq %rax, %r13
movups 0x37b47c(%rip), %xmm0   # 0x432d00
movups %xmm0, 0x20(%rsp)
movups 0x37b460(%rip), %xmm0   # 0x432cf0
movups %xmm0, 0x10(%rsp)
movups 0x37b444(%rip), %xmm0   # 0x432ce0
movups %xmm0, (%rsp)
callq 0x8fac7
movq %rax, %r15
movq %r13, 0x50(%rsp)
movq 0xa8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x10d688
testl %eax, %eax
jne 0xb7bee
orq $-0x1, 0x38(%rsp)
orq $-0x1, 0xa0(%rsp)
andl $0x0, 0x48(%rsp)
movl $0x3, 0x4c(%rsp)
callq 0xacb84
movq %rax, %r13
callq 0xacb84
movq %rax, %rbx
callq 0xacb84
movq %rax, 0x98(%rsp)
movq %r14, %rdi
xorl %esi, %esi
leaq 0x38(%rsp), %rdx
movq %r12, %rcx
callq 0x10d74a
movq %r14, %rdi
pushq $0x1
popq %rsi
movq %r13, 0x90(%rsp)
movq %r13, %rdx
movq %r12, %rcx
callq 0x10d7fc
movq %r14, %rdi
pushq $0x2
popq %rsi
movq %rbx, 0x88(%rsp)
movq %rbx, %rdx
movq 0x98(%rsp), %rbx
movq %r12, %rcx
callq 0x10d7fc
movq %r14, %rdi
pushq $0x3
popq %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x10d7fc
movq %r14, %rdi
pushq $0x4
popq %rsi
leaq 0x60(%rsp), %rdx
movq %r12, %rcx
callq 0x10d74a
movq %r14, %rdi
pushq $0x5
popq %rsi
leaq 0x68(%rsp), %rdx
movq %r12, %rcx
callq 0x10d74a
movq %r14, %rdi
pushq $0x6
popq %rsi
leaq 0xb0(%rsp), %rdx
movq %r12, %rcx
callq 0x10d855
movq %r14, %rdi
pushq $0x7
popq %rsi
leaq 0x4c(%rsp), %rdx
movq %r12, %rcx
callq 0x10d7a3
movq %r14, %rdi
pushq $0x8
popq %rsi
leaq 0x7c(%rsp), %rdx
movq %r12, %rcx
callq 0x10d7a3
movq %r14, %rdi
pushq $0x9
popq %rsi
leaq 0x48(%rsp), %rdx
movq %r12, %rcx
callq 0x10d7a3
cmpl $0x0, 0x48(%rsp)
je 0xb79f0
movq %r14, %rdi
pushq $0xa
popq %rsi
leaq 0xa0(%rsp), %rdx
movq %r12, %rcx
callq 0x10d74a
movq 0x40(%rsp), %rax
movq 0x58(%rax), %rdi
movq 0x38(%rsp), %rsi
callq 0xb9d0c
testq %rax, %rax
movq 0x58(%rsp), %r14
movq 0x50(%rsp), %r13
je 0xb7a49
movq %r13, %rdi
leaq 0x38(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x5851d
movq 0x90(%rsp), %rdi
callq 0xae103
movq 0x88(%rsp), %rdi
callq 0xae103
movq %rbx, %rdi
callq 0xae103
jmp 0xb78ad
movq %rbx, %rdi
callq 0xad1fa
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movl 0x4c(%rsp), %r8d
movq 0x90(%rsp), %rdi
movq %rax, %rsi
callq 0xd9acb
movq %rax, %rdi
callq 0xd9c07
movq %rax, %r13
movl 0x7c(%rsp), %esi
movq %rax, %rdi
callq 0xd9754
movq %r13, %rdi
movq 0x88(%rsp), %rsi
callq 0xd96be
movsd 0xb0(%rsp), %xmm0
ucomisd 0x230268(%rip), %xmm0   # 0x2e7d10
jne 0xb7aac
jnp 0xb7ab8
cvtsd2ss %xmm0, %xmm0
movq %r13, %rdi
callq 0xda425
movq 0x40(%rsp), %rbx
movq 0x58(%rbx), %rdi
movq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0xb9cd8
movq 0x50(%rbx), %rdi
movq %r13, %rsi
callq 0xb9ac3
testq %rax, %rax
jne 0xb7af5
movq 0x40(%rsp), %rax
movq 0x50(%rax), %rdi
movq 0x38(%rsp), %rdx
movq %r13, %rsi
callq 0xb9ca4
movq %r13, 0x70(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x10d4e4
movq 0x38(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x10d58c
movq %r14, %rdi
movq %r12, %rsi
callq 0x10d688
testl %eax, %eax
jne 0xb7b91
callq 0xacb84
movq %rax, %rbx
callq 0xacb84
movq %rax, %r13
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x10d7fc
movq %r14, %rdi
pushq $0x1
popq %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x10d7fc
movq %rbx, %rdi
callq 0xad1fa
movq %rax, %r14
movq %r13, %rdi
callq 0xad1fa
movq 0x70(%rsp), %rdi
movq %r14, %rsi
movq 0x58(%rsp), %r14
movq %rax, %rdx
callq 0xda48b
movq %rbx, %rdi
callq 0xae103
movq %r13, %rdi
callq 0xae103
jmp 0xb7b17
cmpl $0x0, 0x48(%rsp)
movq 0x50(%rsp), %r13
movq 0x98(%rsp), %rbx
je 0xb7a12
movq 0xa0(%rsp), %rsi
testq %rsi, %rsi
je 0xb7bdf
movq 0x40(%rsp), %rax
movq 0x58(%rax), %rdi
callq 0xb9d0c
movq (%rax), %rsi
testq %rsi, %rsi
je 0xb7dd1
movq 0x70(%rsp), %rdi
callq 0xda87c
jmp 0xb7a12
movq 0x70(%rsp), %rdi
callq 0xda7eb
jmp 0xb7a12
xorl %ebx, %ebx
leaq 0x60(%rsp), %r14
movq %r13, %rdi
callq 0x586a4
cmpq %rax, %rbx
jae 0xb7d07
movq %r13, %rdi
movq %rbx, 0x58(%rsp)
movq %rbx, %rsi
callq 0x581aa
movq (%rax), %rbx
movq 0x40(%rsp), %rax
movq 0x58(%rax), %rdi
movq %rbx, %rsi
callq 0xb9d0c
movq (%rax), %rax
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0xb7da3
movq %rbp, %rdi
movq %r12, %rsi
callq 0x10d4e4
xorl %r13d, %r13d
movq %rbp, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x10d58c
movq %rbp, %rdi
movq %r12, %rsi
callq 0x10d688
testl %eax, %eax
jne 0xb7cd0
movq %rbp, %rdi
xorl %esi, %esi
leaq 0x38(%rsp), %rdx
movq %r12, %rcx
callq 0x10d74a
movq 0x40(%rsp), %rax
movq 0x58(%rax), %rdi
movq 0x38(%rsp), %rsi
callq 0xb9d0c
movq (%rax), %rbx
testq %rbx, %rbx
je 0xb7d6b
movq %r15, %rdi
movq %r14, %rsi
callq 0x8fb4d
testq %rax, %rax
je 0xb7cb3
movq 0x60(%rsp), %rdi
callq 0xdccf8
movq 0x60(%rsp), %rsi
movq %rbx, %rdi
callq 0xda055
movq %r15, %rdi
movq %r14, %rsi
callq 0x8fc0c
movb $0x1, %r13b
jmp 0xb7c59
testb $0x1, %r13b
jne 0xb7cf5
movq 0x60(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x80(%rsp), %rdi
leaq 0x38(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x5851d
movq 0x58(%rsp), %rbx
incq %rbx
movq 0x50(%rsp), %r13
jmp 0xb7bf5
xorl %r14d, %r14d
movq 0x40(%rsp), %rbx
movq %r13, %rdi
callq 0x586a4
movq %r13, %rdi
cmpq %rax, %r14
jae 0xb7d4c
movq %r14, %rsi
callq 0x581aa
movq (%rax), %rsi
movq 0x58(%rbx), %rdi
callq 0xb9d0c
movq (%rax), %rdi
movq 0x160(%rbx), %rsi
movq 0x50(%rsp), %r13
callq 0xd97c0
incq %r14
jmp 0xb7d0f
callq 0x58eb9
movq %r15, %rdi
callq 0x9082d
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3801f6(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x22d297(%rip), %rsi    # 0x2e5013
leaq 0x285e0f(%rip), %rdx    # 0x33db92
leaq 0x25e9a9(%rip), %rcx    # 0x316733
leaq 0x25d785(%rip), %r8     # 0x315516
movl $0x58c, %r9d            # imm = 0x58C
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x3801be(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x22d25f(%rip), %rsi    # 0x2e5013
leaq 0x25e98b(%rip), %rdx    # 0x316746
leaq 0x25e971(%rip), %rcx    # 0x316733
leaq 0x25d74d(%rip), %r8     # 0x315516
movl $0x581, %r9d            # imm = 0x581
jmp 0xb7d97
movq 0x380190(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x22d231(%rip), %rsi    # 0x2e5013
leaq 0x26d3ef(%rip), %rdx    # 0x3251d8
leaq 0x25e943(%rip), %rcx    # 0x316733
leaq 0x25d71f(%rip), %r8     # 0x315516
movl $0x570, %r9d            # imm = 0x570
jmp 0xb7d97
movq 0x380162(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x22d203(%rip), %rsi    # 0x2e5013
leaq 0x25e906(%rip), %rdx    # 0x31671d
leaq 0x25e915(%rip), %rcx    # 0x316733
leaq 0x25d6f1(%rip), %r8     # 0x315516
movl $0x51b, %r9d            # imm = 0x51B
jmp 0xb7d97