// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/gtlua/genome_stream_lua.c
// Function: lua_custom_stream_next
static int lua_custom_stream_next(GtNodeStream *ns, GtGenomeNode **gn,
                                  GtError *err)
{
  GT_UNUSED GtNodeStream **s;
  GtGenomeNode **retnode;
  GtLuaCustomStream *lcs;
  int had_err = 0;
  gt_assert(ns);
  gt_error_check(err);
  lcs = lua_custom_stream_cast(ns);

  /* push correct Lua object for this stream */
  lua_rawgeti(lcs->L, LUA_REGISTRYINDEX, lcs->ref);
  s = check_genome_stream(lcs->L, -1);

  /* get overridden next_tree method */
  lua_pushstring(lcs->L, "next_tree");
  lua_gettable(lcs->L, -2);

  /* make sure there is one */
  gt_assert(!lua_isnil(lcs->L, -1));
  lua_pushvalue(lcs->L, -2);

  if (lua_pcall(lcs->L, 1, 1, 0)) {
    const char *error = lua_tostring(lcs->L, -1);
    gt_error_set(err, "%s", error);
    had_err = -1;
  }

  if (!had_err) {
    if (lua_isnil(lcs->L, -1)) {
      *gn = NULL;
    } else {
      retnode = gt_lua_try_checkudata(lcs->L, -1, GENOME_NODE_METATABLE);
      if (!retnode) {
        const char *type;
        type = lua_tostring(lcs->L, -1);
        gt_error_set(err, "custom 'next_tree' method must return a genome "
                          "node or nil, was %s", type);
        had_err = -1;
      } else {
        *gn = gt_genome_node_ref(*retnode);
      }
    }
  }
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x940af
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
testq %rdx, %rdx
je 0x93fa8
movq %rbx, %rdi
callq 0xc103
testb %al, %al
jne 0x9410b
callq 0x93f44
movq %rax, %rdi
movq %r15, %rsi
callq 0x25ec1
movq %rax, %r15
movq 0x18(%rax), %rdi
movl 0x20(%rax), %edx
movl $0xffffd8f0, %esi       # imm = 0xFFFFD8F0
callq 0x38b62
movq 0x18(%r15), %rdi
leaq 0x4b021(%rip), %rdx     # 0xdeff8
pushq $-0x1
popq %rbp
movl %ebp, %esi
callq 0x3ae77
movq 0x18(%r15), %rdi
leaq 0x534d0(%rip), %rsi     # 0xe74bc
callq 0x38431
movq 0x18(%r15), %rdi
pushq $-0x2
popq %rsi
callq 0x3894c
movq 0x18(%r15), %rdi
movl %ebp, %esi
callq 0x37b59
testl %eax, %eax
je 0x940dd
movq 0x18(%r15), %rdi
pushq $-0x2
popq %rsi
callq 0x37b39
movq 0x18(%r15), %rdi
pushq $0x1
popq %rdx
movl %edx, %esi
xorl %ecx, %ecx
callq 0x39305
movq 0x18(%r15), %rdi
testl %eax, %eax
je 0x94053
movl %ebp, %esi
xorl %edx, %edx
callq 0x37f9b
leaq 0x43a65(%rip), %rsi     # 0xd7aa9
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xc007
jmp 0x9408c
pushq $-0x1
popq %rsi
callq 0x37b59
testl %eax, %eax
je 0x94086
movq 0x18(%r15), %rdi
leaq 0x4a71d(%rip), %rdx     # 0xde787
pushq $-0x1
popq %rbp
movl %ebp, %esi
callq 0x88c6a
testq %rax, %rax
je 0x94099
movq (%rax), %rdi
callq 0x1bec8
movq %rax, (%r14)
jmp 0x9408a
andq $0x0, (%r14)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%r15), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x37f9b
leaq 0x53430(%rip), %rsi     # 0xe74dd
jmp 0x94044
movq 0x99f02(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x35fa6(%rip), %rsi     # 0xca066
leaq 0x5352e(%rip), %rdx     # 0xe75f5
leaq 0x533d7(%rip), %rcx     # 0xe74a5
leaq 0x533b2(%rip), %r8      # 0xe7487
movl $0x94, %r9d
jmp 0x94137
movq 0x99ed4(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x35f78(%rip), %rsi     # 0xca066
leaq 0x533d1(%rip), %rdx     # 0xe74c6
leaq 0x533a9(%rip), %rcx     # 0xe74a5
leaq 0x53384(%rip), %r8      # 0xe7487
movl $0xa1, %r9d
jmp 0x94137
movq 0x99ea6(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x35f4a(%rip), %rsi     # 0xca066
leaq 0x36536(%rip), %rdx     # 0xca659
leaq 0x5337b(%rip), %rcx     # 0xe74a5
leaq 0x53356(%rip), %r8      # 0xe7487
movl $0x95, %r9d
xorl %eax, %eax
callq 0xb8c0
callq 0xb300