// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/extended/sort_stream.c
// Function: gt_sort_stream_next
static int gt_sort_stream_next(GtNodeStream *ns, GtGenomeNode **gn,
                               GtError *err)
{
  GtSortStream *sort_stream;
  GtEOFNode *eofn;
  GtGenomeNode *node;
  int had_err = 0;
  gt_error_check(err);
  sort_stream = gt_sort_stream_cast(ns);

  if (!sort_stream->sorted) {
    while (!(had_err = gt_node_stream_next(sort_stream->in_stream, &node,
                                           err)) && node) {
      if ((eofn = gt_eof_node_try_cast(node)))
        gt_genome_node_delete(node); /* get rid of EOF nodes */
      else
        gt_array_add(sort_stream->nodes, node);
    }
    if (!had_err) {
      gt_genome_nodes_sort_stable(sort_stream->nodes);
      sort_stream->sorted = true;
    }
  }

  if (!had_err) {
    gt_assert(sort_stream->sorted);
    if (sort_stream->idx < gt_array_size(sort_stream->nodes)) {
      *gn = *(GtGenomeNode**) gt_array_get(sort_stream->nodes,
                                           sort_stream->idx);
      sort_stream->idx++;
      /* join region nodes with the same sequence ID */
      if (gt_region_node_try_cast(*gn)) {
        GtRange range_a, range_b;
        while (sort_stream->idx < gt_array_size(sort_stream->nodes)) {
          node = *(GtGenomeNode**) gt_array_get(sort_stream->nodes,
                                                sort_stream->idx);
          if (!gt_region_node_try_cast(node) ||
              gt_str_cmp(gt_genome_node_get_seqid(*gn),
                         gt_genome_node_get_seqid(node))) {
            /* the next node is not a region node with the same ID */
            break;
          }
          range_a = gt_genome_node_get_range(*gn);
          range_b = gt_genome_node_get_range(node);
          range_a = gt_range_join(&range_a, &range_b);
          gt_genome_node_set_range(*gn, &range_a);
          gt_genome_node_delete(node);
          sort_stream->idx++;
        }
      }
      return 0;
    }
  }

  if (!had_err) {
    gt_array_reset(sort_stream->nodes);
    *gn = NULL;
  }

  return had_err;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rdx, 0x98(%rsp)
movl $0x0, 0x7c(%rsp)
cmpq $0x0, 0x98(%rsp)
je 0x2a12d
movq 0x98(%rsp), %rdi
callq 0x7dd0
testb $0x1, %al
jne 0x2a0f5
jmp 0x2a12d
movq 0xcfedc(%rip), %rax     # 0xf9fd8
movq (%rax), %rdi
leaq 0x9df1e(%rip), %rsi     # 0xc8024
leaq 0x9e4fb(%rip), %rdx     # 0xc8608
leaq 0xa4d9b(%rip), %rcx     # 0xceeaf
leaq 0xa4d79(%rip), %r8      # 0xcee94
movl $0x2c, %r9d
movb $0x0, %al
callq 0x76e0
callq 0x7250
jmp 0x2a12f
callq 0x29fd0
movq %rax, %rdi
movq 0xa8(%rsp), %rsi
callq 0x28780
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
testb $0x1, 0x28(%rax)
jne 0x2a21f
jmp 0x2a160
movq 0x90(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x98(%rsp), %rdx
leaq 0x80(%rsp), %rsi
callq 0x28420
movl %eax, %ecx
movl %ecx, 0x7c(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x27(%rsp)
jne 0x2a1a2
cmpq $0x0, 0x80(%rsp)
setne %al
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x2a1ac
jmp 0x2a1f9
movq 0x80(%rsp), %rdi
callq 0x7c430
movq %rax, 0x88(%rsp)
cmpq $0x0, %rax
je 0x2a1d6
movq 0x80(%rsp), %rdi
callq 0x1a870
jmp 0x2a1f4
movq 0x90(%rsp), %rax
movq 0x20(%rax), %rdi
leaq 0x80(%rsp), %rsi
movl $0x8, %edx
callq 0x53570
jmp 0x2a160
cmpl $0x0, 0x7c(%rsp)
jne 0x2a21d
movq 0x90(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x19a70
movq 0x90(%rsp), %rax
movb $0x1, 0x28(%rax)
jmp 0x2a21f
cmpl $0x0, 0x7c(%rsp)
jne 0x2a47b
jmp 0x2a22c
movq 0x90(%rsp), %rax
testb $0x1, 0x28(%rax)
jne 0x2a272
movq 0xcfd97(%rip), %rax     # 0xf9fd8
movq (%rax), %rdi
leaq 0x9ddd9(%rip), %rsi     # 0xc8024
leaq 0xa4c71(%rip), %rdx     # 0xceec3
leaq 0xa4c56(%rip), %rcx     # 0xceeaf
leaq 0xa4c34(%rip), %r8      # 0xcee94
movl $0x3e, %r9d
movb $0x0, %al
callq 0x76e0
callq 0x7250
jmp 0x2a274
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x90(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x537e0
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x2a479
movq 0x90(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0x52fd0
movq (%rax), %rcx
movq 0xa0(%rsp), %rax
movq %rcx, (%rax)
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq 0xa0(%rsp), %rax
movq (%rax), %rdi
callq 0x29b70
cmpq $0x0, %rax
je 0x2a46c
jmp 0x2a302
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x90(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x537e0
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x2a46a
movq 0x90(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0x52fd0
movq (%rax), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rdi
callq 0x29b70
cmpq $0x0, %rax
je 0x2a3a4
movq 0xa0(%rsp), %rax
movq (%rax), %rdi
callq 0x19260
movq %rax, 0x8(%rsp)
movq 0x80(%rsp), %rdi
callq 0x19260
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x15730
cmpl $0x0, %eax
je 0x2a3a9
jmp 0x2a46a
movq 0xa0(%rsp), %rax
movq (%rax), %rdi
callq 0x193b0
movq %rax, 0x48(%rsp)
movq %rdx, 0x50(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x80(%rsp), %rdi
callq 0x193b0
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x6a340
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xa0(%rsp), %rax
movq (%rax), %rdi
leaq 0x68(%rsp), %rsi
callq 0x19510
movq 0x80(%rsp), %rdi
callq 0x1a870
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
jmp 0x2a302
jmp 0x2a46c
movl $0x0, 0xb4(%rsp)
jmp 0x2a4ad
jmp 0x2a47b
cmpl $0x0, 0x7c(%rsp)
jne 0x2a4a2
movq 0x90(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x53910
movq 0xa0(%rsp), %rax
movq $0x0, (%rax)
movl 0x7c(%rsp), %eax
movl %eax, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
addq $0xb8, %rsp
retq
nopl (%rax)