// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/LuaInterface.cpp
// Function: t2::CreateLuaState(t2::MemAllocHeap*, bool)
lua_State* CreateLuaState(MemAllocHeap* lua_heap, bool profile)
{
  lua_State* L = lua_newstate(LuaAllocFunc, lua_heap);

  if (profile)
  {
    s_IsProfiling = true;
    LinearAllocInit(&s_ProfilerAllocator, lua_heap, 512 * 1024, "Profiler Allocator");
    LuaProfilerInit(lua_heap, &s_ProfilerAllocator, L); 
  }

  if (!L)
    Croak("couldn't create Lua state");

  // Install panic function.
  lua_atpanic(L, OnLuaPanic);

  // Expose standard Lua libraries.
  luaL_openlibs(L);

  // Expose interpolation module
  LuaEnvNativeOpen(L);

  // Expose path module
  LuaPathNativeOpen(L);

  // Expose JSON writer module
  LuaJsonNativeOpen(L);

  luaL_register(L, "tundra.native", s_LuaFunctions);
  lua_pushstring(L, TUNDRA_PLATFORM_STRING);
  lua_setfield(L, -2, "host_platform");

  // setup package.path
  {
    const char* homedir = FindScriptDirectory();
    const char* luapath = getenv("TUNDRA_LUA_PATH");
    char ppath[1024];
    snprintf(ppath, sizeof(ppath), "%s" TD_PATHSEP_STR "?.lua;%s", homedir, (luapath ? luapath : ""));
    lua_getglobal(L, "package");
    CHECK(LUA_TTABLE == lua_type(L, -1));

    lua_pushstring(L, ppath);
    lua_setfield(L, -2, "path");

    lua_pushstring(L, homedir);
    lua_setglobal(L, "TundraScriptDir");
  }

  /* native table on the top of the stack */
  lua_pop(L, 1);

  Log(kDebug, "Lua initialized successfully");
  return L;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rsi
leaq 0x1de(%rip), %rdi       # 0x6eb0
callq 0x3b7e0
movq %rax, -0x18(%rbp)
testb $0x1, -0x9(%rbp)
je 0x6d18
movb $0x1, 0x5c958(%rip)     # 0x63640
movq -0x8(%rbp), %rsi
leaq 0x5c955(%rip), %rdi     # 0x63648
movl $0x80000, %edx          # imm = 0x80000
leaq 0x4636b(%rip), %rcx     # 0x4d06a
callq 0xcf80
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x5c935(%rip), %rsi     # 0x63648
callq 0xa8b0
cmpq $0x0, -0x18(%rbp)
jne 0x6d2d
leaq 0x46357(%rip), %rdi     # 0x4d07d
movb $0x0, %al
callq 0xba60
movq -0x18(%rbp), %rdi
leaq 0x208(%rip), %rsi       # 0x6f40
callq 0x29850
movq -0x18(%rbp), %rdi
callq 0x33a10
movq -0x18(%rbp), %rdi
callq 0x7ec0
movq -0x18(%rbp), %rdi
callq 0xa2a0
movq -0x18(%rbp), %rdi
callq 0x9b10
movq -0x18(%rbp), %rdi
leaq 0x4632b(%rip), %rsi     # 0x4d097
leaq 0x5b29d(%rip), %rdx     # 0x62010
callq 0x2c850
movq -0x18(%rbp), %rdi
leaq 0x46322(%rip), %rsi     # 0x4d0a5
callq 0x2a7a0
movq -0x18(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0x46313(%rip), %rdx     # 0x4d0ab
callq 0x2b030
callq 0x6f60
movq %rax, -0x20(%rbp)
leaq 0x4630c(%rip), %rdi     # 0x4d0b9
callq 0x65a0
movq %rax, -0x28(%rbp)
leaq -0x430(%rbp), %rax
movq %rax, -0x440(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x438(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6de3
movq -0x28(%rbp), %rax
movq %rax, -0x448(%rbp)
jmp 0x6df3
leaq 0x491e0(%rip), %rax     # 0x4ffca
movq %rax, -0x448(%rbp)
jmp 0x6df3
movq -0x438(%rbp), %rcx
movq -0x440(%rbp), %rdi
movq -0x448(%rbp), %r8
movl $0x400, %esi            # imm = 0x400
leaq 0x462b5(%rip), %rdx     # 0x4d0c9
movb $0x0, %al
callq 0x6740
movq -0x18(%rbp), %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
leaq 0x462aa(%rip), %rdx     # 0x4d0d5
callq 0x2abe0
jmp 0x6e32
movq -0x18(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0x2a7a0
movq -0x18(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0x46873(%rip), %rdx     # 0x4d6c5
callq 0x2b030
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2a7a0
movq -0x18(%rbp), %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
leaq 0x46269(%rip), %rdx     # 0x4d0dd
callq 0x2b030
movq -0x18(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x29940
movl $0x8, %edi
leaq 0x4625a(%rip), %rsi     # 0x4d0ed
movb $0x0, %al
callq 0xbf20
movq -0x18(%rbp), %rax
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
nopw (%rax,%rax)