// File: /workspace/github_c_makefile_star2_O1/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
movq $0x0, (%rsp)
leaq 0x21f89e(%rip), %rdi    # 0x39c6ec
callq 0x12234f
movq %rax, 0x30(%rsp)
leaq 0x21f891(%rip), %rdi    # 0x39c6f0
callq 0x12234f
movq %rax, 0x28(%rsp)
leaq 0x269fdb(%rip), %rdi    # 0x3e6e4b
callq 0x12234f
movq %rax, 0x20(%rsp)
testq %r14, %r14
je 0x17ce8f
movq %r14, %rdi
callq 0x101a9a
testb %al, %al
jne 0x17d119
callq 0x17ccdc
movq %rax, %rdi
movq %rbx, %rsi
callq 0x16ae64
movq %rax, %rbp
movq 0x50(%rax), %rdi
callq 0x112a74
testq %rax, %rax
je 0x17ced4
movq 0x50(%rbp), %rdi
callq 0x112a12
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
movq 0x10(%rbp), %rdi
movq %rsp, %rsi
movq %r14, %rdx
callq 0x16ace8
movl %eax, %ebx
testl %eax, %eax
jne 0x17cec3
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x17cec3
callq 0x14aefc
testq %rax, %rax
je 0x17cf57
movq %rax, %rbx
movq %r12, %r15
movq %rax, %rdi
callq 0x149bb2
movq %rax, %r12
movq (%rsp), %rdi
callq 0x14b8df
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
cmpq 0x30(%rsp), %r12
je 0x17cf6a
cmpq 0x28(%rsp), %r12
je 0x17cf6a
xorl %ebx, %ebx
cmpq 0x20(%rsp), %r12
je 0x17cff6
movq %r15, %r12
jmp 0x17d0fd
movq %rbp, %rdi
movq %r14, %rsi
callq 0x17d22f
movl %eax, %ebx
testl %eax, %eax
jne 0x17cfcb
jmp 0x17cfbe
movq %r15, %r12
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x117826
testb %al, %al
je 0x17cf9f
movq 0x48(%rbp), %r12
movq %rbx, %rdi
callq 0x14b5fc
movq %r12, %rdi
movq %r15, %r12
movq %rax, %rsi
callq 0x112923
xorl %ebx, %ebx
jmp 0x17d0fd
movq 0x50(%rbp), %rdi
callq 0x112a74
testq %rax, %rax
jne 0x17d114
movq %rbp, %rdi
movq %r14, %rsi
callq 0x17d22f
movl %eax, %ebx
movq 0x50(%rbp), %rdi
movq (%rsp), %rsi
callq 0x112923
movq 0x50(%rbp), %rdi
callq 0x112a74
testq %rax, %rax
je 0x17d0fd
movq 0x50(%rbp), %rdi
callq 0x112a12
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movb $0x1, %r13b
jmp 0x17d0fd
movq 0x20(%rbp), %rdi
callq 0xd4a9a
testq %rax, %rax
je 0x17d056
movq %r15, %r12
movq %r15, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x117826
testb %al, %al
je 0x17d08f
movq (%rsp), %rdi
callq 0x14b5fc
movq %rax, 0x8(%rsp)
movq 0x20(%rbp), %rdi
movl $0x8, %edx
leaq 0x8(%rsp), %rsi
callq 0xd49ce
movq %rbx, %rdi
movq %r12, %rsi
callq 0x117923
movq %rax, 0x30(%rbp)
movq %rdx, 0x38(%rbp)
xorl %ebx, %ebx
jmp 0x17d0f4
movq (%rsp), %rdi
callq 0x14b5fc
movq %rax, 0x8(%rsp)
movq 0x20(%rbp), %rdi
movl $0x8, %edx
leaq 0x8(%rsp), %rsi
callq 0xd49ce
movq (%rsp), %rdi
callq 0x14b8df
movq %rax, 0x30(%rbp)
movq %rdx, 0x38(%rbp)
xorl %ebx, %ebx
movq %r15, %r12
jmp 0x17d0f4
movq %rbp, %rdi
movq %r14, %rsi
callq 0x17d22f
movl %eax, %ebx
testl %eax, %eax
jne 0x17d0d2
movq (%rsp), %rdi
callq 0x14b5fc
movq %rax, 0x8(%rsp)
movq 0x20(%rbp), %rdi
movl $0x8, %edx
leaq 0x8(%rsp), %rsi
callq 0xd49ce
movq (%rsp), %rdi
callq 0x14b8df
movq %rax, 0x30(%rbp)
movq %rdx, 0x38(%rbp)
movq 0x50(%rbp), %rdi
callq 0x112a74
testq %rax, %rax
je 0x17d0f4
movq 0x50(%rbp), %rdi
callq 0x112a12
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movb $0x1, %r13b
movq (%rsp), %rdi
callq 0x14c43a
testl %ebx, %ebx
jne 0x17cec3
testb $0x1, %r13b
je 0x17cee8
jmp 0x17cec3
callq 0x55b85
callq 0x55b4e