// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/LuaInterface.cpp
// Function: t2::LuaListDirectory(lua_State*)
static int LuaListDirectory(lua_State* L)
{
  const char* dir = luaL_checkstring(L, 1);

  // Push dir result table on stack
  lua_newtable(L);
  // Push file result table on stack
  lua_newtable(L);

  ListDirectory(dir, L, OnFileIter);

  // Sort both tables
  lua_getglobal(L, "table");
  lua_getfield(L, -1, "sort");

  // Sort dirs
  // stack here: dirs, files, table package, table.sort
  lua_pushvalue(L, -1); // table.sort
  lua_pushvalue(L, -5);
  lua_call(L, 1, 0);

  // Sort files
  // stack here: dirs, files, table package, table.sort
  lua_pushvalue(L, -1); // table.sort
  lua_pushvalue(L, -4);
  lua_call(L, 1, 0);

  lua_pop(L, 2);

  // stack here: dirs, files

  // Compute directory listing hash digest for signature purposes
  HashState h;
  HashInit(&h);

  // Hash directories
  for (size_t i = 1, count = lua_objlen(L, -2); i <= count; ++i)
  {
    lua_rawgeti(L, -2, (int) i);
    HashAddString(&h, lua_tostring(L, -1));
    HashAddSeparator(&h);
    lua_pop(L, 1);
  }

  // Hash files
  for (size_t i = 1, count = lua_objlen(L, -1); i <= count; ++i)
  {
    lua_rawgeti(L, -1, (int) i);
    HashAddString(&h, lua_tostring(L, -1));
    HashAddSeparator(&h);
    lua_pop(L, 1);
  }

  HashDigest digest;
  HashFinalize(&h, &digest);

  lua_pushlstring(L, (char*)digest.m_Data, sizeof digest.m_Data);

  return 3;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2c330
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x2ad70
movq -0x8(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x2ad70
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
leaq 0x7f2(%rip), %rdx       # 0x7c80
callq 0xc6a0
movq -0x8(%rbp), %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
leaq 0x48a70(%rip), %rdx     # 0x4ff13
callq 0x2abe0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x45d36(%rip), %rdx     # 0x4d1ee
callq 0x2abe0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x29e10
movq -0x8(%rbp), %rdi
movl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
callq 0x29e10
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2b4d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x29e10
movq -0x8(%rbp), %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
callq 0x29e10
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2b4d0
movq -0x8(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x29940
leaq -0xb0(%rbp), %rdi
callq 0xcb60
movq $0x1, -0xb8(%rbp)
movq -0x8(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x2a3d0
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rax
cmpq -0xc0(%rbp), %rax
ja 0x75c5
movq -0x8(%rbp), %rdi
movq -0xb8(%rbp), %rax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x2acf0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x2a310
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x7e00
leaq -0xb0(%rbp), %rdi
callq 0xcd70
movq -0x8(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x29940
movq -0xb8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb8(%rbp)
jmp 0x754f
movq $0x1, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2a3d0
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rax
cmpq -0xd0(%rbp), %rax
ja 0x765b
movq -0x8(%rbp), %rdi
movq -0xc8(%rbp), %rax
movl %eax, %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2acf0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x2a310
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x7e00
leaq -0xb0(%rbp), %rdi
callq 0xcd70
movq -0x8(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x29940
movq -0xc8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc8(%rbp)
jmp 0x75e5
leaq -0xb0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xcbb0
movq -0x8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
movl $0x10, %edx
callq 0x2a720
movl $0x3, %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)