// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/LuaInterface.cpp
// Function: t2::FindScriptDirectory()
static const char* FindScriptDirectory()
{
  static char script_dir[kMaxPathLength];

  // Check cached value.
  if (script_dir[0] != '\0')
    return script_dir;

  // If TUNDRA_HOME is set, use that value.
  if (char* tmp = getenv("TUNDRA_HOME"))
  {
    PathBuffer dir;
    PathInit(&dir, tmp);
    PathFormat(script_dir, &dir);
    return script_dir;
  }
  else
  {
    // Otherwise we need to try a little harder.
    //
    // Scan the directories from where Tundra is installed upwards to find a
    // scripts/tundra.lua file or a share/tundra.lua file. That is our home
    // directory.
    //
    // This handles both the installed case where tundra is installed to say:
    //
    // /usr/local/bin/t2-lua - we want /use/local/share
    //
    // and the case where the build is being run from the build directory:
    //
    // /a/b/c/build/tundra2 - we want /a/b/c/

    PathBuffer dir;
    PathInit(&dir, GetExePath());

    static const struct Probe
    {
      const char* m_Subdir;
      const char* m_ProbeFile;
    }
    dirs[] =
    {
      { "share/tundra",  "tundra.lua" },
      { "scripts",       "tundra.lua", }
    };

    while (PathStripLast(&dir))
    {
      for (size_t i = 0; i < ARRAY_SIZE(dirs); ++i)
      {
        PathBuffer sdir = dir;
        PathConcat(&sdir, dirs[i].m_Subdir);

        PathBuffer test_file = sdir;
        PathConcat(&test_file, dirs[i].m_ProbeFile);

        char test_file_p[kMaxPathLength];
        PathFormat(test_file_p, &test_file);

        FileInfo info = GetFileInfo(test_file_p);

        if (info.Exists())
        {
          PathFormat(script_dir, &sdir);
          return script_dir;
        }
      }
    }
  }

  Croak("Can't detect script directory.\nTried all directories leading up from %s - please set TUNDRA_HOME.",
      GetExePath());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc70, %rsp            # imm = 0xC70
movsbl 0x5c70e(%rip), %eax     # 0x63680
cmpl $0x0, %eax
je 0x6f87
leaq 0x5c702(%rip), %rax     # 0x63680
movq %rax, -0x8(%rbp)
jmp 0x711e
leaq 0x4631b(%rip), %rdi     # 0x4d2a9
callq 0x65a0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x6fd3
movq -0x10(%rbp), %rsi
leaq -0x29c(%rbp), %rdi
xorl %edx, %edx
callq 0xd180
leaq 0x5c6c9(%rip), %rdi     # 0x63680
leaq -0x29c(%rbp), %rsi
callq 0xd8d0
leaq 0x5c6b6(%rip), %rax     # 0x63680
movq %rax, -0x8(%rbp)
jmp 0x711e
callq 0xc100
movq %rax, %rsi
leaq -0x528(%rbp), %rdi
xorl %edx, %edx
callq 0xd180
leaq -0x528(%rbp), %rdi
callq 0xd680
testb $0x1, %al
jne 0x6ffe
jmp 0x7106
movq $0x0, -0x530(%rbp)
cmpq $0x2, -0x530(%rbp)
jae 0x7101
leaq -0x7bc(%rbp), %rdi
leaq -0x528(%rbp), %rsi
movl $0x28c, %edx            # imm = 0x28C
callq 0x63c0
movq -0x530(%rbp), %rcx
leaq 0x5b0b3(%rip), %rax     # 0x620f0
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
leaq -0x7bc(%rbp), %rdi
callq 0xd6e0
leaq -0xa48(%rbp), %rdi
leaq -0x7bc(%rbp), %rsi
movl $0x28c, %edx            # imm = 0x28C
callq 0x63c0
movq -0x530(%rbp), %rcx
leaq 0x5b077(%rip), %rax     # 0x620f0
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
leaq -0xa48(%rbp), %rdi
callq 0xd6e0
leaq -0xc50(%rbp), %rdi
leaq -0xa48(%rbp), %rsi
callq 0xd8d0
leaq -0xc50(%rbp), %rsi
leaq -0xc68(%rbp), %rdi
callq 0xc450
leaq -0xc68(%rbp), %rdi
callq 0x7e80
testb $0x1, %al
jne 0x70c8
jmp 0x70e8
leaq 0x5c5b1(%rip), %rdi     # 0x63680
leaq -0x7bc(%rbp), %rsi
callq 0xd8d0
leaq 0x5c59e(%rip), %rax     # 0x63680
movq %rax, -0x8(%rbp)
jmp 0x711e
jmp 0x70ea
movq -0x530(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x530(%rbp)
jmp 0x7009
jmp 0x6fe9
jmp 0x7108
callq 0xc100
movq %rax, %rsi
leaq 0x461be(%rip), %rdi     # 0x4d2d5
movb $0x0, %al
callq 0xba60
movq -0x8(%rbp), %rax
addq $0xc70, %rsp            # imm = 0xC70
popq %rbp
retq
nopl (%rax,%rax)