// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
movq (%rsi), %r14
movq %r14, (%rdi)
movb $0x0, 0x8(%rdi)
movl 0xc(%rsi), %esi
testl %esi, %esi
je 0x806f
movq %r14, %rdi
movq %r15, %rdx
callq 0x18977
pushq $-0x1
popq %rsi
movq %r14, %rdi
callq 0x18318
testl %eax, %eax
je 0x8064
pushq $-0x1
popq %rsi
movq %r14, %rdi
callq 0x18318
cmpl $0x5, %eax
je 0x8049
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x18a30
pushq $-0x2
popq %rbx
movq %r14, %rdi
movl %ebx, %esi
callq 0x182f8
pushq $0x1
popq %rdx
movq %r14, %rdi
movl %ebx, %esi
callq 0x18c13
movq %r14, %rdi
movl %ebx, %esi
callq 0x1823c
pushq $-0x1
popq %rsi
movq %r14, %rdi
callq 0x185ab
movq %rax, 0x10(%r12)
movb $0x1, 0x8(%r12)
jmp 0x8157
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x180d8
movq %r12, (%rsp)
movl 0x8(%rbx), %esi
movq %r14, %rdi
callq 0x182f8
pushq $-0x1
popq %rbp
leaq 0x243ed(%rip), %r13     # 0x2c475
pushq $-0x2
popq %rbx
pushq $-0x3
popq %r12
movq %r14, %rdi
movl %ebp, %esi
callq 0x18318
testl %eax, %eax
je 0x80ee
movq %r14, %rdi
movl %ebp, %esi
leaq 0x243c5(%rip), %rdx     # 0x2c46e
callq 0x18977
movq %r14, %rdi
movl %ebx, %esi
movq %r13, %rdx
callq 0x18977
movq %r14, %rdi
movl %r12d, %esi
callq 0x18117
movq %r14, %rdi
movl %ebp, %esi
movq %r15, %rdx
callq 0x18977
movq %r14, %rdi
movl %ebp, %esi
callq 0x18318
testl %eax, %eax
jne 0x811b
movq %r14, %rdi
movl %r12d, %esi
callq 0x180d8
jmp 0x808f
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x180d8
leaq 0x2437a(%rip), %rsi     # 0x2c47a
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x19357
pushq $-0x1
popq %rbx
pushq $0x5
popq %rdx
movq %r14, %rdi
movl %ebx, %esi
callq 0x196cc
pushq $-0x3
popq %rsi
movq %r14, %rdi
callq 0x18117
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x18117
movq %r14, %rdi
movl %ebx, %esi
callq 0x185ab
movq (%rsp), %rcx
movq %rax, 0x10(%rcx)
movb $0x1, 0x8(%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq