// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/chseqids_stream.c
// Function: chseqids_stream_next
static int chseqids_stream_next(GtNodeStream *ns, GtGenomeNode **gn,
                                GtError *err)
{
  GtChseqidsStream *cs;
  GtGenomeNode *node, **gn_a, **gn_b;
  GtFeatureNode *feature_node;
  GtStr *changed_seqid;
  GtUword i;
  int GT_UNUSED rval, had_err = 0;
  gt_error_check(err);
  cs = chseqids_stream_cast(ns);

  if (!cs->sequence_regions_processed) {
    while (!had_err) {
      if (!(had_err = gt_node_stream_next(cs->in_stream, &node, err))) {
        if (node)
          gt_array_add(cs->node_buffer, node);
        else
          break;
        if (!gt_region_node_try_cast(node))
          break; /* no more sequence regions */
      }
    }
    /* now the buffer contains only sequence regions (except the last entry)
       -> change sequence ids */
    for (i = 0; !had_err && i < gt_array_size(cs->node_buffer); i++) {
      node = *(GtGenomeNode**) gt_array_get(cs->node_buffer, i);
      if (gt_genome_node_get_seqid(node)) {
        if  ((changed_seqid = gt_mapping_map_string(cs->chseqids_mapping,
                                     gt_str_get(gt_genome_node_get_seqid(node)),
                                                 err))) {
          if ((feature_node = gt_feature_node_try_cast(node))) {
            rval = gt_feature_node_traverse_children(feature_node,
                                                     changed_seqid,
                                                     change_sequence_id, true,
                                                     err);
            gt_assert(!rval); /* change_sequence_id() is sane */
          }
          else
            gt_genome_node_change_seqid(node, changed_seqid);
          gt_str_delete(changed_seqid);
        }
        else
          had_err = -1;
       }
    }
    /* sort them */
    if (!had_err)
      gt_genome_nodes_sort(cs->node_buffer);
    /* consolidate them */
    for (i = 1; !had_err && i + 1 < gt_array_size(cs->node_buffer); i++) {
      gn_a = gt_array_get(cs->node_buffer, i-1);
      gn_b = gt_array_get(cs->node_buffer, i);
      if (gt_genome_nodes_are_equal_region_nodes(*gn_a, *gn_b)) {
        gt_region_node_consolidate(gt_region_node_cast(*gn_b),
                                   gt_region_node_cast(*gn_a));
        gt_genome_node_delete(*gn_a);
        *gn_a = NULL;
      }
    }
    cs->sequence_regions_processed = true;
  }

  /* return non-null nodes from buffer */
  while (!had_err && cs->buffer_index < gt_array_size(cs->node_buffer)) {
    node = *(GtGenomeNode**) gt_array_get(cs->node_buffer, cs->buffer_index);
    cs->buffer_index++;
    if (node) {
      *gn = node;
      return had_err;
    }
  }

  if (!had_err)
    had_err = gt_node_stream_next(cs->in_stream, gn, err);
  if (!had_err && *gn) {
    if (gt_genome_node_get_seqid(*gn)) {
      changed_seqid = gt_mapping_map_string(cs->chseqids_mapping,
                                      gt_str_get(gt_genome_node_get_seqid(*gn)),
                                         err);
      gt_assert(changed_seqid); /* is always defined, because an undefined
                                   mapping would be catched earlier */
      if ((feature_node = gt_feature_node_try_cast(*gn))) {
        rval = gt_feature_node_traverse_children(feature_node, changed_seqid,
                                                 change_sequence_id, true, err);
        gt_assert(!rval); /* change_sequence_id() is sane */
      }
      else
        gt_genome_node_change_seqid(*gn, changed_seqid);
      gt_str_delete(changed_seqid);
    }
  }

  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r14
testq %rdx, %rdx
je 0xbe82a
movq %rbx, %rdi
callq 0x89eb7
testb %al, %al
jne 0xbeb34
callq 0xbe760
movq %rax, %rdi
movq %r14, %rsi
callq 0x102c81
movq %rax, %r15
cmpb $0x0, 0x30(%rax)
jne 0xbe9f0
movq %r12, 0x10(%rsp)
xorl %r13d, %r13d
leaq 0x8(%rsp), %r14
pushq $0x8
popq %r12
movl %r13d, %ebp
testl %r13d, %r13d
jne 0xbe89c
movq 0x10(%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x102a22
movl %eax, %r13d
testl %eax, %eax
jne 0xbe858
cmpq $0x0, 0x8(%rsp)
je 0xbe89c
movq 0x20(%r15), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x5851d
movq 0x8(%rsp), %rdi
callq 0x1112ad
testq %rax, %rax
jne 0xbe858
xorl %r12d, %r12d
pushq $-0x1
popq %r14
testl %ebp, %ebp
jne 0xbe95b
movq 0x20(%r15), %rdi
callq 0x586a4
movq 0x20(%r15), %rdi
cmpq %rax, %r12
jae 0xbe965
movq %r12, %rsi
callq 0x581aa
movq (%rax), %rdi
movq %rdi, 0x8(%rsp)
callq 0xdd14a
xorl %ebp, %ebp
testq %rax, %rax
je 0xbe953
movq 0x18(%r15), %r13
movq 0x8(%rsp), %rdi
callq 0xdd14a
movq %rax, %rdi
callq 0xad1fa
movq %r13, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0xfb336
movl %r14d, %ebp
testq %rax, %rax
je 0xbe953
movq %rax, %r13
movq 0x8(%rsp), %rdi
callq 0xdc2f0
testq %rax, %rax
je 0xbe93c
movq %rax, %rdi
movq %r13, %rsi
leaq 0x3c1(%rip), %rdx       # 0xbece9
pushq $0x1
popq %rcx
movq %rbx, %r8
callq 0xdac92
testl %eax, %eax
je 0xbe949
jmp 0xbeb0a
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0xdd346
movq %r13, %rdi
callq 0xae103
xorl %ebp, %ebp
incq %r12
jmp 0xbe8a3
movb $0x1, 0x30(%r15)
jmp 0xbea44
callq 0xdd582
xorl %r12d, %r12d
leaq 0x2(%r12), %r14
movq 0x20(%r15), %rdi
callq 0x586a4
cmpq %rax, %r14
jae 0xbe9e6
leaq 0x1(%r12), %r14
movq 0x20(%r15), %rdi
movq %r12, %rsi
callq 0x581aa
movq %rax, %r12
movq 0x20(%r15), %rdi
movq %r14, %rsi
callq 0x581aa
movq %rax, %r13
movq (%r12), %rdi
movq (%rax), %rsi
callq 0xdd708
testb %al, %al
je 0xbe9e1
movq (%r13), %rdi
callq 0x111184
movq %rax, %r13
movq (%r12), %rdi
callq 0x111184
movq %r13, %rdi
movq %rax, %rsi
callq 0x111199
movq (%r12), %rdi
callq 0xde013
andq $0x0, (%r12)
movq %r14, %r12
jmp 0xbe96d
movb $0x1, 0x30(%r15)
movq 0x10(%rsp), %r12
movq 0x28(%r15), %r14
movq 0x20(%r15), %rdi
callq 0x586a4
cmpq %rax, %r14
jae 0xbea2f
movq 0x20(%r15), %rdi
movq 0x28(%r15), %rsi
callq 0x581aa
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%r15), %r14
incq %r14
movq %r14, 0x28(%r15)
testq %rax, %rax
je 0xbe9f4
movq %rax, (%r12)
xorl %ebp, %ebp
jmp 0xbea44
movq 0x10(%r15), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x102a22
movl %eax, %ebp
testl %eax, %eax
je 0xbea55
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rdi
xorl %ebp, %ebp
testq %rdi, %rdi
je 0xbea44
callq 0xdd14a
testq %rax, %rax
je 0xbea44
movq 0x18(%r15), %r14
movq (%r12), %rdi
callq 0xdd14a
movq %rax, %rdi
callq 0xad1fa
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0xfb336
testq %rax, %rax
je 0xbeb6a
movq %rax, %r14
movq (%r12), %rdi
callq 0xdc2f0
testq %rax, %rax
je 0xbeaf1
leaq 0x23b(%rip), %rdx       # 0xbece9
pushq $0x1
popq %rcx
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %r8
callq 0xdac92
testl %eax, %eax
je 0xbeafd
movq 0x37949e(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x22653f(%rip), %rsi    # 0x2e5013
leaq 0x2444bc(%rip), %rdx    # 0x302f97
leaq 0x259aa2(%rip), %rcx    # 0x318584
leaq 0x259a61(%rip), %r8     # 0x31854a
movl $0x88, %r9d
jmp 0xbeb5e
movq (%r12), %rdi
movq %r14, %rsi
callq 0xdd346
movq %r14, %rdi
callq 0xae103
jmp 0xbea44
movq 0x379457(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2264f8(%rip), %rsi    # 0x2e5013
leaq 0x244475(%rip), %rdx    # 0x302f97
leaq 0x259a5b(%rip), %rcx    # 0x318584
leaq 0x259a1a(%rip), %r8     # 0x31854a
pushq $0x57
jmp 0xbeb5c
movq 0x37942d(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2264ce(%rip), %rsi    # 0x2e5013
leaq 0x226673(%rip), %rdx    # 0x2e51bf
leaq 0x259a31(%rip), %rcx    # 0x318584
leaq 0x2599f0(%rip), %r8     # 0x31854a
pushq $0x3c
popq %r9
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x3793f7(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x226498(%rip), %rsi    # 0x2e5013
leaq 0x259a17(%rip), %rdx    # 0x318599
leaq 0x2599fb(%rip), %rcx    # 0x318584
leaq 0x2599ba(%rip), %r8     # 0x31854a
movl $0x83, %r9d
jmp 0xbeb5e