// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/extended/gff3_in_stream_plain.c
// Function: gff3_in_stream_plain_next
static int gff3_in_stream_plain_next(GtNodeStream *ns, GtGenomeNode **gn,
                                     GtError *err)
{
  GtGFF3InStreamPlain *is = gff3_in_stream_plain_cast(ns);
  GtStr *filenamestr;
  int had_err = 0, status_code;

  gt_error_check(err);

  if (gt_queue_size(is->genome_node_buffer) > 1) {
    /* we still have at least two nodes in the buffer -> serve from there */
    *gn = gt_queue_get(is->genome_node_buffer);
    return 0;
  }

  /* the buffer is empty or has one element */
  gt_assert(gt_queue_size(is->genome_node_buffer) <= 1);

  for (;;) {
    /* open file if necessary */
    if (!is->file_is_open) {
      if (gt_str_array_size(is->files) &&
          is->next_file == gt_str_array_size(is->files)) {
        break;
      }
      if (gt_str_array_size(is->files)) {
        if (strcmp(gt_str_array_get(is->files, is->next_file), "-") == 0) {
          if (is->stdin_argument) {
            gt_error_set(err, "multiple specification of argument file \"-\"");
            had_err = -1;
            break;
          }
          is->fpin = gt_file_xopen(NULL, "r");
          is->file_is_open = true;
          is->stdin_argument = true;
        }
        else {
          is->fpin = gt_file_xopen(gt_str_array_get(is->files,
                                                       is->next_file), "r");
          is->file_is_open = true;
        }
        is->next_file++;
      }
      else {
        if (is->stdin_processed)
          break;
        is->fpin = NULL;
        is->file_is_open = true;
      }
      is->line_number = 0;

      if (!had_err && is->progress_bar) {
        printf("processing file \"%s\"\n", gt_str_array_size(is->files)
               ? gt_str_array_get(is->files, is->next_file-1) : "stdin");
      }
      if (!had_err && is->fpin && is->progress_bar) {
        gt_progressbar_start(&is->line_number,
                            gt_file_number_of_lines(gt_str_array_get(is->files,
                                                             is->next_file-1)));
      }
    }

    gt_assert(is->file_is_open);

    filenamestr = gt_str_array_size(is->files)
                  ? gt_str_array_get_str(is->files, is->next_file-1)
                  : is->stdinstr;
    /* read two nodes */
    had_err = gt_gff3_parser_parse_genome_nodes(is->gff3_parser, &status_code,
                                                is->genome_node_buffer,
                                                is->used_types, filenamestr,
                                                &is->line_number, is->fpin,
                                                err);
    if (had_err)
      break;
    if (status_code != EOF) {
      had_err = gt_gff3_parser_parse_genome_nodes(is->gff3_parser, &status_code,
                                                  is->genome_node_buffer,
                                                  is->used_types, filenamestr,
                                                  &is->line_number, is->fpin,
                                                  err);
      if (had_err)
        break;
    }

    if (status_code == EOF) {
      /* end of current file */
      if (is->progress_bar) gt_progressbar_stop();
      gt_file_delete(is->fpin);
      is->fpin = NULL;
      is->file_is_open = false;
      gt_gff3_parser_reset(is->gff3_parser);
      if (!gt_str_array_size(is->files)) {
        is->stdin_processed = true;
        break;
      }
      continue;
    }

    gt_assert(gt_queue_size(is->genome_node_buffer));

    /* make sure the parsed nodes are sorted */
    if (is->ensure_sorting && gt_queue_size(is->genome_node_buffer) > 1) {
      GtGenomeNode *last_node = NULL;
      /* a sorted stream can have at most one input file */
      gt_assert(gt_str_array_size(is->files) == 0 ||
                gt_str_array_size(is->files) == 1);
      had_err = gt_queue_iterate(is->genome_node_buffer, buffer_is_sorted,
                                 &last_node, err);
    }
    if (!had_err) {
      *gn = gt_queue_get(is->genome_node_buffer);
    }
    return had_err;
  }
  gt_assert(!gt_queue_size(is->genome_node_buffer));
  *gn = NULL;
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
callq 0x430f0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x49b60
movq %rax, %r14
testq %r15, %r15
je 0x431db
movq %r15, %rdi
callq 0x3566a
testb %al, %al
jne 0x43512
movq 0x40(%r14), %rdi
callq 0x7c194
xorl %ebp, %ebp
movq 0x40(%r14), %rdi
cmpq $0x1, %rax
jbe 0x431fa
callq 0x7c132
jmp 0x4345d
movq %r12, 0x10(%rsp)
callq 0x7c194
cmpq $0x1, %rax
ja 0x43517
leaq 0x2b(%r14), %r13
leaq 0x29(%r14), %rbp
movq %r14, %r12
addq $0x38, %r12
movq %rbp, 0x18(%rsp)
cmpb $0x0, (%r13)
jne 0x4335f
movq 0x18(%r14), %rdi
callq 0x3d560
testq %rax, %rax
je 0x43251
movq 0x10(%r14), %rbx
movq 0x18(%r14), %rdi
callq 0x3d560
cmpq %rax, %rbx
je 0x4343e
movq 0x18(%r14), %rdi
callq 0x3d560
testq %rax, %rax
je 0x432a4
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdi
callq 0x3d3e2
movq %rax, %rdi
leaq 0xaaaf9(%rip), %rsi     # 0xedd6f
callq 0xb890
testl %eax, %eax
je 0x432be
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdi
callq 0x3d3e2
movq %rax, %rdi
leaq 0xabc12(%rip), %rsi     # 0xeeea8
callq 0x756a8
movq %rax, 0x30(%r14)
movq %r13, %rax
jmp 0x432e2
cmpb $0x0, 0x2a(%r14)
jne 0x4343e
movq $0x0, 0x30(%r14)
movb $0x1, 0x2b(%r14)
jmp 0x432e9
cmpb $0x1, (%rbp)
je 0x434f2
xorl %edi, %edi
leaq 0xabbd7(%rip), %rsi     # 0xeeea8
callq 0x756a8
movq %rax, 0x30(%r14)
movb $0x1, 0x2b(%r14)
movq %rbp, %rax
movb $0x1, (%rax)
incq 0x10(%r14)
movq $0x0, 0x38(%r14)
cmpb $0x1, 0x2c(%r14)
jne 0x4332e
movq 0x18(%r14), %rdi
callq 0x3d560
leaq 0xaa92c(%rip), %rsi     # 0xedc34
testq %rax, %rax
je 0x43320
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdi
decq %rsi
callq 0x3d3e2
movq %rax, %rsi
leaq 0xa30af(%rip), %rdi     # 0xe63d6
xorl %eax, %eax
callq 0xb070
cmpq $0x0, 0x30(%r14)
je 0x4335f
cmpb $0x1, 0x2c(%r14)
jne 0x4335f
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdi
decq %rsi
callq 0x3d3e2
movq %rax, %rdi
callq 0x75ce3
movq %r12, %rdi
movq %rax, %rsi
callq 0x7b1ac
cmpb $0x0, (%r13)
je 0x4350d
movq 0x18(%r14), %rdi
callq 0x3d560
testq %rax, %rax
je 0x4338d
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdi
decq %rsi
callq 0x3d41d
movq %rax, %rbx
jmp 0x43391
movq 0x20(%r14), %rbx
movq 0x48(%r14), %rdi
movq 0x40(%r14), %rdx
movq 0x50(%r14), %rcx
leaq 0xc(%rsp), %rsi
movq %rbx, %r8
movq %r12, %r9
pushq %r15
pushq 0x30(%r14)
callq 0x440b1
addq $0x10, %rsp
testl %eax, %eax
jne 0x43442
cmpl $-0x1, 0xc(%rsp)
je 0x433f0
movq 0x48(%r14), %rdi
movq 0x40(%r14), %rdx
movq 0x50(%r14), %rcx
leaq 0xc(%rsp), %rsi
movq %rbx, %r8
movq %r12, %r9
pushq %r15
pushq 0x30(%r14)
callq 0x440b1
addq $0x10, %rsp
testl %eax, %eax
jne 0x43442
cmpl $-0x1, 0xc(%rsp)
jne 0x43472
cmpb $0x1, 0x2c(%r14)
jne 0x43403
callq 0x7b6c9
movq 0x30(%r14), %rdi
callq 0x75b7c
movq $0x0, 0x30(%r14)
movb $0x0, 0x2b(%r14)
movq 0x48(%r14), %rdi
callq 0x46c80
movq 0x18(%r14), %rdi
callq 0x3d560
testq %rax, %rax
movq 0x18(%rsp), %rbp
jne 0x43222
movb $0x1, 0x2a(%r14)
xorl %ebp, %ebp
jmp 0x43444
movl %eax, %ebp
movq 0x40(%r14), %rdi
callq 0x7c194
testq %rax, %rax
movq 0x10(%rsp), %r12
jne 0x4351c
xorl %eax, %eax
movq %rax, (%r12)
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%r14), %rdi
callq 0x7c194
testq %rax, %rax
je 0x43521
xorl %ebp, %ebp
cmpb $0x1, 0x28(%r14)
movq 0x10(%rsp), %r12
jne 0x434e1
movq 0x40(%r14), %rdi
callq 0x7c194
cmpq $0x2, %rax
jb 0x434e1
movq $0x0, 0x20(%rsp)
movq 0x18(%r14), %rdi
callq 0x3d560
testq %rax, %rax
je 0x434c7
movq 0x18(%r14), %rdi
callq 0x3d560
cmpq $0x1, %rax
jne 0x43526
movq 0x40(%r14), %rdi
leaq 0x2e7(%rip), %rsi       # 0x437b9
leaq 0x20(%rsp), %rdx
movq %r15, %rcx
callq 0x7c3d1
movl %eax, %ebp
testl %ebp, %ebp
jne 0x43461
movq 0x40(%r14), %rdi
jmp 0x431f0
leaq 0xa2eb1(%rip), %rsi     # 0xe63aa
movq %r15, %rdi
xorl %eax, %eax
callq 0x3559f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x43444
callq 0x117cc
callq 0x1175e
callq 0x11795
callq 0x11877
callq 0x1183e
callq 0x11805