// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movq %rdi, %rbx
movq $0x0, 0x8(%rsp)
leaq 0x21e840(%rip), %rdi    # 0x393283
callq 0x11c5ff
movq %rax, %r15
leaq 0x21e835(%rip), %rdi    # 0x393287
callq 0x11c5ff
movq %rax, 0x30(%rsp)
leaq 0x268ce8(%rip), %rdi    # 0x3dd74b
callq 0x11c5ff
movq %rax, 0x28(%rsp)
testq %r14, %r14
je 0x174a82
movq %r14, %rdi
callq 0xfcc32
testb %al, %al
jne 0x174d49
callq 0x1748d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x162ff7
movq %rax, %rbp
movq 0x50(%rax), %rdi
callq 0x10d7ac
testq %rax, %rax
je 0x174ac9
movq 0x50(%rbp), %rdi
callq 0x10d74a
xorl %r13d, %r13d
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movl %r13d, %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, 0x20(%rsp)
movq 0x10(%rbp), %rdi
leaq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x162e68
movl %eax, %r13d
testl %eax, %eax
jne 0x174ab7
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x174ab7
callq 0x143cab
testq %rax, %rax
je 0x174baf
movq %rax, %r13
movq %rax, %rdi
callq 0x142988
movq %rax, %r12
movq 0x8(%rsp), %rdi
callq 0x144679
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
cmpq %r15, %r12
je 0x174be8
cmpq 0x30(%rsp), %r12
je 0x174be8
xorl %ebx, %ebx
movl $0x0, %r13d
cmpq 0x28(%rsp), %r12
jne 0x174d20
movq 0x20(%rbp), %rdi
callq 0xd24e0
testq %rax, %rax
je 0x174c70
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x112246
testb %al, %al
je 0x174cab
movq 0x8(%rsp), %rdi
callq 0x1443a0
movq %rax, 0x10(%rsp)
movq 0x20(%rbp), %rdi
movl $0x8, %edx
leaq 0x10(%rsp), %rsi
callq 0xd2410
movq %rbx, %rdi
movq %r12, %rsi
callq 0x112343
jmp 0x174c9c
movq %rbp, %rdi
movq %r14, %rsi
callq 0x174e62
movl %eax, %r13d
testl %eax, %eax
jne 0x174bcf
movq 0x50(%rbp), %rdi
movq 0x8(%rsp), %rsi
callq 0x10d65b
movq 0x50(%rbp), %rdi
callq 0x10d7ac
testq %rax, %rax
jne 0x174d36
xorl %ebx, %ebx
jmp 0x174d20
leaq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x112246
testb %al, %al
je 0x174c1c
movq 0x48(%rbp), %r12
movq %r13, %rdi
callq 0x1443a0
movq %r12, %rdi
movq %rax, %rsi
callq 0x10d65b
xorl %ebx, %ebx
xorl %r13d, %r13d
jmp 0x174d20
movq 0x50(%rbp), %rdi
callq 0x10d7ac
testq %rax, %rax
jne 0x174d44
movq %rbp, %rdi
movq %r14, %rsi
callq 0x174e62
movl %eax, %r13d
movq 0x50(%rbp), %rdi
movq 0x8(%rsp), %rsi
callq 0x10d65b
movq 0x50(%rbp), %rdi
callq 0x10d7ac
testq %rax, %rax
je 0x174be1
movq 0x50(%rbp), %rdi
callq 0x10d74a
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movb $0x1, %bl
jmp 0x174d20
movq 0x8(%rsp), %rdi
callq 0x1443a0
movq %rax, 0x10(%rsp)
movq 0x20(%rbp), %rdi
movl $0x8, %edx
leaq 0x10(%rsp), %rsi
callq 0xd2410
movq 0x8(%rsp), %rdi
callq 0x144679
movq %rax, 0x30(%rbp)
movq %rdx, 0x38(%rbp)
xorl %ebx, %ebx
xorl %r13d, %r13d
jmp 0x174d16
movq %rbp, %rdi
movq %r14, %rsi
callq 0x174e62
movl %eax, %r13d
testl %eax, %eax
jne 0x174cf1
movq 0x8(%rsp), %rdi
callq 0x1443a0
movq %rax, 0x10(%rsp)
movq 0x20(%rbp), %rdi
movl $0x8, %edx
leaq 0x10(%rsp), %rsi
callq 0xd2410
movq 0x8(%rsp), %rdi
callq 0x144679
movq %rax, 0x30(%rbp)
movq %rdx, 0x38(%rbp)
movq 0x50(%rbp), %rdi
callq 0x10d7ac
testq %rax, %rax
je 0x174d14
movq 0x50(%rbp), %rdi
callq 0x10d74a
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movb $0x1, %bl
jmp 0x174d16
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
callq 0x1451a0
testl %r13d, %r13d
jne 0x174ab7
testb %bl, %bl
je 0x174ad5
jmp 0x174ab7
movq 0x50(%rbp), %rdi
callq 0x10d74a
jmp 0x174aaf
callq 0x54a5e
callq 0x54a27