// File: /workspace/github_cpp_makefile_star2_O2/tylerkaraszewski[P]Argyle/FilenameResolver.cpp
// Function: FilenameResolver::findNewestInDir(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Config const&)
string FilenameResolver::findNewestInDir(const std::string& webPath, const Config& config)
{
  string basePath = config.getString(Config::S_KEY_BASE_PATH);
  string fullPath = basePath + webPath;
  char * name = 0;
  DIR * cwd = opendir(fullPath.c_str());
  struct dirent * entry;
  time_t timestamp = 0;

  struct tm time;
  time.tm_sec = 0;
  time.tm_min = 0;
  time.tm_hour = 12;
  time.tm_wday = 0;
  time.tm_yday = 0;
  time.tm_isdst = 0;

  while((entry = readdir(cwd)))
  {
    // Skip files that are too short to count.
    if(strlen(entry->d_name) < 10)
    {
      continue;
    }

    int day = atoi(entry->d_name + 8);
    int mon = atoi(entry->d_name + 5);
    int year = atoi(entry->d_name);

    // Sanity check.
    if ((year < 1900) || (year > 2500) || (mon < 1) || (mon > 12))
    {
      continue;
    }

    // Because of how these are stored in a struct tm.
    mon--;
    year -= 1900;

    // Parse our date.
    time.tm_mday = day;
    time.tm_mon = mon;
    time.tm_year = year;

    time_t filestamp = mktime(&time);
    if(filestamp > timestamp)
    {
        timestamp = filestamp;
        name = entry->d_name;
    }
  }

  closedir(cwd);
  if (name != 0)
  {
    return fullPath + "/" + name;
  }
  return "";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %rbx
movq %rdi, 0x18(%rsp)
leaq 0x74ee(%rip), %rax      # 0xe420
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0x8808
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x72e8
movq 0x40(%rsp), %rdi
callq 0x3430
leaq 0x80(%rsp), %r15
andq $0x0, (%r15)
movl $0xc, 0x8(%r15)
andq $0x0, 0x18(%r15)
andl $0x0, 0x20(%r15)
movq %rax, %r12
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %r12, %rdi
callq 0x3450
movq %rax, %rbp
testq %rax, %rax
je 0x7041
leaq 0x13(%rbp), %r13
movq %r13, %rdi
callq 0x3150
cmpq $0xa, %rax
jb 0x6f92
leaq 0x18(%rbp), %rdi
callq 0x3470
movl %eax, %ebx
movq %r13, %rdi
callq 0x3470
movl %eax, %r14d
leal -0x9c5(%r14), %eax
cmpl $0xfffffda7, %eax       # imm = 0xFFFFFDA7
setb %al
leal -0xd(%rbx), %ecx
cmpl $-0xc, %ecx
setb %cl
orb %al, %cl
jne 0x6f92
addq $0x1b, %rbp
movq %rbp, %rdi
callq 0x3470
decl %ebx
addl $0xfffff894, %r14d      # imm = 0xFFFFF894
movl %eax, 0x8c(%rsp)
movl %ebx, 0x90(%rsp)
movl %r14d, 0x94(%rsp)
movq %r15, %rdi
callq 0x31c0
movq 0x10(%rsp), %rdx
cmpq %rdx, %rax
movq 0x8(%rsp), %rcx
cmovgq %r13, %rcx
movq %rcx, 0x8(%rsp)
cmovgq %rax, %rdx
movq %rdx, 0x10(%rsp)
jmp 0x6f92
movq %r12, %rdi
callq 0x34b0
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x708a
leaq 0x2286(%rip), %rdx      # 0x92e0
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x7320
movq 0x18(%rsp), %rbx
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x42dc
leaq 0x20(%rsp), %rdi
callq 0x35d8
jmp 0x70a3
leaq 0x20cf(%rip), %rsi      # 0x9160
leaq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x438c
leaq 0x40(%rsp), %rdi
callq 0x35d8
leaq 0x60(%rsp), %rdi
callq 0x35d8
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x70e4
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x35d8
jmp 0x70e7
jmp 0x70e4
movq %rax, %rbx
jmp 0x70f1
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x35d8
leaq 0x60(%rsp), %rdi
callq 0x35d8
movq %rbx, %rdi
callq 0x3510
nop