// File: /workspace/github_cpp_makefile_star2_O1/tylerkaraszewski[P]Argyle/FilenameResolver.cpp
// Function: FilenameResolver::resolve(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Config const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, long*)
string FilenameResolver::resolve(const string& webPath, const Config& config, string& redirectPath, time_t* mtime)
{
  string basePath = config.getString(Config::S_KEY_BASE_PATH);

  if (mtime != NULL)
  {
    *mtime = 0; // We'll set this to something useful later if we can. Setting it to 0 implies "N/A".
  }

  bool needToRedirectIfDir = false;
  // Trim trailing slashes.
  string processedWebPath = webPath.substr(0, webPath.find_last_not_of('/') + 1);
  if (processedWebPath.size() == webPath.size())
  {
    // Nothing was stripped, indicating if a directory, it was requested like a file.
    needToRedirectIfDir = true;
  }
  string fullPath = basePath + processedWebPath;

  // Look our path to see if it exists, and if so, what we should do with it.
  struct stat fileStat;
  if(stat(fullPath.c_str(), &fileStat) == -1)
  {
    fullPath = "";
  }

  // Is it a directory?
  else if (fileStat.st_mode & S_IFDIR)
  {
    if (needToRedirectIfDir)
    {
      redirectPath = Utils::UriEscape(webPath + "/");
      fullPath = "";
    }
    else
    {
      fullPath = resolveDir(processedWebPath, config, mtime);
    }
  }

  // Is it something besides a normal file?
  else if (!(fileStat.st_mode & S_IFREG))
  {
    fullPath = "";
  }

  // Report our modified time if the caller gave us a place to put it (and if we're not operating on a directory)
  // If we are looking at a directory, resolveDir should have already set this if it resolved to a particular file.
  // If it's a 404, we want to leave it blank anyway.
  if ((mtime != NULL) && !(fileStat.st_mode & S_IFDIR))
  {
    *mtime = fileStat.st_mtime;
  }

  // Normal files need no special handling.
  return fullPath;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r8, %r14
movq %rcx, 0x20(%rsp)
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x7953(%rip), %rdx      # 0x10408
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0xb59a
testq %r14, %r14
je 0x8ace
movq $0x0, (%r14)
movq %r13, %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x31c0
leaq 0x1(%rax), %rcx
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x32b0
leaq 0x48(%rsp), %rdx
movq 0x8(%rdx), %rbp
movq 0x8(%r13), %r15
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x93e3
movq (%rbx), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3250
cmpl $-0x1, %eax
je 0x8bc7
movl 0xa0(%rsp), %eax
btl $0xe, %eax
jb 0x8b43
testw %ax, %ax
jns 0x8bc7
jmp 0x8bdf
cmpq %r15, %rbp
jne 0x8c44
leaq 0x10(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x773e
leaq 0x376a(%rip), %rsi      # 0xc2d9
movq %rsp, %rdi
callq 0x3560
leaq 0x28(%rsp), %rdi
movq %rsp, %rsi
callq 0xacb4
leaq 0x28(%rsp), %r12
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x3360
movq (%r12), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x8bb1
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0x8bc7
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x8(%rbx), %rdx
leaq 0x358e(%rip), %rcx      # 0xc160
movq %rbx, %rdi
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x3440
testq %r14, %r14
je 0x8bf9
testb $0x40, 0xa1(%rsp)
jne 0x8bf9
movq 0xe0(%rsp), %rax
movq %rax, (%r14)
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8c14
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8c2f
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x8d10
leaq 0x28(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3360
movq (%r15), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x8bdf
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x8bdf
jmp 0x8c8e
movq %rax, %r14
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0x8cb0
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x8cb0
jmp 0x8cad
jmp 0x8cad
movq %rax, %r14
movq (%rbx), %rdi
addq $0x10, %rbx
cmpq %rbx, %rdi
je 0x8ccc
movq (%rbx), %rsi
incq %rsi
callq 0x3290
jmp 0x8ccc
movq %rax, %r14
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8cec
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x8cec
movq %rax, %r14
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8d07
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
movq %r14, %rdi
callq 0x3520
nop