#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 int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ dat_path;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ choose_random_datfile(char *, int, char *);
scalar_t__ choose_random_fortune_pos(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     int *, char *);
scalar_t__ choose_random_path(char *, int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
scalar_t__ getpid();
scalar_t__ isdir(char *);
scalar_t__ isfile(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ read_fortune(char **, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                        int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ srand(scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char dat_path[4096];
  if (argc == 2 &&
      ((strcmp("-h", argv[1]) == 0) || (strcmp("--help", argv[1]) == 0))) {
    printf("Usage: %s [path to fortune file or directory]\n\n"
           "Version 2.5 - https://github.com/vsergeev/minifortune\n\n"
           "If no fortune file or directory is specified, minifortune defaults "
           "to:\n\n"
           "    %s         environment variable containing one or more\n"
           "                         colon-separated files or directories\n\n"
           "    %s   directory\n\n",
           argv[0], "FORTUNE_PATH", "/usr/share/fortune");
    exit(EXIT_SUCCESS);
  }
  srand(time(NULL) + getpid());
  if (argc == 1) {
    if (getenv("FORTUNE_PATH") != NULL && strlen(getenv("FORTUNE_PATH")) > 0) {
      char path[4096];
      if (choose_random_path(path, sizeof(path), getenv("FORTUNE_PATH")) < 0) {
        fprintf(stderr,
                "Error, no path found in environment variable paths: %s\n",
                getenv("FORTUNE_PATH"));
        exit(EXIT_FAILURE);
      }
      if (isdir(path)) {
        if (choose_random_datfile(dat_path, sizeof(dat_path), path) < 0) {
          fprintf(stderr, "Error, no fortune file found in directory: \"%s\"\n",
                  path);
          exit(EXIT_FAILURE);
        }
      } else if (isfile(path)) {
        snprintf(dat_path, sizeof(dat_path), "%s.dat", path);
      } else {
        fprintf(stderr, "Error, invalid fortune path: \"%s\"\n", path);
        exit(EXIT_FAILURE);
      }
    } else if (isdir("/usr/share/fortune")) {
      if (choose_random_datfile(dat_path, sizeof(dat_path),
                                "/usr/share/fortune") < 0) {
        fprintf(stderr, "Error, no fortune file found in directory: \"%s\"\n",
                "/usr/share/fortune");
        exit(EXIT_FAILURE);
      }
    } else {
      printf("A wise man once said:\n\tPopulate %s with fortunes,\n\tor run "
             "'minifortune -h' for more options.\n",
             "/usr/share/fortune");
      exit(EXIT_SUCCESS);
    }
  } else if (argc == 2) {
    if (isdir(argv[1])) {
      if (choose_random_datfile(dat_path, sizeof(dat_path), argv[1]) < 0) {
        fprintf(stderr,
                "Error, no fortune .dat file found in directory \"%s\".\n",
                argv[1]);
        exit(EXIT_FAILURE);
      }
    } else if (isfile(argv[1])) {
      snprintf(dat_path, sizeof(dat_path), "%s.dat", argv[1]);
    } else {
      fprintf(stderr, "Error, invalid fortune path: \"%s\"\n", argv[1]);
      exit(EXIT_FAILURE);
    }
  }
  uint32_t fortune_pos;
  uint8_t fortune_delim;
  bool fortune_rot13;
  char *fortune = NULL;
  if (choose_random_fortune_pos(&fortune_pos, &fortune_delim, &fortune_rot13,
                                dat_path) < 0)
    exit(EXIT_FAILURE);
  dat_path[strlen(dat_path) - 4] = '\0';
  if (read_fortune(&fortune, dat_path, fortune_pos, fortune_delim,
                   fortune_rot13) < 0)
    exit(EXIT_FAILURE);
  fputs(fortune, stdout);
  free(fortune);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    12b0 <main+0x90>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdae(%rip),%rdi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
je     127f <main+0x5f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd93(%rip),%rdi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    12b0 <main+0x90>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd7d(%rip),%rdi
lea    0xeb3(%rip),%rdx
lea    0xeb9(%rip),%rcx
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
mov    %rax,-0x2030(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x2030(%rbp),%rdi
add    %rax,%rdi
call   10b0 <srand@plt>
cmpl   $0x1,-0x8(%rbp)
jne    14f2 <main+0x2d2>
lea    0xe60(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     145e <main+0x23e>
lea    0xe4a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1070 <strlen@plt>
cmp    $0x0,%eax
jle    145e <main+0x23e>
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2038(%rbp)
lea    0xe1f(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x2038(%rbp),%rdi
mov    %rax,%rdx
mov    $0x1000,%esi
call   1140 <choose_random_path@plt>
cmp    $0x0,%rax
jge    1389 <main+0x169>
mov    0x2c8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x203c(%rbp)
lea    0xde6(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x203c(%rbp),%edi
mov    %rax,%rdx
lea    0xdf1(%rip),%rsi
call   10d0 <fprintf@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
lea    -0x2010(%rbp),%rdi
call   10f0 <isdir@plt>
cmp    $0x0,%rax
je     13f0 <main+0x1d0>
lea    -0x1010(%rbp),%rdi
lea    -0x2010(%rbp),%rdx
mov    $0x1000,%esi
call   1130 <choose_random_datfile@plt>
cmp    $0x0,%rax
jge    13eb <main+0x1cb>
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
lea    -0x2010(%rbp),%rdx
lea    0xdc7(%rip),%rsi
call   10d0 <fprintf@plt>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
jmp    1459 <main+0x239>
lea    -0x2010(%rbp),%rdi
call   1110 <isfile@plt>
cmp    $0x0,%rax
je     142a <main+0x20a>
lea    -0x1010(%rbp),%rdi
lea    -0x2010(%rbp),%rcx
mov    $0x1000,%esi
lea    0xdb0(%rip),%rdx
call   1090 <snprintf@plt>
jmp    1454 <main+0x234>
mov    0x2baf(%rip),%rax
mov    (%rax),%edi
lea    -0x2010(%rbp),%rdx
lea    0xd96(%rip),%rsi
call   10d0 <fprintf@plt>
mov    0x2b8b(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
jmp    1459 <main+0x239>
jmp    14ed <main+0x2cd>
lea    0xcef(%rip),%rdi
call   10f0 <isdir@plt>
cmp    $0x0,%rax
je     14c5 <main+0x2a5>
lea    -0x1010(%rbp),%rdi
mov    $0x1000,%esi
lea    0xccd(%rip),%rdx
call   1130 <choose_random_datfile@plt>
cmp    $0x0,%rax
jge    14c0 <main+0x2a0>
mov    0x2b43(%rip),%rax
mov    (%rax),%edi
lea    0xcf9(%rip),%rsi
lea    0xca7(%rip),%rdx
call   10d0 <fprintf@plt>
mov    0x2b1f(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
jmp    14e8 <main+0x2c8>
lea    0xd2e(%rip),%rdi
lea    0xc81(%rip),%rsi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2ae7(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
jmp    14ed <main+0x2cd>
jmp    15dc <main+0x3bc>
cmpl   $0x2,-0x8(%rbp)
jne    15d7 <main+0x3b7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <isdir@plt>
cmp    $0x0,%rax
je     1566 <main+0x346>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x1000,%esi
call   1130 <choose_random_datfile@plt>
cmp    $0x0,%rax
jge    1561 <main+0x341>
mov    0x2aa3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd0a(%rip),%rsi
call   10d0 <fprintf@plt>
mov    0x2a7e(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
jmp    15d2 <main+0x3b2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <isfile@plt>
cmp    $0x0,%rax
je     15a2 <main+0x382>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x1000,%esi
lea    0xc38(%rip),%rdx
call   1090 <snprintf@plt>
jmp    15cd <main+0x3ad>
mov    0x2a37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc1d(%rip),%rsi
call   10d0 <fprintf@plt>
mov    0x2a12(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
jmp    15d2 <main+0x3b2>
jmp    15d7 <main+0x3b7>
jmp    15dc <main+0x3bc>
movq   $0x0,-0x2028(%rbp)
lea    -0x1010(%rbp),%rcx
lea    -0x2014(%rbp),%rdi
lea    -0x2018(%rbp),%rsi
lea    -0x201c(%rbp),%rdx
call   1050 <choose_random_fortune_pos@plt>
cmp    $0x0,%rax
jge    1620 <main+0x400>
mov    0x29bf(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
lea    -0x1010(%rbp),%rdi
call   1070 <strlen@plt>
sub    $0x4,%eax
cltq
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x1010(%rbp),%rsi
mov    -0x2014(%rbp),%edx
mov    -0x2018(%rbp),%ecx
mov    -0x201c(%rbp),%r8d
lea    -0x2028(%rbp),%rdi
call   1100 <read_fortune@plt>
cmp    $0x0,%rax
jge    1677 <main+0x457>
mov    0x2968(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x2028(%rbp),%rdi
mov    0x294b(%rip),%rax
mov    (%rax),%esi
call   10a0 <fputs@plt>
mov    -0x2028(%rbp),%rdi
call   1040 <free@plt>
mov    0x2929(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2010,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
cmp    $0x2,%edi
jne    1283 <main+0x63>
mov    0x8(%r14),%rsi
lea    0xdc0(%rip),%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     125f <main+0x3f>
mov    0x8(%r14),%rsi
lea    0xdae(%rip),%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
jne    1283 <main+0x63>
mov    (%r14),%rsi
lea    0xda1(%rip),%rdi
lea    0xed7(%rip),%rdx
lea    0xedd(%rip),%rcx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    151a <main+0x2fa>
xor    %edi,%edi
call   10e0 <time@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getpid@plt>
add    %rax,%rbx
mov    %rbx,%rdi
call   10b0 <srand@plt>
cmp    $0x1,%ebp
jne    1316 <main+0xf6>
lea    0xe9c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     135f <main+0x13f>
mov    %rax,%rdi
call   1070 <strlen@plt>
test   %eax,%eax
jle    135f <main+0x13f>
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
lea    0x10(%rsp),%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1140 <choose_random_path@plt>
test   %rax,%rax
jns    13f9 <main+0x1d9>
mov    0x2ce9(%rip),%rax
mov    (%rax),%ebx
lea    0xe47(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe5b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    146f <main+0x24f>
cmp    $0x2,%ebp
jne    1494 <main+0x274>
mov    0x8(%r14),%rdi
call   10f0 <isdir@plt>
mov    0x8(%r14),%rdx
test   %rax,%rax
jne    13c8 <main+0x1a8>
mov    %rdx,%rdi
call   1110 <isfile@plt>
test   %rax,%rax
jne    1429 <main+0x209>
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe7d(%rip),%rsi
jmp    146f <main+0x24f>
lea    0xdee(%rip),%rdi
call   10f0 <isdir@plt>
test   %rax,%rax
jne    138a <main+0x16a>
lea    0xe83(%rip),%rdi
lea    0xdd6(%rip),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    151a <main+0x2fa>
lea    0xdc3(%rip),%rdx
lea    0x1010(%rsp),%rdi
mov    $0x1000,%esi
call   1130 <choose_random_datfile@plt>
test   %rax,%rax
jns    1494 <main+0x274>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
lea    0xd91(%rip),%rdx
jmp    146f <main+0x24f>
lea    0x1010(%rsp),%rdi
mov    $0x1000,%esi
call   1130 <choose_random_datfile@plt>
test   %rax,%rax
jns    1494 <main+0x274>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe61(%rip),%rsi
jmp    146f <main+0x24f>
lea    0x10(%rsp),%rdi
call   10f0 <isdir@plt>
test   %rax,%rax
jne    143e <main+0x21e>
lea    0x10(%rsp),%rdi
call   1110 <isfile@plt>
test   %rax,%rax
jne    1476 <main+0x256>
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
jmp    146a <main+0x24a>
mov    0x8(%r14),%rcx
lea    0xd9c(%rip),%rdx
lea    0x1010(%rsp),%rdi
jmp    148a <main+0x26a>
lea    0x1010(%rsp),%rdi
lea    0x10(%rsp),%rdx
mov    $0x1000,%esi
call   1130 <choose_random_datfile@plt>
test   %rax,%rax
jns    1494 <main+0x274>
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
lea    0x10(%rsp),%rdx
call   10d0 <fprintf@plt>
jmp    14ef <main+0x2cf>
lea    0xd53(%rip),%rdx
lea    0x1010(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    $0x1000,%esi
call   1090 <snprintf@plt>
movq   $0x0,0x10(%rsp)
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
lea    0x1010(%rsp),%rbx
mov    %rbx,%rcx
call   1050 <choose_random_fortune_pos@plt>
test   %rax,%rax
js     14ef <main+0x2cf>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x4(%rax,%rbx,1)
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%r8d
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1100 <read_fortune@plt>
test   %rax,%rax
jns    14fd <main+0x2dd>
mov    0x2ae2(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    0x10(%rsp),%rdi
mov    0x2ac7(%rip),%rax
mov    (%rax),%esi
call   10a0 <fputs@plt>
mov    0x10(%rsp),%rdi
call   1040 <free@plt>
mov    0x2aa7(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [317 x i8] c"Usage: %s [path to fortune file or directory]\0A\0AVersion 2.5 - https://github.com/vsergeev/minifortune\0A\0AIf no fortune file or directory is specified, minifortune defaults to:\0A\0A %s environment variable containing one or more\0A colon-separated files or directories\0A\0A %s directory\0A\0A\00"
@.str.3 = [13 x i8] c"FORTUNE_PATH\00"
@.str.4 = [19 x i8] c"/usr/share/fortune\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.5 = [56 x i8] c"Error, no path found in environment variable paths: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [49 x i8] c"Error, no fortune file found in directory: \22%s\22\0A\00"
@.str.7 = [7 x i8] c"%s.dat\00"
@.str.8 = [35 x i8] c"Error, invalid fortune path: \22%s\22\0A\00"
@.str.9 = [94 x i8] c"A wise man once said:\0A\09Populate %s with fortunes,\0A\09or run 'minifortune -h' for more options.\0A\00"
@.str.10 = [54 x i8] c"Error, no fortune .dat file found in directory \22%s\22.\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca [4096 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %33
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %14
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %20, %14
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([317 x i8], [317 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* @EXIT_SUCCESS
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %20, %2
%34 = call i64 @time(i32* null)
%35 = call i64 (...) @getpid()
%36 = add nsw i64 %34, %35
%37 = call i32 @srand(i64 %36)
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %109
40: ; preds = %33
%41 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %90
43: ; preds = %40
%44 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @strlen(i8* %44)
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %90
47: ; preds = %43
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%49 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%50 = call i64 @choose_random_path(i8* %48, i32 4096, i8* %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %47
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%60 = call i64 @isdir(i8* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %74
62: ; preds = %58
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%65 = call i64 @choose_random_datfile(i8* %63, i32 4096, i8* %64)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %73
67: ; preds = %62
%68 = load i32, i32* @stderr
%69 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%70 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %62
br label %89
74: ; preds = %58
%75 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%76 = call i64 @isfile(i8* %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %74
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%80 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%81 = call i32 @snprintf(i8* %79, i32 4096, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %80)
br label %88
82: ; preds = %74
%83 = load i32, i32* @stderr
%84 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%85 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %84)
%86 = load i32, i32* @EXIT_FAILURE
%87 = call i32 @exit(i32 %86)
unreachable
88: ; preds = %78
br label %89
89: ; preds = %88, %73
br label %108
90: ; preds = %43, %40
%91 = call i64 @isdir(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%92 = icmp ne i64 %91, 0
br i1 %92, label %93, label %103
93: ; preds = %90
%94 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%95 = call i64 @choose_random_datfile(i8* %94, i32 4096, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %102
97: ; preds = %93
%98 = load i32, i32* @stderr
%99 = call i32 @fprintf(i32 %98, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%100 = load i32, i32* @EXIT_FAILURE
%101 = call i32 @exit(i32 %100)
unreachable
102: ; preds = %93
br label %107
103: ; preds = %90
%104 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%105 = load i32, i32* @EXIT_SUCCESS
%106 = call i32 @exit(i32 %105)
unreachable
107: ; preds = %102
br label %108
108: ; preds = %107, %89
br label %157
109: ; preds = %33
%110 = load i32, i32* %4
%111 = icmp eq i32 %110, 2
br i1 %111, label %112, label %156
112: ; preds = %109
%113 = load i8**, i8*** %5
%114 = getelementptr inbounds i8*, i8** %113, i64 1
%115 = load i8*, i8** %114
%116 = call i64 @isdir(i8* %115)
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %134
118: ; preds = %112
%119 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%120 = load i8**, i8*** %5
%121 = getelementptr inbounds i8*, i8** %120, i64 1
%122 = load i8*, i8** %121
%123 = call i64 @choose_random_datfile(i8* %119, i32 4096, i8* %122)
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %133
125: ; preds = %118
%126 = load i32, i32* @stderr
%127 = load i8**, i8*** %5
%128 = getelementptr inbounds i8*, i8** %127, i64 1
%129 = load i8*, i8** %128
%130 = call i32 @fprintf(i32 %126, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.10, i64 0, i64 0), i8* %129)
%131 = load i32, i32* @EXIT_FAILURE
%132 = call i32 @exit(i32 %131)
unreachable
133: ; preds = %118
br label %155
134: ; preds = %112
%135 = load i8**, i8*** %5
%136 = getelementptr inbounds i8*, i8** %135, i64 1
%137 = load i8*, i8** %136
%138 = call i64 @isfile(i8* %137)
%139 = icmp ne i64 %138, 0
br i1 %139, label %140, label %146
140: ; preds = %134
%141 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%142 = load i8**, i8*** %5
%143 = getelementptr inbounds i8*, i8** %142, i64 1
%144 = load i8*, i8** %143
%145 = call i32 @snprintf(i8* %141, i32 4096, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %144)
br label %154
146: ; preds = %134
%147 = load i32, i32* @stderr
%148 = load i8**, i8*** %5
%149 = getelementptr inbounds i8*, i8** %148, i64 1
%150 = load i8*, i8** %149
%151 = call i32 @fprintf(i32 %147, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %150)
%152 = load i32, i32* @EXIT_FAILURE
%153 = call i32 @exit(i32 %152)
unreachable
154: ; preds = %140
br label %155
155: ; preds = %154, %133
br label %156
156: ; preds = %155, %109
br label %157
157: ; preds = %156, %108
store i8* null, i8** %11
%158 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%159 = call i64 @choose_random_fortune_pos(i32* %8, i32* %9, i32* %10, i8* %158)
%160 = icmp slt i64 %159, 0
br i1 %160, label %161, label %164
161: ; preds = %157
%162 = load i32, i32* @EXIT_FAILURE
%163 = call i32 @exit(i32 %162)
unreachable
164: ; preds = %157
%165 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%166 = call i32 @strlen(i8* %165)
%167 = sub nsw i32 %166, 4
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %168
store i8 0, i8* %169
%170 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%171 = load i32, i32* %8
%172 = load i32, i32* %9
%173 = load i32, i32* %10
%174 = call i64 @read_fortune(i8** %11, i8* %170, i32 %171, i32 %172, i32 %173)
%175 = icmp slt i64 %174, 0
br i1 %175, label %176, label %179
176: ; preds = %164
%177 = load i32, i32* @EXIT_FAILURE
%178 = call i32 @exit(i32 %177)
unreachable
179: ; preds = %164
%180 = load i8*, i8** %11
%181 = load i32, i32* @stdout
%182 = call i32 @fputs(i8* %180, i32 %181)
%183 = load i8*, i8** %11
%184 = call i32 @free(i8* %183)
%185 = load i32, i32* @EXIT_SUCCESS
%186 = call i32 @exit(i32 %185)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [317 x i8] c"Usage: %s [path to fortune file or directory]\0A\0AVersion 2.5 - https://github.com/vsergeev/minifortune\0A\0AIf no fortune file or directory is specified, minifortune defaults to:\0A\0A %s environment variable containing one or more\0A colon-separated files or directories\0A\0A %s directory\0A\0A\00"
@.str.3 = [13 x i8] c"FORTUNE_PATH\00"
@.str.4 = [19 x i8] c"/usr/share/fortune\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.5 = [56 x i8] c"Error, no path found in environment variable paths: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [49 x i8] c"Error, no fortune file found in directory: \22%s\22\0A\00"
@.str.7 = [7 x i8] c"%s.dat\00"
@.str.8 = [35 x i8] c"Error, invalid fortune path: \22%s\22\0A\00"
@.str.9 = [94 x i8] c"A wise man once said:\0A\09Populate %s with fortunes,\0A\09or run 'minifortune -h' for more options.\0A\00"
@.str.10 = [54 x i8] c"Error, no fortune .dat file found in directory \22%s\22.\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4096 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = load i8*, i8** %12
%18 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16, %11
%21 = load i8*, i8** %1
%22 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([317 x i8], [317 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%23 = load i32, i32* @EXIT_SUCCESS
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %16, %2
%26 = tail call i64 @time(i32* null)
%27 = tail call i64 (...) @getpid()
%28 = add nsw i64 %27, %26
%29 = tail call i32 @srand(i64 %28)
%30 = icmp eq i32 %0, 1
br i1 %30, label %31, label %85
31: ; preds = %25
%32 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i8* %32, null
br i1 %33, label %70, label %34
34: ; preds = %31
%35 = tail call i32 @strlen(i8* %32)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %70
37: ; preds = %34
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%39 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%40 = call i64 @choose_random_path(i8* %38, i32 4096, i8* %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %37
%49 = call i64 @isdir(i8* %38)
%50 = icmp eq i64 %49, 0
br i1 %50, label %59, label %51
51: ; preds = %48
%52 = call i64 @choose_random_datfile(i8* %9, i32 4096, i8* %38)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %69
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %38)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %48
%60 = call i64 @isfile(i8* %38)
%61 = icmp eq i64 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %59
%63 = call i32 @snprintf(i8* %9, i32 4096, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %38)
br label %69
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %38)
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %51, %62
br label %113
70: ; preds = %34, %31
%71 = tail call i64 @isdir(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
br i1 %72, label %81, label %73
73: ; preds = %70
%74 = call i64 @choose_random_datfile(i8* %9, i32 4096, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %113
76: ; preds = %73
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%79 = load i32, i32* @EXIT_FAILURE
%80 = call i32 @exit(i32 %79)
unreachable
81: ; preds = %70
%82 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%83 = load i32, i32* @EXIT_SUCCESS
%84 = tail call i32 @exit(i32 %83)
unreachable
85: ; preds = %25
br i1 %10, label %86, label %113
86: ; preds = %85
%87 = getelementptr inbounds i8*, i8** %1, i64 1
%88 = load i8*, i8** %87
%89 = tail call i64 @isdir(i8* %88)
%90 = icmp eq i64 %89, 0
%91 = load i8*, i8** %87
br i1 %90, label %101, label %92
92: ; preds = %86
%93 = call i64 @choose_random_datfile(i8* %9, i32 4096, i8* %91)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %113
95: ; preds = %92
%96 = load i32, i32* @stderr
%97 = load i8*, i8** %87
%98 = call i32 @fprintf(i32 %96, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.10, i64 0, i64 0), i8* %97)
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %86
%102 = tail call i64 @isfile(i8* %91)
%103 = icmp eq i64 %102, 0
br i1 %103, label %107, label %104
104: ; preds = %101
%105 = load i8*, i8** %87
%106 = call i32 @snprintf(i8* %9, i32 4096, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %105)
br label %113
107: ; preds = %101
%108 = load i32, i32* @stderr
%109 = load i8*, i8** %87
%110 = tail call i32 @fprintf(i32 %108, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %109)
%111 = load i32, i32* @EXIT_FAILURE
%112 = tail call i32 @exit(i32 %111)
unreachable
113: ; preds = %85, %92, %104, %69, %73
%114 = bitcast i32* %5 to i8*
%115 = bitcast i32* %6 to i8*
%116 = bitcast i32* %7 to i8*
%117 = bitcast i8** %8 to i8*
store i8* null, i8** %8
%118 = call i64 @choose_random_fortune_pos(i32* %5, i32* %6, i32* %7, i8* %9)
%119 = icmp slt i64 %118, 0
br i1 %119, label %120, label %123
120: ; preds = %113
%121 = load i32, i32* @EXIT_FAILURE
%122 = call i32 @exit(i32 %121)
unreachable
123: ; preds = %113
%124 = call i32 @strlen(i8* %9)
%125 = add nsw i32 %124, -4
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %126
store i8 0, i8* %127
%128 = load i32, i32* %5
%129 = load i32, i32* %6
%130 = load i32, i32* %7
%131 = call i64 @read_fortune(i8** %8, i8* %9, i32 %128, i32 %129, i32 %130)
%132 = icmp slt i64 %131, 0
br i1 %132, label %133, label %136
133: ; preds = %123
%134 = load i32, i32* @EXIT_FAILURE
%135 = call i32 @exit(i32 %134)
unreachable
136: ; preds = %123
%137 = load i8*, i8** %8
%138 = load i32, i32* @stdout
%139 = call i32 @fputs(i8* %137, i32 %138)
%140 = load i8*, i8** %8
%141 = call i32 @free(i8* %140)
%142 = load i32, i32* @EXIT_SUCCESS
%143 = call i32 @exit(i32 %142)
unreachable
}