// File: /workspace/github_cpp_makefile_star2_O3/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 $0xa8, %rsp
movq %rsi, %rbx
movq %rdi, %r12
leaq 0x7566(%rip), %rax      # 0x10408
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0xb516
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x937b
movq 0x30(%rsp), %rdi
callq 0x3400
movq %rax, %r15
xorl %r14d, %r14d
leaq 0x70(%rsp), %rax
movq %r14, (%rax)
movl $0xc, 0x8(%rax)
movq %r14, 0x18(%rax)
movl $0x0, 0x20(%rax)
movq $0x0, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, %rdi
callq 0x3430
movq %rax, %rbp
testq %rax, %rax
je 0x8f9f
leaq 0x13(%rbp), %r13
movq %r13, %rdi
callq 0x3160
cmpq $0xa, %rax
jb 0x8efc
leaq 0x18(%rbp), %rdi
callq 0x3460
movl %eax, %ebx
movq %r13, %rdi
callq 0x3460
movl %eax, %r12d
leal -0x9c5(%r12), %eax
cmpl $0xfffffda7, %eax       # imm = 0xFFFFFDA7
setb %al
leal -0xd(%rbx), %ecx
cmpl $-0xc, %ecx
setb %cl
orb %al, %cl
jne 0x8efc
addq $0x1b, %rbp
movq %rbp, %rdi
callq 0x3460
decl %ebx
addl $0xfffff894, %r12d      # imm = 0xFFFFF894
movl %eax, 0x7c(%rsp)
movl %ebx, 0x80(%rsp)
movl %r12d, 0x84(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x31b0
movq (%rsp), %rcx
cmpq %rcx, %rax
cmovgq %r13, %r14
cmovgq %rax, %rcx
movq %rcx, (%rsp)
jmp 0x8efc
movq %r15, %rdi
callq 0x3490
testq %r14, %r14
je 0x9011
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0x76da
movq 0x8(%rsp), %rbx
leaq 0x3301(%rip), %rsi      # 0xc2d9
leaq 0x10(%rsp), %rdi
callq 0x3560
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x3560
leaq 0x10(%rbx), %rdx
movq %rdx, (%rbx)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x9031
movq %rsi, (%rbx)
movq (%rcx), %rdx
movq %rdx, 0x10(%rbx)
jmp 0x9037
movq 0x8(%rsp), %rbx
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x313c(%rip), %rdx      # 0xc160
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x513a
jmp 0x9065
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rbx)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x9065
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9080
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x909b
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x90d7
jmp 0x90b4
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x90da
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x90da
jmp 0x90d7
movq %rax, %rbx
jmp 0x90f5
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x90f5
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9110
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq %rbx, %rdi
callq 0x3520