// File: /workspace/github_cpp_makefile_star2_O2/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, (%rsp)
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x77d4(%rip), %rdx      # 0xe420
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x8808
testq %r14, %r14
je 0x6c62
andq $0x0, (%r14)
pushq $0x2f
popq %rsi
pushq $-0x1
popq %rdx
movq %r13, %rdi
callq 0x31d0
leaq 0x1(%rax), %rcx
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x32e0
leaq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rbp
movq 0x8(%r13), %r15
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x72e8
movq (%rbx), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3290
cmpl $-0x1, %eax
je 0x6d15
movl 0xa0(%rsp), %eax
btl $0xe, %eax
jb 0x6cc6
testw %ax, %ax
jns 0x6d15
jmp 0x6d24
cmpq %r15, %rbp
jne 0x6d67
leaq 0x260a(%rip), %rdx      # 0x92e0
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x7320
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x8170
leaq 0x48(%rsp), %r12
movq (%rsp), %rdi
movq %r12, %rsi
callq 0x3380
movq %r12, %rdi
callq 0x35d8
leaq 0x28(%rsp), %rdi
callq 0x35d8
leaq 0x2444(%rip), %rsi      # 0x9160
movq %rbx, %rdi
callq 0x3570
testq %r14, %r14
je 0x6d3e
testb $0x40, 0xa1(%rsp)
jne 0x6d3e
movq 0xe0(%rsp), %rax
movq %rax, (%r14)
leaq 0x8(%rsp), %rdi
callq 0x35d8
leaq 0x68(%rsp), %rdi
callq 0x35d8
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x6dda
leaq 0x48(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3380
movq %r15, %rdi
callq 0x35d8
jmp 0x6d24
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x35d8
jmp 0x6dac
jmp 0x6da9
jmp 0x6da9
movq %rax, %r14
movq %rbx, %rdi
callq 0x35d8
jmp 0x6db9
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x35d8
jmp 0x6dc8
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x35d8
movq %r14, %rdi
callq 0x3510