// File: /workspace/github_c_makefile_star2_O3/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 $0xd8, %rsp
movq %rsi, 0x98(%rsp)
testq %rdi, %rdi
je 0x123635
cmpq $0x0, 0x98(%rsp)
je 0x123635
movq %rdx, %r14
testq %rdx, %rdx
je 0x123635
movq %rcx, %r12
movq %rdi, %r15
movq 0xd0(%rdi), %rax
movq %rax, 0xb8(%rsp)
movq 0xd8(%rdi), %rbp
movl $0x8, %edi
callq 0xd214c
movq %rax, %rbx
movups 0x390c7d(%rip), %xmm0   # 0x4b3ce0
movups %xmm0, 0x20(%rsp)
movups 0x390c61(%rip), %xmm0   # 0x4b3cd0
movups %xmm0, 0x10(%rsp)
movups 0x390c45(%rip), %xmm0   # 0x4b3cc0
movups %xmm0, (%rsp)
callq 0x101194
movq %rax, 0xa0(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x16bfbe
testl %eax, %eax
movq %r15, 0x68(%rsp)
movq %rbx, 0xb0(%rsp)
je 0x123273
movq %rbx, %rdi
callq 0xd24e0
testq %rax, %rax
je 0x1231f6
xorl %r14d, %r14d
leaq 0x70(%rsp), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd2207
movq %r15, %rcx
movq (%rax), %r15
movq 0x58(%rcx), %rdi
movq %r15, 0x38(%rsp)
leaq 0x38(%rsp), %rsi
callq 0x1012ee
movq 0x8(%rax), %rax
movq %rax, 0x70(%rsp)
testq %rax, %rax
je 0x12362b
movq %rbp, %rdi
movq %r12, %rsi
callq 0x16bf19
movq %rbp, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
callq 0x16bf5b
movq %rbp, %rdi
movq %r12, %rsi
callq 0x16bfbe
testl %eax, %eax
movq 0xa0(%rsp), %rbx
je 0x123158
movq 0x70(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x8, %edx
movq 0x98(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xd2410
movq 0x68(%rsp), %r15
jmp 0x1231da
movq 0x68(%rsp), %r15
movq %rbp, %rdi
xorl %esi, %esi
leaq 0x58(%rsp), %rdx
movq %r12, %rcx
callq 0x16c01a
movq 0x58(%r15), %rdi
movq 0x58(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rsi
callq 0x1012ee
movq 0x8(%rax), %r15
testq %r15, %r15
je 0x123626
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1012ee
testq %rax, %rax
je 0x1231ae
movq 0x70(%rsp), %rdi
callq 0x1443a0
movq 0x70(%rsp), %rsi
movq %r15, %rdi
callq 0x14275f
movq %rbx, %rdi
movq %r13, %rsi
callq 0x10137a
movq %rbp, %rdi
movq %r12, %rsi
callq 0x16bfbe
testl %eax, %eax
movq 0x68(%rsp), %r15
je 0x12315d
incq %r14
movq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xd24e0
cmpq %rax, %r14
jb 0x1230c5
movq %rbx, %rdi
callq 0xd24e0
testq %rax, %rax
movq %rbx, %r12
je 0x12324c
xorl %ebx, %ebx
leaq 0x38(%rsp), %r14
movq %r12, %rdi
movq %rbx, %rsi
callq 0xd2207
movq (%rax), %rax
movq 0x58(%r15), %rdi
movq %rax, 0x38(%rsp)
movq %r14, %rsi
callq 0x1012ee
movq 0x8(%rax), %rdi
movq 0x160(%r15), %rsi
callq 0x142051
incq %rbx
movq %r12, %rdi
callq 0xd24e0
cmpq %rax, %rbx
jb 0x12320d
movq %r12, %rdi
callq 0xd2938
movq 0xa0(%rsp), %rdi
callq 0x101d90
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x50(%rsp), %r13
movq %r14, 0xc8(%rsp)
movq $-0x1, %rax
movq %rax, 0x50(%rsp)
movq %rax, 0xc0(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x3, 0x64(%rsp)
callq 0x11ac6c
movq %rax, %rbx
callq 0x11ac6c
movq %rax, 0x88(%rsp)
callq 0x11ac6c
movq %rax, 0x80(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %rcx
callq 0x16c01a
movl $0x1, %esi
movq %r14, %rdi
movq %rbx, 0xa8(%rsp)
movq %rbx, %rdx
movq %r12, %rcx
callq 0x16c066
movl $0x2, %esi
movq %r14, %rdi
movq 0x88(%rsp), %rdx
movq %r12, %rcx
callq 0x16c066
movl $0x3, %esi
movq %r14, %rdi
movq 0x80(%rsp), %rdx
movq %r12, %rcx
callq 0x16c066
movl $0x4, %esi
movq %r14, %rdi
leaq 0x70(%rsp), %rdx
movq %r12, %rcx
callq 0x16c01a
movl $0x5, %esi
movq %r14, %rdi
leaq 0x78(%rsp), %rdx
movq %r12, %rcx
callq 0x16c01a
movl $0x6, %esi
movq %r14, %rdi
leaq 0xd0(%rsp), %rdx
movq %r12, %rcx
callq 0x16c08c
movl $0x7, %esi
movq %r14, %rdi
leaq 0x64(%rsp), %rdx
movq %r12, %rcx
callq 0x16c040
movl $0x8, %esi
movq %r14, %rdi
leaq 0x94(%rsp), %rdx
movq %r12, %rcx
callq 0x16c040
movl $0x9, %esi
movq %r14, %rdi
leaq 0x4c(%rsp), %rdx
movq %r12, %rcx
callq 0x16c040
cmpl $0x0, 0x4c(%rsp)
je 0x1233c4
movl $0xa, %esi
movq %r14, %rdi
leaq 0xc0(%rsp), %rdx
movq %r12, %rcx
callq 0x16c01a
movq 0x58(%r15), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rbx
movq %rbx, %rsi
callq 0x1012ee
testq %rax, %rax
je 0x123440
movl $0x8, %edx
movq 0xb0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x50(%rsp), %r13
movq %r13, %rsi
callq 0xd2410
movq 0xa8(%rsp), %rdi
callq 0x11bdbf
movq 0x88(%rsp), %rdi
callq 0x11bdbf
movq 0x80(%rsp), %rdi
callq 0x11bdbf
movq %r14, %rdi
movq %r12, %rsi
callq 0x16bfbe
testl %eax, %eax
je 0x123280
jmp 0x1230ac
movq 0x80(%rsp), %rdi
callq 0x11b0a1
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
movl 0x64(%rsp), %r8d
movq 0xa8(%rsp), %rdi
movq %rax, %rsi
callq 0x1422f4
movq %rax, %rdi
callq 0x1423dd
movq %rax, %r13
movl 0x94(%rsp), %esi
movq %rax, %rdi
callq 0x142018
movq %r13, %rdi
movq 0x88(%rsp), %rsi
callq 0x141fb5
movsd 0xd0(%rsp), %xmm0
ucomisd 0x224869(%rip), %xmm0   # 0x347d10
jne 0x1234ab
jnp 0x1234b7
cvtsd2ss %xmm0, %xmm0
movq %r13, %rdi
callq 0x1429dc
movq 0x58(%r15), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r13, 0x40(%rsp)
movq %rbx, %rsi
leaq 0x58(%rsp), %rdx
callq 0x1015ee
testl %eax, %eax
jne 0x1234e4
movq 0x58(%rsp), %rax
movq %r13, 0x8(%rax)
movq 0x50(%r15), %rdi
movq %r13, 0x38(%rsp)
movq %rbx, %rsi
callq 0x1012ee
testq %rax, %rax
jne 0x123529
movq 0x50(%r15), %rdi
movq 0x50(%rsp), %rbx
movq %r13, 0x38(%rsp)
movq %rbx, 0x40(%rsp)
leaq 0x38(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x1015ee
testl %eax, %eax
jne 0x123529
movq 0x58(%rsp), %rax
movq %rbx, 0x8(%rax)
movq 0xb8(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x16bf19
movq 0x50(%rsp), %rdx
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x16bf5b
movq %r15, %rdi
movq %r12, %rsi
callq 0x16bfbe
testl %eax, %eax
jne 0x1235cb
callq 0x11ac6c
movq %rax, %rbx
callq 0x11ac6c
movq %rax, %r14
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x16c066
movl $0x1, %esi
movq %r15, %rdi
movq %r14, %rdx
movq %r12, %rcx
callq 0x16c066
movq %rbx, %rdi
callq 0x11b0a1
movq %rax, %r15
movq %r14, %rdi
callq 0x11b0a1
movq %r13, %rdi
movq %r15, %rsi
movq 0xb8(%rsp), %r15
movq %rax, %rdx
callq 0x142a0f
movq %rbx, %rdi
callq 0x11bdbf
movq %r14, %rdi
callq 0x11bdbf
jmp 0x12354e
cmpl $0x0, 0x4c(%rsp)
movq 0x68(%rsp), %r15
movq 0xc8(%rsp), %r14
leaq 0x38(%rsp), %rsi
je 0x1233e4
movq 0xc0(%rsp), %rax
testq %rax, %rax
je 0x123619
movq 0x58(%r15), %rdi
movq %rax, 0x38(%rsp)
callq 0x1012ee
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x123630
movq %r13, %rdi
callq 0x142bed
jmp 0x1233e4
movq %r13, %rdi
callq 0x142b8f
jmp 0x1233e4
callq 0x3a5dc
callq 0x3a615
callq 0x3a5a3
callq 0x3a56a