// File: /workspace/github_c_makefile_star2_O3/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 0x48203
movq %r14, %rdi
callq 0x34fea
testb %al, %al
jne 0x483cb
testq %r12, %r12
je 0x483c6
testq %r15, %r15
je 0x483c6
leaq 0xa0832(%rip), %rsi     # 0xe8a4e
movl $0x28, %edi
movl $0x2a, %edx
callq 0x35862
movq %rax, %rbx
movq %r12, %rdi
callq 0x3bcaf
movq %rax, (%rbx)
movq %r15, %rdi
callq 0x728c0
movq %rax, 0x8(%rbx)
movl %ebp, 0x10(%rbx)
callq 0x5b65a
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x482d1
movq %rax, %rdi
callq 0x5ba88
movq 0x18(%rbx), %rdi
callq 0x56afc
testl %eax, %eax
jne 0x483d0
movq 0x18(%rbx), %r13
movq %r12, %rdi
callq 0x3bb5d
movq %r13, %rdi
movq %rax, %rsi
callq 0x5b1f2
testl %eax, %eax
jne 0x4829d
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x588cb
testl %eax, %eax
je 0x4830f
movq 0x18(%rbx), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x573f8
leaq 0xa080b(%rip), %rsi     # 0xe8abf
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x34f1f
movq 0x18(%rbx), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x56b09
jmp 0x482e2
leaq 0xa07a9(%rip), %rsi     # 0xe8a81
movq %r14, %rdi
xorl %eax, %eax
callq 0x34f1f
movq 0x18(%rbx), %rdi
callq 0x56afc
testl %eax, %eax
jne 0x4838c
movq %rbx, %rdi
callq 0x483d5
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 0x57f56
movq 0x18(%rbx), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x56f9b
testl %eax, %eax
je 0x48391
movq 0x18(%rbx), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x56f9b
cmpl $0x5, %eax
je 0x48358
movq 0x18(%rbx), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x56f9b
cmpl $0x6, %eax
jne 0x483a2
movq 0x18(%rbx), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x56f9b
cmpl $0x5, %eax
sete 0x20(%rbx)
movq 0x18(%rbx), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x56b09
movq 0x18(%rbx), %rdi
callq 0x56afc
testl %eax, %eax
je 0x482fd
callq 0x13516
movq %r12, %rdi
callq 0x3bb5d
leaq 0xa0733(%rip), %rsi     # 0xe8ad3
jmp 0x483b1
movq %r12, %rdi
callq 0x3bb5d
leaq 0xa073e(%rip), %rsi     # 0xe8aef
movq %r14, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x34f1f
jmp 0x482c1
callq 0x134a8
callq 0x13471
callq 0x134df