// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/snp_annotator_stream.c
// Function: snp_annotator_stream_next
static int snp_annotator_stream_next(GtNodeStream *ns, GtGenomeNode **gn,
                                     GtError *err)
{
  GtSNPAnnotatorStream *sas;
  int had_err = 0;
  bool complete_cluster = false;
  GtGenomeNode *mygn = NULL;
  GtFeatureNode *fn = NULL;
  const char *snv_type = gt_symbol(gt_ft_SNV),
             *snp_type = gt_symbol(gt_ft_SNP),
             *gene_type = gt_symbol(gt_ft_gene);
  gt_error_check(err);
  sas = gt_snp_annotator_stream_cast(ns);

  /* if there are still SNPs left in the buffer, output them */
  if (gt_queue_size(sas->outqueue) > 0) {
    *gn = (GtGenomeNode*) gt_queue_get(sas->outqueue);
    return had_err;
  } else complete_cluster = false;

  while (!had_err && !complete_cluster) {
    had_err = gt_node_stream_next(sas->merge_stream, &mygn, err);

    /* stop if stream is at the end */
    if (had_err || !mygn) break;

    /* process all feature nodes */
    if ((fn = gt_feature_node_try_cast(mygn))) {
      GtGenomeNode *addgn;
      const char *type = gt_feature_node_get_type(fn);
      GtRange new_rng = gt_genome_node_get_range(mygn);
      if (type == snv_type || type == snp_type) {
        /* -----> this is a SNP <----- */
        if (gt_range_overlap(&new_rng, &sas->cur_gene_range)) {
          /* it falls into the currently observed range */
          gt_queue_add(sas->snps, gt_genome_node_ref((GtGenomeNode*) fn));
        } else {
          /* SNP outside a gene, this cluster is done
             add to out queue and start serving */
          gt_assert(gt_queue_size(sas->outqueue) == 0);
          had_err = snp_annotator_stream_process_current_gene(sas, err);
          gt_queue_add(sas->outqueue, mygn);
          if (gt_queue_size(sas->outqueue) > 0) {
            *gn = (GtGenomeNode*) gt_queue_get(sas->outqueue);
            complete_cluster = true;
          }
        }
      } else if (type == gene_type) {
        /* -----> this is a gene <----- */
        if (gt_array_size(sas->cur_gene_set) == 0UL) {
          /* new overlapping gene cluster */
          addgn = gt_genome_node_ref(mygn);
          gt_array_add(sas->cur_gene_set, addgn);
          sas->cur_gene_range = gt_genome_node_get_range(mygn);
        } else {
          if (gt_range_overlap(&new_rng, &sas->cur_gene_range)) {
            /* gene overlaps with current one, add to cluster */
            addgn = gt_genome_node_ref(mygn);
            gt_array_add(sas->cur_gene_set, addgn);
            sas->cur_gene_range = gt_range_join(&sas->cur_gene_range, &new_rng);
          } else {
            /* finish current cluster and start a new one */
            had_err = snp_annotator_stream_process_current_gene(sas, err);
            if (!had_err) {
              addgn = gt_genome_node_ref(mygn);
              gt_array_add(sas->cur_gene_set, addgn);
              sas->cur_gene_range = gt_genome_node_get_range(mygn);
            }
            if (gt_queue_size(sas->outqueue) > 0) {
              *gn = (GtGenomeNode*) gt_queue_get(sas->outqueue);
              complete_cluster = true;
            }
          }
        }
        /* from now on, genes are kept in gene cluster arrays only */
        gt_genome_node_delete(mygn);
      }
    } else {
      /* meta node */
      had_err = snp_annotator_stream_process_current_gene(sas, err);
      if (!had_err) {
        gt_queue_add(sas->outqueue, mygn);
      }
      if (gt_queue_size(sas->outqueue) > 0) {
        *gn = (GtGenomeNode*) gt_queue_get(sas->outqueue);
        complete_cluster = true;
      }
    }
  }

  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r14
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
andq $0x0, (%rsp)
leaq 0x21a607(%rip), %rdi    # 0x3335dc
callq 0xaed4b
movq %rax, 0x30(%rsp)
leaq 0x21a5fa(%rip), %rdi    # 0x3335e0
callq 0xaed4b
movq %rax, 0x28(%rsp)
leaq 0x264b24(%rip), %rdi    # 0x37db1b
callq 0xaed4b
movq %rax, 0x20(%rsp)
testq %r14, %r14
je 0x119016
movq %r14, %rdi
callq 0x89eb7
testb %al, %al
jne 0x1192f4
callq 0x118e84
movq %rax, %rdi
movq %rbx, %rsi
callq 0x102c81
movq %rax, %rbp
movq 0x50(%rax), %rdi
callq 0x9e48b
testq %rax, %rax
je 0x11905b
movq 0x50(%rbp), %rdi
callq 0x9e411
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rax
addq $0x30, %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
leaq 0x38(%rsp), %r12
xorl %ebx, %ebx
testl %ebx, %ebx
jne 0x11904a
testb $0x1, %r13b
jne 0x11904a
movq 0x10(%rbp), %rdi
movq %rsp, %rsi
movq %r14, %rdx
callq 0x102a22
movl %eax, %ebx
testl %eax, %eax
jne 0x11904a
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x11904a
callq 0xdc2f0
testq %rax, %rax
je 0x119150
movq %rax, %rbx
movq %r12, %r15
movq %rax, %rdi
callq 0xda338
movq %rax, %r12
movq (%rsp), %rdi
callq 0xdd1f4
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
cmpq 0x30(%rsp), %r12
je 0x119184
cmpq 0x28(%rsp), %r12
je 0x119184
xorl %r13d, %r13d
movl $0x0, %ebx
cmpq 0x20(%rsp), %r12
movq %r15, %r12
jne 0x119071
movq 0x20(%rbp), %rdi
callq 0x586a4
testq %rax, %rax
je 0x1191f7
movq %r12, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0xa3234
testb %al, %al
je 0x11922e
movq (%rsp), %rdi
callq 0xdccf8
movq %rax, 0x8(%rsp)
movq 0x20(%rbp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x5851d
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa33f9
jmp 0x11921f
movq %rbp, %rdi
movq %r14, %rsi
callq 0x11946f
movl %eax, %ebx
testl %eax, %eax
jne 0x11916e
movq 0x50(%rbp), %rdi
movq (%rsp), %rsi
callq 0x9e2d1
movq 0x50(%rbp), %rdi
callq 0x9e48b
xorl %r13d, %r13d
testq %rax, %rax
jne 0x1191d6
jmp 0x119071
movq %r15, %r12
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0xa3234
testb %al, %al
jne 0x1192a4
movq 0x50(%rbp), %rdi
callq 0x9e48b
testq %rax, %rax
jne 0x1192c6
movq %rbp, %rdi
movq %r14, %rsi
callq 0x11946f
movl %eax, %ebx
movq 0x50(%rbp), %rdi
movq (%rsp), %rsi
callq 0x9e2d1
movq 0x50(%rbp), %rdi
callq 0x9e48b
testq %rax, %rax
je 0x1191ef
movq 0x50(%rbp), %rdi
callq 0x9e411
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movb $0x1, %r13b
jmp 0x119071
xorl %r13d, %r13d
jmp 0x119071
movq (%rsp), %rdi
callq 0xdccf8
movq %rax, 0x8(%rsp)
movq 0x20(%rbp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x5851d
movq (%rsp), %rdi
callq 0xdd1f4
movq %rax, 0x30(%rbp)
movq %rdx, 0x38(%rbp)
xorl %r13d, %r13d
xorl %ebx, %ebx
jmp 0x119296
movq %rbp, %rdi
movq %r14, %rsi
callq 0x11946f
movl %eax, %ebx
testl %eax, %eax
jne 0x11926f
movq (%rsp), %rdi
callq 0xdccf8
movq %rax, 0x8(%rsp)
movq 0x20(%rbp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x5851d
movq (%rsp), %rdi
callq 0xdd1f4
movq %rax, 0x30(%rbp)
movq %rdx, 0x38(%rbp)
movq 0x50(%rbp), %rdi
callq 0x9e48b
testq %rax, %rax
je 0x119293
movq 0x50(%rbp), %rdi
callq 0x9e411
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movb $0x1, %r13b
jmp 0x119296
xorl %r13d, %r13d
movq (%rsp), %rdi
callq 0xde013
jmp 0x119071
movq 0x48(%rbp), %r12
movq %rbx, %rdi
callq 0xdccf8
movq %r12, %rdi
movq %r15, %r12
movq %rax, %rsi
callq 0x9e2d1
xorl %r13d, %r13d
jmp 0x11906f
movq 0x31ec9b(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1cbd3c(%rip), %rsi    # 0x2e5013
leaq 0x21a320(%rip), %rdx    # 0x3335fe
leaq 0x21a2ff(%rip), %rcx    # 0x3335e4
leaq 0x21a2cc(%rip), %r8     # 0x3335b8
movl $0x92, %r9d
jmp 0x11931e
movq 0x31ec6d(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1cbd0e(%rip), %rsi    # 0x2e5013
leaq 0x1cbeb3(%rip), %rdx    # 0x2e51bf
leaq 0x21a2d1(%rip), %rcx    # 0x3335e4
leaq 0x21a29e(%rip), %r8     # 0x3335b8
pushq $0x76
popq %r9
xorl %eax, %eax
callq 0x17a50
callq 0x17390