// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/mapping.c
// Function: gt_mapping_new
GtMapping* gt_mapping_new(GtStr *mapping_file, const char *global_name,
                          GtMappingType type, GtError *err)
{
  GtMapping *m;
  int had_err = 0;
  gt_error_check(err);
  gt_assert(mapping_file && global_name);
  /* alloc */
  m = gt_malloc(sizeof (GtMapping));
  m->mapping_file = gt_str_ref(mapping_file);
  m->global = gt_cstr_dup(global_name);
  m->type = type;
  /* create new lua state (i.e., interpreter) */
  m->L = luaL_newstate();
  if (!m->L) {
    gt_error_set(err, "out of memory (cannot create new Lua state)");
    had_err = -1;
  }
  /* load the standard libs into the Lua interpreter */
  if (!had_err) {
    luaL_openlibs(m->L);
    gt_assert(!lua_gettop(m->L));
  }
  /* try to load & run mapping file */
  if (!had_err) {
    if (luaL_loadfile(m->L, gt_str_get(mapping_file)) ||
        lua_pcall(m->L, 0, 0, 0)) {
      gt_error_set(err, "cannot run file: %s", lua_tostring(m->L, -1));
      had_err = -1;
      lua_pop(m->L, 1);
    }
  }
  /* make sure a global variable with name <global_name> is defined */
  if (!had_err) {
    lua_getglobal(m->L, global_name);
    if (lua_isnil(m->L, -1)) {
      gt_error_set(err, "'%s' is not defined in \"%s\"", global_name,
                gt_str_get(mapping_file));
      had_err = -1;
      lua_pop(m->L, 1);
    }
  }
  /* make sure it is either a table or a function */
  if (!had_err) {
    if (!(lua_istable(m->L, -1) || lua_isfunction(m->L, -1))) {
      gt_error_set(err, "'%s' must be either a table or a function (defined "
                     "in \"%s\")", global_name, gt_str_get(mapping_file));
      had_err = -1;
      lua_pop(m->L, 1);
    }
  }
  /* remember if it is a table or a function */
  if (!had_err) {
    if (lua_istable(m->L, -1))
      m->is_table = true;
    else
      m->is_table = false;
    lua_pop(m->L, 1);
  }
  /* return */
  gt_assert(!lua_gettop(m->L));
  if (had_err) {
    gt_mapping_delete(m);
    return NULL;
  }
  return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r12
testq %rcx, %rcx
je 0x24c5b
movq %r14, %rdi
callq 0xc103
testb %al, %al
jne 0x24e60
testq %r12, %r12
je 0x24e0c
testq %r15, %r15
je 0x24e0c
leaq 0xacdca(%rip), %rsi     # 0xd1a3e
pushq $0x28
popq %rdi
pushq $0x2a
popq %rdx
callq 0xccb0
movq %rax, %rbx
movq %r12, %rdi
callq 0x146aa
movq %rax, (%rbx)
movq %r15, %rdi
callq 0x4f8ae
movq %rax, 0x8(%rbx)
movl %ebp, 0x10(%rbx)
callq 0x3ba0a
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x24d24
movq %rax, %rdi
callq 0x3be09
movq 0x18(%rbx), %rdi
callq 0x377ed
testl %eax, %eax
jne 0x24e8a
movq 0x18(%rbx), %r13
movq %r12, %rdi
callq 0x143d2
movq %r13, %rdi
movq %rax, %rsi
callq 0x3b730
testl %eax, %eax
jne 0x24cf1
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x39305
testl %eax, %eax
je 0x24d6a
movq 0x18(%rbx), %rdi
xorl %r12d, %r12d
pushq $-0x1
popq %rsi
xorl %edx, %edx
callq 0x37f9b
leaq 0xacda6(%rip), %rsi     # 0xd1aaf
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xc007
movq 0x18(%rbx), %rdi
pushq $-0x2
popq %rsi
callq 0x377fa
jmp 0x24d38
leaq 0xacd46(%rip), %rsi     # 0xd1a71
xorl %r12d, %r12d
movq %r14, %rdi
xorl %eax, %eax
callq 0xc007
movq 0x18(%rbx), %rdi
callq 0x377ed
testl %eax, %eax
jne 0x24e36
testb %r12b, %r12b
jne 0x24d58
movq %rbx, %rdi
callq 0x24ec0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
movq %r15, %rdx
callq 0x38a63
movq 0x18(%rbx), %rdi
pushq $-0x1
popq %rsi
callq 0x37b59
testl %eax, %eax
je 0x24dd4
movq 0x18(%rbx), %rdi
pushq $-0x1
popq %rsi
callq 0x37b59
cmpl $0x5, %eax
je 0x24dad
movq 0x18(%rbx), %rdi
pushq $-0x1
popq %rsi
callq 0x37b59
cmpl $0x6, %eax
jne 0x24de5
movq 0x18(%rbx), %rdi
pushq $-0x1
popq %rsi
callq 0x37b59
cmpl $0x5, %eax
sete 0x20(%rbx)
movq 0x18(%rbx), %rdi
pushq $-0x2
popq %rsi
callq 0x377fa
movb $0x1, %r12b
jmp 0x24d38
movq %r12, %rdi
callq 0x143d2
leaq 0xacce0(%rip), %rsi     # 0xd1ac3
jmp 0x24df4
movq %r12, %rdi
callq 0x143d2
leaq 0xacceb(%rip), %rsi     # 0xd1adf
xorl %r12d, %r12d
movq %r14, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xc007
jmp 0x24d16
movq 0x1091a5(%rip), %rax    # 0x12dfb8
movq (%rax), %rdi
leaq 0xa5249(%rip), %rsi     # 0xca066
leaq 0xacc31(%rip), %rdx     # 0xd1a55
leaq 0xacc04(%rip), %rcx     # 0xd1a2f
leaq 0xacc0c(%rip), %r8      # 0xd1a3e
pushq $0x28
jmp 0x24eb2
movq 0x10917b(%rip), %rax    # 0x12dfb8
movq (%rax), %rdi
leaq 0xa521f(%rip), %rsi     # 0xca066
leaq 0xacc4f(%rip), %rdx     # 0xd1a9d
leaq 0xacbda(%rip), %rcx     # 0xd1a2f
leaq 0xacbe2(%rip), %r8      # 0xd1a3e
pushq $0x5e
jmp 0x24eb2
movq 0x109151(%rip), %rax    # 0x12dfb8
movq (%rax), %rdi
leaq 0xa51f5(%rip), %rsi     # 0xca066
leaq 0xa57e1(%rip), %rdx     # 0xca659
leaq 0xacbb0(%rip), %rcx     # 0xd1a2f
leaq 0xacbb8(%rip), %r8      # 0xd1a3e
pushq $0x27
jmp 0x24eb2
movq 0x109127(%rip), %rax    # 0x12dfb8
movq (%rax), %rdi
leaq 0xa51cb(%rip), %rsi     # 0xca066
leaq 0xacbfb(%rip), %rdx     # 0xd1a9d
leaq 0xacb86(%rip), %rcx     # 0xd1a2f
leaq 0xacb8e(%rip), %r8      # 0xd1a3e
pushq $0x37
popq %r9
xorl %eax, %eax
callq 0xb8c0
callq 0xb300