// File: /workspace/github_c_makefile_star2_O1/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 0x129495
cmpq $0x0, 0x98(%rsp)
je 0x129495
movq %rdx, %r14
testq %rdx, %rdx
je 0x129495
movq %rcx, %r12
movq %rdi, %r15
movq 0xd0(%rdi), %rax
movq %rax, 0xb8(%rsp)
movq 0xd8(%rdi), %rbp
movl $0x8, %edi
callq 0xd46fc
movq %rax, %rbx
movups 0x395e2d(%rip), %xmm0   # 0x4becf0
movups %xmm0, 0x20(%rsp)
movups 0x395e11(%rip), %xmm0   # 0x4bece0
movups %xmm0, 0x10(%rsp)
movups 0x395df5(%rip), %xmm0   # 0x4becd0
movups %xmm0, (%rsp)
callq 0x1060b4
movq %rax, 0xa0(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x1741ce
testl %eax, %eax
movq %r15, 0x68(%rsp)
movq %rbx, 0xb0(%rsp)
je 0x1290d3
movq %rbx, %rdi
callq 0xd4a9a
testq %rax, %rax
je 0x129056
xorl %r14d, %r14d
leaq 0x70(%rsp), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd47ba
movq %r15, %rcx
movq (%rax), %r15
movq 0x58(%rcx), %rdi
movq %r15, 0x38(%rsp)
leaq 0x38(%rsp), %rsi
callq 0x10620e
movq 0x8(%rax), %rax
movq %rax, 0x70(%rsp)
testq %rax, %rax
je 0x12948b
movq %rbp, %rdi
movq %r12, %rsi
callq 0x174129
movq %rbp, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
callq 0x17416b
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1741ce
testl %eax, %eax
movq 0xa0(%rsp), %rbx
je 0x128fb8
movq 0x70(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x8, %edx
movq 0x98(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xd49ce
movq 0x68(%rsp), %r15
jmp 0x12903a
movq 0x68(%rsp), %r15
movq %rbp, %rdi
xorl %esi, %esi
leaq 0x58(%rsp), %rdx
movq %r12, %rcx
callq 0x17422a
movq 0x58(%r15), %rdi
movq 0x58(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rsi
callq 0x10620e
movq 0x8(%rax), %r15
testq %r15, %r15
je 0x129486
movq %rbx, %rdi
movq %r13, %rsi
callq 0x10620e
testq %rax, %rax
je 0x12900e
movq 0x70(%rsp), %rdi
callq 0x14b5fc
movq 0x70(%rsp), %rsi
movq %r15, %rdi
callq 0x149997
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1062a2
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1741ce
testl %eax, %eax
movq 0x68(%rsp), %r15
je 0x128fbd
incq %r14
movq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xd4a9a
cmpq %rax, %r14
jb 0x128f25
movq %rbx, %rdi
callq 0xd4a9a
testq %rax, %rax
movq %rbx, %r12
je 0x1290ac
xorl %ebx, %ebx
leaq 0x38(%rsp), %r14
movq %r12, %rdi
movq %rbx, %rsi
callq 0xd47ba
movq (%rax), %rax
movq 0x58(%r15), %rdi
movq %rax, 0x38(%rsp)
movq %r14, %rsi
callq 0x10620e
movq 0x8(%rax), %rdi
movq 0x160(%r15), %rsi
callq 0x14928d
incq %rbx
movq %r12, %rdi
callq 0xd4a9a
cmpq %rax, %rbx
jb 0x12906d
movq %r12, %rdi
callq 0xd4ef4
movq 0xa0(%rsp), %rdi
callq 0x106d10
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 0x1208f8
movq %rax, %rbx
callq 0x1208f8
movq %rax, 0x88(%rsp)
callq 0x1208f8
movq %rax, 0x80(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %rcx
callq 0x17422a
movl $0x1, %esi
movq %r14, %rdi
movq %rbx, 0xa8(%rsp)
movq %rbx, %rdx
movq %r12, %rcx
callq 0x174276
movl $0x2, %esi
movq %r14, %rdi
movq 0x88(%rsp), %rdx
movq %r12, %rcx
callq 0x174276
movl $0x3, %esi
movq %r14, %rdi
movq 0x80(%rsp), %rdx
movq %r12, %rcx
callq 0x174276
movl $0x4, %esi
movq %r14, %rdi
leaq 0x70(%rsp), %rdx
movq %r12, %rcx
callq 0x17422a
movl $0x5, %esi
movq %r14, %rdi
leaq 0x78(%rsp), %rdx
movq %r12, %rcx
callq 0x17422a
movl $0x6, %esi
movq %r14, %rdi
leaq 0xd0(%rsp), %rdx
movq %r12, %rcx
callq 0x17429c
movl $0x7, %esi
movq %r14, %rdi
leaq 0x64(%rsp), %rdx
movq %r12, %rcx
callq 0x174250
movl $0x8, %esi
movq %r14, %rdi
leaq 0x94(%rsp), %rdx
movq %r12, %rcx
callq 0x174250
movl $0x9, %esi
movq %r14, %rdi
leaq 0x4c(%rsp), %rdx
movq %r12, %rcx
callq 0x174250
cmpl $0x0, 0x4c(%rsp)
je 0x129224
movl $0xa, %esi
movq %r14, %rdi
leaq 0xc0(%rsp), %rdx
movq %r12, %rcx
callq 0x17422a
movq 0x58(%r15), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rbx
movq %rbx, %rsi
callq 0x10620e
testq %rax, %rax
je 0x1292a0
movl $0x8, %edx
movq 0xb0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x50(%rsp), %r13
movq %r13, %rsi
callq 0xd49ce
movq 0xa8(%rsp), %rdi
callq 0x121b03
movq 0x88(%rsp), %rdi
callq 0x121b03
movq 0x80(%rsp), %rdi
callq 0x121b03
movq %r14, %rdi
movq %r12, %rsi
callq 0x1741ce
testl %eax, %eax
je 0x1290e0
jmp 0x128f0c
movq 0x80(%rsp), %rdi
callq 0x120d23
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
movl 0x64(%rsp), %r8d
movq 0xa8(%rsp), %rdi
movq %rax, %rsi
callq 0x14952c
movq %rax, %rdi
callq 0x149615
movq %rax, %r13
movl 0x94(%rsp), %esi
movq %rax, %rdi
callq 0x149254
movq %r13, %rdi
movq 0x88(%rsp), %rsi
callq 0x1491f1
movsd 0xd0(%rsp), %xmm0
ucomisd 0x227a09(%rip), %xmm0   # 0x350d10
jne 0x12930b
jnp 0x129317
cvtsd2ss %xmm0, %xmm0
movq %r13, %rdi
callq 0x149c09
movq 0x58(%r15), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r13, 0x40(%rsp)
movq %rbx, %rsi
leaq 0x58(%rsp), %rdx
callq 0x106536
testl %eax, %eax
jne 0x129344
movq 0x58(%rsp), %rax
movq %r13, 0x8(%rax)
movq 0x50(%r15), %rdi
movq %r13, 0x38(%rsp)
movq %rbx, %rsi
callq 0x10620e
testq %rax, %rax
jne 0x129389
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 0x106536
testl %eax, %eax
jne 0x129389
movq 0x58(%rsp), %rax
movq %rbx, 0x8(%rax)
movq 0xb8(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x174129
movq 0x50(%rsp), %rdx
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x17416b
movq %r15, %rdi
movq %r12, %rsi
callq 0x1741ce
testl %eax, %eax
jne 0x12942b
callq 0x1208f8
movq %rax, %rbx
callq 0x1208f8
movq %rax, %r14
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x174276
movl $0x1, %esi
movq %r15, %rdi
movq %r14, %rdx
movq %r12, %rcx
callq 0x174276
movq %rbx, %rdi
callq 0x120d23
movq %rax, %r15
movq %r14, %rdi
callq 0x120d23
movq %r13, %rdi
movq %r15, %rsi
movq 0xb8(%rsp), %r15
movq %rax, %rdx
callq 0x149c3c
movq %rbx, %rdi
callq 0x121b03
movq %r14, %rdi
callq 0x121b03
jmp 0x1293ae
cmpl $0x0, 0x4c(%rsp)
movq 0x68(%rsp), %r15
movq 0xc8(%rsp), %r14
leaq 0x38(%rsp), %rsi
je 0x129244
movq 0xc0(%rsp), %rax
testq %rax, %rax
je 0x129479
movq 0x58(%r15), %rdi
movq %rax, 0x38(%rsp)
callq 0x10620e
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x129490
movq %r13, %rdi
callq 0x149e1a
jmp 0x129244
movq %r13, %rdi
callq 0x149dbc
jmp 0x129244
callq 0x3afb1
callq 0x3afea
callq 0x3af78
callq 0x3af3f