#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef unsigned long uint32_t;
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ EBADF;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strrchr(char *, char);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int FindNextTimestampedFile(char *directory, char *file_prefix,
                            uint32_t timestamp, int mode,
                            uint32_t *next_timestamp) {
  DIR *dir = NULL;
  struct dirent *entry;
  unsigned long file_timestamp;
  unsigned long selected_timestamp = 0;
  char *extension;
  if (!directory || !file_prefix)
    return 1;
  if (!(dir = opendir(directory))) {
    fprintf(stderr, "Unable to open directory '%s': %s", directory,
            strerror(errno));
    return 38;
  }
  errno = 0;
  while ((entry = readdir(dir))) {
    char *ts_test = NULL;
    if (strncmp(entry->d_name, file_prefix, strlen(file_prefix)) != 0) {
      continue;
    }
    ts_test = entry->d_name + strlen(file_prefix);
    if (ts_test && !isdigit(ts_test[0])) {
      continue;
    }
    ts_test = strrchr(entry->d_name, '.');
    if (ts_test && !isdigit(ts_test[1])) {
      fprintf(stderr, "Skip validating file '%s' (%s)", entry->d_name, ts_test);
      continue;
    }
    extension = entry->d_name + strlen(file_prefix);
    if ((file_timestamp = strtoul(extension, NULL, 10)) == 0) {
      fprintf(stderr, "Failed to extract timestamp from '%s'", entry->d_name);
      continue;
    }
    if (mode == 2) {
      if (file_timestamp < timestamp)
        continue;
      if ((selected_timestamp != 0) && file_timestamp > selected_timestamp)
        continue;
      selected_timestamp = file_timestamp;
    } else if (mode == 1) {
      if (file_timestamp <= timestamp)
        continue;
      if ((selected_timestamp != 0) && file_timestamp > selected_timestamp)
        continue;
      selected_timestamp = file_timestamp;
    } else {
      if (selected_timestamp == 0) {
        selected_timestamp = file_timestamp;
        continue;
      }
      if (file_timestamp > timestamp) {
        if (selected_timestamp > file_timestamp) {
          selected_timestamp = file_timestamp;
        }
      } else {
        if (selected_timestamp <= file_timestamp) {
          selected_timestamp = file_timestamp;
        }
      }
    }
  }
  if (errno == EBADF) {
    fprintf(stderr, "Error reading directory %s", strerror(errno));
    closedir(dir);
    return 20;
  }
  closedir(dir);
  if (selected_timestamp == 0)
    return 6;
  if (next_timestamp)
    *next_timestamp = selected_timestamp;
  return 0;
}


x86 assembly (clang, -O0):
<FindNextTimestampedFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e4 <FindNextTimestampedFile+0x44>
cmpq   $0x0,-0x18(%rbp)
jne    11f0 <FindNextTimestampedFile+0x50>
movl   $0x1,-0x4(%rbp)
jmp    156a <FindNextTimestampedFile+0x3ca>
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    124e <FindNextTimestampedFile+0xae>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x26,-0x4(%rbp)
jmp    156a <FindNextTimestampedFile+0x3ca>
mov    0x2d83(%rip),%rax
movq   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     14c9 <FindNextTimestampedFile+0x329>
movq   $0x0,-0x60(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12b5 <FindNextTimestampedFile+0x115>
jmp    125c <FindNextTimestampedFile+0xbc>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     1304 <FindNextTimestampedFile+0x164>
mov    -0x60(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    1304 <FindNextTimestampedFile+0x164>
jmp    125c <FindNextTimestampedFile+0xbc>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     1361 <FindNextTimestampedFile+0x1c1>
mov    -0x60(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    1361 <FindNextTimestampedFile+0x1c1>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rax
mov    (%rax),%rdx
mov    -0x60(%rbp),%rcx
lea    0xccd(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    125c <FindNextTimestampedFile+0xbc>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x90(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10b0 <strtoul@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    13ce <FindNextTimestampedFile+0x22e>
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rax
mov    (%rax),%rdx
lea    0xc7f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    125c <FindNextTimestampedFile+0xbc>
cmpl   $0x2,-0x24(%rbp)
jne    1416 <FindNextTimestampedFile+0x276>
mov    -0x48(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    13eb <FindNextTimestampedFile+0x24b>
jmp    125c <FindNextTimestampedFile+0xbc>
cmpq   $0x0,-0x50(%rbp)
je     1409 <FindNextTimestampedFile+0x269>
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jbe    1409 <FindNextTimestampedFile+0x269>
jmp    125c <FindNextTimestampedFile+0xbc>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    14c4 <FindNextTimestampedFile+0x324>
cmpl   $0x1,-0x24(%rbp)
jne    145e <FindNextTimestampedFile+0x2be>
mov    -0x48(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     1433 <FindNextTimestampedFile+0x293>
jmp    125c <FindNextTimestampedFile+0xbc>
cmpq   $0x0,-0x50(%rbp)
je     1451 <FindNextTimestampedFile+0x2b1>
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jbe    1451 <FindNextTimestampedFile+0x2b1>
jmp    125c <FindNextTimestampedFile+0xbc>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    14bf <FindNextTimestampedFile+0x31f>
cmpq   $0x0,-0x50(%rbp)
jne    1476 <FindNextTimestampedFile+0x2d6>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    125c <FindNextTimestampedFile+0xbc>
mov    -0x48(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    149f <FindNextTimestampedFile+0x2ff>
mov    -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
jbe    149a <FindNextTimestampedFile+0x2fa>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    14ba <FindNextTimestampedFile+0x31a>
mov    -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
ja     14b5 <FindNextTimestampedFile+0x315>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    14ba <FindNextTimestampedFile+0x31a>
jmp    14bf <FindNextTimestampedFile+0x31f>
jmp    14c4 <FindNextTimestampedFile+0x324>
jmp    125c <FindNextTimestampedFile+0xbc>
mov    0x2b08(%rip),%rax
mov    (%rax),%rax
mov    0x2af6(%rip),%rcx
cmp    (%rcx),%rax
jne    152d <FindNextTimestampedFile+0x38d>
mov    0x2af6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2adf(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
lea    0xb56(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x14,-0x4(%rbp)
jmp    156a <FindNextTimestampedFile+0x3ca>
mov    -0x38(%rbp),%rdi
call   1080 <closedir@plt>
cmpq   $0x0,-0x50(%rbp)
jne    154d <FindNextTimestampedFile+0x3ad>
movl   $0x6,-0x4(%rbp)
jmp    156a <FindNextTimestampedFile+0x3ca>
cmpq   $0x0,-0x30(%rbp)
je     1563 <FindNextTimestampedFile+0x3c3>
mov    -0x50(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindNextTimestampedFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,(%rsp)
mov    $0x1,%eax
test   %rdi,%rdi
je     1409 <FindNextTimestampedFile+0x269>
mov    %rsi,%rbp
test   %rsi,%rsi
je     1409 <FindNextTimestampedFile+0x269>
mov    %r8,%r15
mov    %ecx,%r12d
mov    %rdi,%rbx
call   1050 <opendir@plt>
test   %rax,%rax
je     1369 <FindNextTimestampedFile+0x1c9>
mov    %rax,%r14
mov    %r12d,0xc(%rsp)
mov    %r15,0x10(%rsp)
mov    0x2de1(%rip),%rax
movq   $0x0,(%rax)
mov    %r14,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     139e <FindNextTimestampedFile+0x1fe>
mov    %rax,%r13
xor    %r12d,%r12d
jmp    125a <FindNextTimestampedFile+0xba>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xe16(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rbx
mov    %r14,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r13
mov    %rbx,%r12
test   %rax,%rax
je     13a0 <FindNextTimestampedFile+0x200>
mov    0x0(%r13),%rbx
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1240 <FindNextTimestampedFile+0xa0>
mov    0x0(%r13),%rbx
mov    %rbp,%rdi
call   1060 <strlen@plt>
test   %rbx,%rbx
je     1298 <FindNextTimestampedFile+0xf8>
cltq
movsbl (%rbx,%rax,1),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     1240 <FindNextTimestampedFile+0xa0>
mov    0x0(%r13),%r15
mov    %r15,%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     12c2 <FindNextTimestampedFile+0x122>
mov    %rax,%rbx
movsbl 0x1(%rax),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     12ff <FindNextTimestampedFile+0x15f>
mov    0x0(%r13),%r15
mov    %rbp,%rdi
call   1060 <strlen@plt>
movslq %eax,%rdi
add    %r15,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10b0 <strtoul@plt>
test   %rax,%rax
je     1217 <FindNextTimestampedFile+0x77>
mov    0xc(%rsp),%ecx
cmp    $0x1,%ecx
je     1322 <FindNextTimestampedFile+0x182>
cmp    $0x2,%ecx
jne    133f <FindNextTimestampedFile+0x19f>
cmp    (%rsp),%rax
jb     1240 <FindNextTimestampedFile+0xa0>
jmp    132c <FindNextTimestampedFile+0x18c>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xd0f(%rip),%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1240 <FindNextTimestampedFile+0xa0>
cmp    (%rsp),%rax
jbe    1240 <FindNextTimestampedFile+0xa0>
test   %r12,%r12
je     1361 <FindNextTimestampedFile+0x1c1>
mov    %r12,%rbx
cmp    %r12,%rax
ja     1243 <FindNextTimestampedFile+0xa3>
jmp    1361 <FindNextTimestampedFile+0x1c1>
mov    %rax,%rbx
test   %r12,%r12
je     1243 <FindNextTimestampedFile+0xa3>
cmp    (%rsp),%rax
jbe    135a <FindNextTimestampedFile+0x1ba>
cmp    %rax,%r12
cmovbe %r12,%rax
jmp    1361 <FindNextTimestampedFile+0x1c1>
cmp    %rax,%r12
cmova  %r12,%rax
mov    %rax,%rbx
jmp    1243 <FindNextTimestampedFile+0xa3>
mov    0x2c70(%rip),%rax
mov    (%rax),%ebp
mov    0x2c5f(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xc78(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x26,%eax
jmp    1409 <FindNextTimestampedFile+0x269>
xor    %ebx,%ebx
mov    0x2c31(%rip),%rax
mov    (%rax),%rdi
mov    0x2c1f(%rip),%rax
cmp    (%rax),%rdi
jne    13e6 <FindNextTimestampedFile+0x246>
mov    0x2c23(%rip),%rax
mov    (%rax),%ebx
call   10c0 <strerror@plt>
lea    0xc9c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1080 <closedir@plt>
mov    $0x14,%eax
jmp    1409 <FindNextTimestampedFile+0x269>
mov    %r14,%rdi
call   1080 <closedir@plt>
test   %rbx,%rbx
je     1404 <FindNextTimestampedFile+0x264>
xor    %eax,%eax
mov    0x10(%rsp),%rcx
test   %rcx,%rcx
je     1409 <FindNextTimestampedFile+0x269>
mov    %rbx,(%rcx)
jmp    1409 <FindNextTimestampedFile+0x269>
mov    $0x6,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [34 x i8] c"Unable to open directory '%s': %s\00"
@errno = global i64 0
@.str.1 = [31 x i8] c"Skip validating file '%s' (%s)\00"
@.str.2 = [38 x i8] c"Failed to extract timestamp from '%s'\00"
@EBADF = global i64 0
@.str.3 = [27 x i8] c"Error reading directory %s\00"
define i32 @FindNextTimestampedFile(i8* %0, i8* %1, i64 %2, i32 %3, i64* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64*
%12 = alloca i32*
%13 = alloca %struct.dirent*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i64* %4, i64** %11
store i32* null, i32** %12
store i64 0, i64* %15
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %5
%21 = load i8*, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %20, %5
store i32 1, i32* %6
br label %189
24: ; preds = %20
%25 = load i8*, i8** %7
%26 = call i32* @opendir(i8* %25)
store i32* %26, i32** %12
%27 = icmp ne i32* %26, null
br i1 %27, label %34, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %7
%31 = load i64, i64* @errno
%32 = call i8* @strerror(i64 %31)
%33 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %30, i8* %32)
store i32 38, i32* %6
br label %189
34: ; preds = %24
store i64 0, i64* @errno
br label %35
35: ; preds = %164, %142, %136, %128, %118, %110, %97, %79, %65, %48, %34
%36 = load i32*, i32** %12
%37 = call %struct.dirent* @readdir(i32* %36)
store %struct.dirent* %37, %struct.dirent** %13
%38 = icmp ne %struct.dirent* %37, null
br i1 %38, label %39, label %165
39: ; preds = %35
store i8* null, i8** %17
%40 = load %struct.dirent*, %struct.dirent** %13
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = load i8*, i8** %8
%44 = load i8*, i8** %8
%45 = call i32 @strlen(i8* %44)
%46 = call i64 @strncmp(i8* %42, i8* %43, i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %39
br label %35
49: ; preds = %39
%50 = load %struct.dirent*, %struct.dirent** %13
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 0
%52 = load i8*, i8** %51
%53 = load i8*, i8** %8
%54 = call i32 @strlen(i8* %53)
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8* %56, i8** %17
%57 = load i8*, i8** %17
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %66
59: ; preds = %49
%60 = load i8*, i8** %17
%61 = getelementptr inbounds i8, i8* %60, i64 0
%62 = load i8, i8* %61
%63 = call i32 @isdigit(i8 signext %62)
%64 = icmp ne i32 %63, 0
br i1 %64, label %66, label %65
65: ; preds = %59
br label %35
66: ; preds = %59, %49
%67 = load %struct.dirent*, %struct.dirent** %13
%68 = getelementptr inbounds %struct.dirent, %struct.dirent* %67, i32 0, i32 0
%69 = load i8*, i8** %68
%70 = call i8* @strrchr(i8* %69, i8 signext 46)
store i8* %70, i8** %17
%71 = load i8*, i8** %17
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %86
73: ; preds = %66
%74 = load i8*, i8** %17
%75 = getelementptr inbounds i8, i8* %74, i64 1
%76 = load i8, i8* %75
%77 = call i32 @isdigit(i8 signext %76)
%78 = icmp ne i32 %77, 0
br i1 %78, label %86, label %79
79: ; preds = %73
%80 = load i32, i32* @stderr
%81 = load %struct.dirent*, %struct.dirent** %13
%82 = getelementptr inbounds %struct.dirent, %struct.dirent* %81, i32 0, i32 0
%83 = load i8*, i8** %82
%84 = load i8*, i8** %17
%85 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %83, i8* %84)
br label %35
86: ; preds = %73, %66
%87 = load %struct.dirent*, %struct.dirent** %13
%88 = getelementptr inbounds %struct.dirent, %struct.dirent* %87, i32 0, i32 0
%89 = load i8*, i8** %88
%90 = load i8*, i8** %8
%91 = call i32 @strlen(i8* %90)
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %89, i64 %92
store i8* %93, i8** %16
%94 = load i8*, i8** %16
%95 = call i64 @strtoul(i8* %94, i32* null, i32 10)
store i64 %95, i64* %14
%96 = icmp eq i64 %95, 0
br i1 %96, label %97, label %103
97: ; preds = %86
%98 = load i32, i32* @stderr
%99 = load %struct.dirent*, %struct.dirent** %13
%100 = getelementptr inbounds %struct.dirent, %struct.dirent* %99, i32 0, i32 0
%101 = load i8*, i8** %100
%102 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %101)
br label %35
103: ; preds = %86
%104 = load i32, i32* %10
%105 = icmp eq i32 %104, 2
br i1 %105, label %106, label %121
106: ; preds = %103
%107 = load i64, i64* %14
%108 = load i64, i64* %9
%109 = icmp ult i64 %107, %108
br i1 %109, label %110, label %111
110: ; preds = %106
br label %35
111: ; preds = %106
%112 = load i64, i64* %15
%113 = icmp ne i64 %112, 0
br i1 %113, label %114, label %119
114: ; preds = %111
%115 = load i64, i64* %14
%116 = load i64, i64* %15
%117 = icmp ugt i64 %115, %116
br i1 %117, label %118, label %119
118: ; preds = %114
br label %35
119: ; preds = %114, %111
%120 = load i64, i64* %14
store i64 %120, i64* %15
br label %164
121: ; preds = %103
%122 = load i32, i32* %10
%123 = icmp eq i32 %122, 1
br i1 %123, label %124, label %139
124: ; preds = %121
%125 = load i64, i64* %14
%126 = load i64, i64* %9
%127 = icmp ule i64 %125, %126
br i1 %127, label %128, label %129
128: ; preds = %124
br label %35
129: ; preds = %124
%130 = load i64, i64* %15
%131 = icmp ne i64 %130, 0
br i1 %131, label %132, label %137
132: ; preds = %129
%133 = load i64, i64* %14
%134 = load i64, i64* %15
%135 = icmp ugt i64 %133, %134
br i1 %135, label %136, label %137
136: ; preds = %132
br label %35
137: ; preds = %132, %129
%138 = load i64, i64* %14
store i64 %138, i64* %15
br label %163
139: ; preds = %121
%140 = load i64, i64* %15
%141 = icmp eq i64 %140, 0
br i1 %141, label %142, label %144
142: ; preds = %139
%143 = load i64, i64* %14
store i64 %143, i64* %15
br label %35
144: ; preds = %139
%145 = load i64, i64* %14
%146 = load i64, i64* %9
%147 = icmp ugt i64 %145, %146
br i1 %147, label %148, label %155
148: ; preds = %144
%149 = load i64, i64* %15
%150 = load i64, i64* %14
%151 = icmp ugt i64 %149, %150
br i1 %151, label %152, label %154
152: ; preds = %148
%153 = load i64, i64* %14
store i64 %153, i64* %15
br label %154
154: ; preds = %152, %148
br label %162
155: ; preds = %144
%156 = load i64, i64* %15
%157 = load i64, i64* %14
%158 = icmp ule i64 %156, %157
br i1 %158, label %159, label %161
159: ; preds = %155
%160 = load i64, i64* %14
store i64 %160, i64* %15
br label %161
161: ; preds = %159, %155
br label %162
162: ; preds = %161, %154
br label %163
163: ; preds = %162, %137
br label %164
164: ; preds = %163, %119
br label %35
165: ; preds = %35
%166 = load i64, i64* @errno
%167 = load i64, i64* @EBADF
%168 = icmp eq i64 %166, %167
br i1 %168, label %169, label %176
169: ; preds = %165
%170 = load i32, i32* @stderr
%171 = load i64, i64* @errno
%172 = call i8* @strerror(i64 %171)
%173 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %170, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %172)
%174 = load i32*, i32** %12
%175 = call i32 @closedir(i32* %174)
store i32 20, i32* %6
br label %189
176: ; preds = %165
%177 = load i32*, i32** %12
%178 = call i32 @closedir(i32* %177)
%179 = load i64, i64* %15
%180 = icmp eq i64 %179, 0
br i1 %180, label %181, label %182
181: ; preds = %176
store i32 6, i32* %6
br label %189
182: ; preds = %176
%183 = load i64*, i64** %11
%184 = icmp ne i64* %183, null
br i1 %184, label %185, label %188
185: ; preds = %182
%186 = load i64, i64* %15
%187 = load i64*, i64** %11
store i64 %186, i64* %187
br label %188
188: ; preds = %185, %182
store i32 0, i32* %6
br label %189
189: ; preds = %188, %181, %169, %28, %23
%190 = load i32, i32* %6
ret i32 %190
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [34 x i8] c"Unable to open directory '%s': %s\00"
@errno = global i64 0
@.str.1 = [31 x i8] c"Skip validating file '%s' (%s)\00"
@.str.2 = [38 x i8] c"Failed to extract timestamp from '%s'\00"
@EBADF = global i64 0
@.str.3 = [27 x i8] c"Error reading directory %s\00"
define i32 @FindNextTimestampedFile(i8* %0, i8* %1, i64 %2, i32 %3, i64* writeonly %4) {
%6 = icmp ne i8* %0, null
%7 = icmp ne i8* %1, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %108
9: ; preds = %5
%10 = tail call i32* @opendir(i8* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = load i64, i64* @errno
%15 = tail call i8* @strerror(i64 %14)
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %15)
br label %108
17: ; preds = %9
store i64 0, i64* @errno
%18 = tail call %struct.dirent* @readdir(i32* %10)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %92, label %20
20: ; preds = %17, %88
%21 = phi %struct.dirent* [ %90, %88 ], [ %18, %17 ]
%22 = phi i64 [ %89, %88 ], [ 0, %17 ]
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = tail call i32 @strlen(i8* %1)
%26 = tail call i64 @strncmp(i8* %24, i8* %1, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %88
28: ; preds = %20
%29 = load i8*, i8** %23
%30 = tail call i32 @strlen(i8* %1)
%31 = icmp eq i8* %29, null
br i1 %31, label %38, label %32
32: ; preds = %28
%33 = sext i32 %30 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
%35 = load i8, i8* %34
%36 = tail call i32 @isdigit(i8 signext %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %88, label %38
38: ; preds = %32, %28
%39 = load i8*, i8** %23
%40 = tail call i8* @strrchr(i8* dereferenceable(1) %39, i8 signext 46)
%41 = icmp eq i8* %40, null
br i1 %41, label %53, label %42
42: ; preds = %38
%43 = getelementptr inbounds i8, i8* %40, i64 1
%44 = load i8, i8* %43
%45 = tail call i32 @isdigit(i8 signext %44)
%46 = icmp eq i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %42
%48 = load i8*, i8** %23
br label %53
49: ; preds = %42
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %23
%52 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %51, i8* %40)
br label %88
53: ; preds = %47, %38
%54 = phi i8* [ %48, %47 ], [ %39, %38 ]
%55 = tail call i32 @strlen(i8* %1)
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = tail call i64 @strtoul(i8* nocapture %57, i32* null, i32 10)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %23
%63 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %62)
br label %88
64: ; preds = %53
switch i32 %3, label %77 [
i32 2, label %65
i32 1, label %71
]
65: ; preds = %64
%66 = icmp ult i64 %58, %2
br i1 %66, label %88, label %67
67: ; preds = %65
%68 = icmp ne i64 %22, 0
%69 = icmp ugt i64 %58, %22
%70 = select i1 %68, i1 %69, i1 false
br i1 %70, label %88, label %86
71: ; preds = %64
%72 = icmp ugt i64 %58, %2
br i1 %72, label %73, label %88
73: ; preds = %71
%74 = icmp ne i64 %22, 0
%75 = icmp ugt i64 %58, %22
%76 = select i1 %74, i1 %75, i1 false
br i1 %76, label %88, label %86
77: ; preds = %64
%78 = icmp eq i64 %22, 0
br i1 %78, label %88, label %79
79: ; preds = %77
%80 = icmp ugt i64 %58, %2
%81 = icmp ugt i64 %22, %58
br i1 %80, label %82, label %84
82: ; preds = %79
%83 = select i1 %81, i64 %58, i64 %22
br label %86
84: ; preds = %79
%85 = select i1 %81, i64 %22, i64 %58
br label %86
86: ; preds = %84, %82, %73, %67
%87 = phi i64 [ %58, %67 ], [ %58, %73 ], [ %83, %82 ], [ %85, %84 ]
br label %88
88: ; preds = %77, %73, %71, %67, %65, %32, %20, %86, %60, %49
%89 = phi i64 [ %22, %60 ], [ %87, %86 ], [ %22, %49 ], [ %22, %20 ], [ %22, %32 ], [ %22, %65 ], [ %22, %67 ], [ %22, %71 ], [ %22, %73 ], [ %58, %77 ]
%90 = tail call %struct.dirent* @readdir(i32* %10)
%91 = icmp eq %struct.dirent* %90, null
br i1 %91, label %92, label %20
92: ; preds = %88, %17
%93 = phi i64 [ 0, %17 ], [ %89, %88 ]
%94 = load i64, i64* @errno
%95 = load i64, i64* @EBADF
%96 = icmp eq i64 %94, %95
br i1 %96, label %97, label %102
97: ; preds = %92
%98 = load i32, i32* @stderr
%99 = tail call i8* @strerror(i64 %94)
%100 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %99)
%101 = tail call i32 @closedir(i32* %10)
br label %108
102: ; preds = %92
%103 = tail call i32 @closedir(i32* %10)
%104 = icmp eq i64 %93, 0
br i1 %104, label %108, label %105
105: ; preds = %102
%106 = icmp eq i64* %4, null
br i1 %106, label %108, label %107
107: ; preds = %105
store i64 %93, i64* %4
br label %108
108: ; preds = %105, %107, %102, %5, %97, %12
%109 = phi i32 [ 20, %97 ], [ 38, %12 ], [ 1, %5 ], [ 6, %102 ], [ 0, %107 ], [ 0, %105 ]
ret i32 %109
}