// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/LuaInterpolate.cpp
// Function: t2::LuaEnvLookupScope::LuaEnvLookupScope(t2::LuaEnvLookup&, char const*, unsigned long)
explicit LuaEnvLookupScope(LuaEnvLookup& lookup, const char* key, size_t len)
  {
    m_LuaState = lookup.m_LuaState;
    m_Valid    = false;

    lua_State* L = lookup.m_LuaState;

    // If we have a table of per-call variables, look there first.
    if (int var_table_idx = lookup.m_VarIndex)
    {
      lua_getfield(L, var_table_idx, key);
      if (!lua_isnil(L, -1))
      {
        if (LUA_TTABLE != lua_type(L, -1))
        {
          lua_newtable(L);
          lua_pushvalue(L, -2);
          lua_rawseti(L, -2, 1);
          lua_replace(L, -2);
        }
        m_Count = lua_objlen(L, -1);
        m_Valid = true;
        return;
      }
      else
      {
        lua_pop(L, 1);
      }
    }

    // Next, walk through the environment tables. 
    lua_pushvalue(L, lookup.m_EnvIndex);
    while (!lua_isnil(L, -1))
    {
      lua_getfield(L, -1, "parent");
      lua_getfield(L, -2, "vars");
      // remove env table index from stack, replace it with its parent table
      lua_remove(L, -3);

      lua_getfield(L, -1, key);
      if (!lua_isnil(L, -1))
      {
        luaL_checktype(L, -1, LUA_TTABLE);
        lua_remove(L, -3);
        lua_remove(L, -2);
        m_Count = lua_objlen(L, -1);
        m_Valid = true;
        return;
      }

      // Pop nil value, and vars table. Leaving us with next table to try.
      lua_pop(L, 2);
    }
    // Pop nil table.
    lua_pop(L, 1);

    luaL_error(L, "No key '%s' present in environment", key);
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movb $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x8e07
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x2abe0
movq -0x28(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x29e70
cmpl $0x0, %eax
je 0x8df7
movq -0x28(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x29e70
movl %eax, %ecx
movl $0x5, %eax
cmpl %ecx, %eax
je 0x8dd5
movq -0x28(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x2ad70
movq -0x28(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x29e10
movq -0x28(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movl $0x1, %edx
callq 0x2b1a0
movq -0x28(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x29c80
movq -0x28(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2a3d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movb $0x1, 0x8(%rax)
jmp 0x8f18
movq -0x28(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x29940
jmp 0x8e07
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x29e10
movq -0x28(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x29e70
cmpl $0x0, %eax
sete %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x8e36
jmp 0x8ef4
movq -0x28(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x446f8(%rip), %rdx     # 0x4d53e
callq 0x2abe0
movq -0x28(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0x446ea(%rip), %rdx     # 0x4d545
callq 0x2abe0
movq -0x28(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x299d0
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2abe0
movq -0x28(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x29e70
cmpl $0x0, %eax
je 0x8ee1
movq -0x28(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x5, %edx
callq 0x2c500
movq -0x28(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x299d0
movq -0x28(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x299d0
movq -0x28(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2a3d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movb $0x1, 0x8(%rax)
jmp 0x8f18
movq -0x28(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x29940
jmp 0x8e17
movq -0x28(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x29940
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x44639(%rip), %rsi     # 0x4d54a
movb $0x0, %al
callq 0x2c000
addq $0x40, %rsp
popq %rbp
retq
nop