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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
unsigned int fread(char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(unsigned int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int read_fortune(char **fortune, const char *fortune_path, uint32_t pos,
                 uint8_t delim, bool rot13) {
  FILE *fp;
  *fortune = NULL;
  if ((fp = fopen(fortune_path, "r")) == NULL) {
    fprintf(stderr, "Error opening fortune file \"%s\": fopen(): %s\n",
            fortune_path, strerror(errno));
    goto cleanup_failure;
  }
  if (fseek(fp, pos, SEEK_SET) < 0) {
    fprintf(stderr, "Error seeking fortune file \"%s\": fseek(): %s\n",
            fortune_path, strerror(errno));
    goto cleanup_failure;
  }
  unsigned int len;
  int c = 0, prev_c = 0;
  for (len = 0;; len++) {
    if ((c = fgetc(fp)) == EOF) {
      if (feof(fp))
        fprintf(stderr,
                "Error reading fortune from \"%s\": End delimiter not found.\n",
                fortune_path);
      else if (ferror(fp))
        fprintf(stderr, "Error reading fortune from \"%s\": fgetc(): %s\n",
                fortune_path, strerror(errno));
      goto cleanup_failure;
    }
    if (prev_c == delim && c == '\n')
      break;
    prev_c = c;
  }
  len -= 1;
  if ((*fortune = malloc(len + 1)) == NULL) {
    perror("Error allocating memory for fortune. malloc()");
    goto cleanup_failure;
  }
  if (fseek(fp, pos, SEEK_SET) < 0) {
    fprintf(stderr, "Error seeking in fortune file \"%s\": fseek(): %s\n",
            fortune_path, strerror(errno));
    goto cleanup_failure;
  }
  if (fread(*fortune, 1, len, fp) < len) {
    fprintf(stderr, "Error reading fortune from \"%s\": fread(): %s\n",
            fortune_path, strerror(errno));
    goto cleanup_failure;
  }
  (*fortune)[len] = '\0';
  if (rot13) {
    for (unsigned int i = 0; i < len; i++) {
      if ((*fortune)[i] >= 'a' && (*fortune)[i] <= 'z')
        (*fortune)[i] = ((((*fortune)[i] - 'a') + 13) % 26) + 'a';
      else if ((*fortune)[i] >= 'A' && (*fortune)[i] <= 'Z')
        (*fortune)[i] = ((((*fortune)[i] - 'A') + 13) % 26) + 'A';
    }
  }
  fclose(fp);
  return 0;
cleanup_failure:
  if (*fortune != NULL)
    free(*fortune);
  if (fp != NULL)
    fclose(fp);
  return -1;
}


x86 assembly (clang, -O0):
<read_fortune>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1245 <read_fortune+0x85>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15a2 <read_fortune+0x3e2>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
call   10b0 <fseek@plt>
cmp    $0x0,%rax
jge    12a3 <read_fortune+0xe3>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xd99(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15a2 <read_fortune+0x3e2>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x38(%rbp)
mov    0x2d1d(%rip),%rcx
cmp    (%rcx),%eax
jne    135d <read_fortune+0x19d>
mov    -0x30(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     1306 <read_fortune+0x146>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1358 <read_fortune+0x198>
mov    -0x30(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1353 <read_fortune+0x193>
mov    0x2cb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xd4d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1358 <read_fortune+0x198>
jmp    15a2 <read_fortune+0x3e2>
mov    -0x3c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    1378 <read_fortune+0x1b8>
cmpl   $0xa,-0x38(%rbp)
jne    1378 <read_fortune+0x1b8>
jmp    138c <read_fortune+0x1cc>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12b8 <read_fortune+0xf8>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    13c2 <read_fortune+0x202>
lea    0xd0f(%rip),%rdi
call   10d0 <perror@plt>
jmp    15a2 <read_fortune+0x3e2>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2bf8(%rip),%rax
mov    (%rax),%edx
call   10b0 <fseek@plt>
cmp    $0x0,%rax
jge    1420 <read_fortune+0x260>
mov    0x2bf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
lea    0xce1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15a2 <read_fortune+0x3e2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
cmp    -0x34(%rbp),%eax
jae    148c <read_fortune+0x2cc>
mov    0x2b90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    0x2b6e(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    %rax,%rcx
lea    0xca6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15a2 <read_fortune+0x3e2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x34(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x24(%rbp)
je     158d <read_fortune+0x3cd>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x34(%rbp),%eax
jae    1588 <read_fortune+0x3c8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x61,%eax
jl     1516 <read_fortune+0x356>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7a,%eax
jg     1516 <read_fortune+0x356>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
sub    $0x61,%eax
add    $0xd,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1575 <read_fortune+0x3b5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x41,%eax
jl     1570 <read_fortune+0x3b0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5a,%eax
jg     1570 <read_fortune+0x3b0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
sub    $0x41,%eax
add    $0xd,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1575 <read_fortune+0x3b5>
jmp    157a <read_fortune+0x3ba>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    14ab <read_fortune+0x2eb>
jmp    158d <read_fortune+0x3cd>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    15d7 <read_fortune+0x417>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     15bc <read_fortune+0x3fc>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     15d0 <read_fortune+0x410>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fortune>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%ebp
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,%rbx
mov    %rdi,%r15
movq   $0x0,(%rdi)
lea    0xe15(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     126b <read_fortune+0xab>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r13d,%esi
call   10b0 <fseek@plt>
test   %rax,%rax
js     128b <read_fortune+0xcb>
mov    %ebp,0x14(%rsp)
mov    %rbx,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,%rdi
call   1070 <fgetc@plt>
mov    0x2db8(%rip),%rbx
cmp    (%rbx),%eax
jne    12e8 <read_fortune+0x128>
mov    %r14,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     1381 <read_fortune+0x1c1>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
mov    (%rsp),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x8(%rsp),%r15
jmp    12b8 <read_fortune+0xf8>
mov    0x2d66(%rip),%rax
mov    (%rax),%ebp
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd79(%rip),%rsi
jmp    12a9 <read_fortune+0xe9>
mov    0x2d46(%rip),%rax
mov    (%rax),%ebp
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd87(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r15),%rdi
test   %rdi,%rdi
je     12c5 <read_fortune+0x105>
call   1030 <free@plt>
mov    $0xffffffff,%ebx
test   %r14,%r14
je     12d7 <read_fortune+0x117>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    1303 <read_fortune+0x143>
nop
mov    %r14,%rdi
call   1070 <fgetc@plt>
add    $0xffffffff,%ebp
cmp    (%rbx),%eax
je     1238 <read_fortune+0x78>
mov    %r15d,%ecx
mov    %eax,%r15d
cmp    %r12d,%ecx
jne    12f0 <read_fortune+0x130>
cmp    $0xa,%r15d
jne    12f0 <read_fortune+0x130>
mov    %ebp,%edi
neg    %edi
call   10a0 <malloc@plt>
mov    0x8(%rsp),%r15
mov    %rax,(%r15)
test   %rax,%rax
je     145b <read_fortune+0x29b>
mov    0x2c93(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r13d,%esi
call   10b0 <fseek@plt>
test   %rax,%rax
js     13b7 <read_fortune+0x1f7>
mov    %ebp,%ebx
not    %ebx
mov    (%r15),%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
cmp    %ebx,%eax
jae    13e0 <read_fortune+0x220>
mov    0x2c70(%rip),%rax
mov    (%rax),%ebp
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xda7(%rip),%rsi
jmp    13d5 <read_fortune+0x215>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
mov    0x8(%rsp),%r15
je     12b8 <read_fortune+0xf8>
mov    0x2c3a(%rip),%rax
mov    (%rax),%ebp
mov    0x2c29(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xce4(%rip),%rsi
jmp    13d5 <read_fortune+0x215>
mov    0x2c1a(%rip),%rax
mov    (%rax),%ebp
mov    0x2c09(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd20(%rip),%rsi
mov    %ebp,%edi
mov    (%rsp),%rdx
jmp    12ae <read_fortune+0xee>
mov    (%r15),%rax
mov    %ebx,%edi
movb   $0x0,(%rax,%rdi,1)
xor    %ebx,%ebx
cmpl   $0x0,0x14(%rsp)
je     12cf <read_fortune+0x10f>
cmp    $0xffffffff,%ebp
je     12cf <read_fortune+0x10f>
xor    %ecx,%ecx
jmp    1440 <read_fortune+0x280>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x61,%bl
mov    $0xac,%al
add    %sil,%al
movzbl %al,%eax
imul   $0x4f,%eax,%esi
shr    $0xb,%esi
lea    (%rsi,%rsi,4),%ebp
lea    0x0(%rbp,%rbp,4),%ebp
add    %esi,%ebp
sub    %bpl,%al
add    %bl,%al
mov    %al,(%rdx,%rcx,1)
add    $0x1,%rcx
xor    %ebx,%ebx
cmp    %rcx,%rdi
je     12cf <read_fortune+0x10f>
mov    (%r15),%rdx
movzbl (%rdx,%rcx,1),%esi
lea    -0x61(%rsi),%eax
cmp    $0x1a,%al
jb     1410 <read_fortune+0x250>
lea    -0x41(%rsi),%eax
cmp    $0x19,%al
ja     1431 <read_fortune+0x271>
mov    $0x41,%bl
mov    $0xcc,%al
jmp    1414 <read_fortune+0x254>
lea    0xc65(%rip),%rdi
call   10d0 <perror@plt>
jmp    12b8 <read_fortune+0xf8>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"Error opening fortune file \22%s\22: fopen(): %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [46 x i8] c"Error seeking fortune file \22%s\22: fseek(): %s\0A\00"
@EOF = global i32 0
@.str.3 = [59 x i8] c"Error reading fortune from \22%s\22: End delimiter not found.\0A\00"
@.str.4 = [46 x i8] c"Error reading fortune from \22%s\22: fgetc(): %s\0A\00"
@.str.5 = [46 x i8] c"Error allocating memory for fortune. malloc()\00"
@.str.6 = [49 x i8] c"Error seeking in fortune file \22%s\22: fseek(): %s\0A\00"
@.str.7 = [46 x i8] c"Error reading fortune from \22%s\22: fread(): %s\0A\00"
define i32 @read_fortune(i8** %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8** %0, i8*** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%17 = load i8**, i8*** %7
store i8* null, i8** %17
%18 = load i8*, i8** %8
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %12
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %5
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %8
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %25)
br label %208
27: ; preds = %5
%28 = load i32*, i32** %12
%29 = load i32, i32* %9
%30 = load i32, i32* @SEEK_SET
%31 = call i64 @fseek(i32* %28, i32 %29, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %8
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %37)
br label %208
39: ; preds = %27
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %13
br label %40
40: ; preds = %75, %39
%41 = load i32*, i32** %12
%42 = call i32 @fgetc(i32* %41)
store i32 %42, i32* %14
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %65
45: ; preds = %40
%46 = load i32*, i32** %12
%47 = call i64 @feof(i32* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %8
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i8* %51)
br label %64
53: ; preds = %45
%54 = load i32*, i32** %12
%55 = call i64 @ferror(i32* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %8
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %59, i8* %61)
br label %63
63: ; preds = %57, %53
br label %64
64: ; preds = %63, %49
br label %208
65: ; preds = %40
%66 = load i32, i32* %15
%67 = load i32, i32* %10
%68 = icmp eq i32 %66, %67
br i1 %68, label %69, label %73
69: ; preds = %65
%70 = load i32, i32* %14
%71 = icmp eq i32 %70, 10
br i1 %71, label %72, label %73
72: ; preds = %69
br label %78
73: ; preds = %69, %65
%74 = load i32, i32* %14
store i32 %74, i32* %15
br label %75
75: ; preds = %73
%76 = load i32, i32* %13
%77 = add i32 %76, 1
store i32 %77, i32* %13
br label %40
78: ; preds = %72
%79 = load i32, i32* %13
%80 = sub i32 %79, 1
store i32 %80, i32* %13
%81 = load i32, i32* %13
%82 = add i32 %81, 1
%83 = call i8* @malloc(i32 %82)
%84 = load i8**, i8*** %7
store i8* %83, i8** %84
%85 = icmp eq i8* %83, null
br i1 %85, label %86, label %88
86: ; preds = %78
%87 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
br label %208
88: ; preds = %78
%89 = load i32*, i32** %12
%90 = load i32, i32* %9
%91 = load i32, i32* @SEEK_SET
%92 = call i64 @fseek(i32* %89, i32 %90, i32 %91)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %100
94: ; preds = %88
%95 = load i32, i32* @stderr
%96 = load i8*, i8** %8
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %96, i8* %98)
br label %208
100: ; preds = %88
%101 = load i8**, i8*** %7
%102 = load i8*, i8** %101
%103 = load i32, i32* %13
%104 = load i32*, i32** %12
%105 = call i32 @fread(i8* %102, i32 1, i32 %103, i32* %104)
%106 = load i32, i32* %13
%107 = icmp ult i32 %105, %106
br i1 %107, label %108, label %114
108: ; preds = %100
%109 = load i32, i32* @stderr
%110 = load i8*, i8** %8
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i8* %110, i8* %112)
br label %208
114: ; preds = %100
%115 = load i8**, i8*** %7
%116 = load i8*, i8** %115
%117 = load i32, i32* %13
%118 = zext i32 %117 to i64
%119 = getelementptr inbounds i8, i8* %116, i64 %118
store i8 0, i8* %119
%120 = load i32, i32* %11
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %205
122: ; preds = %114
store i32 0, i32* %16
br label %123
123: ; preds = %201, %122
%124 = load i32, i32* %16
%125 = load i32, i32* %13
%126 = icmp ult i32 %124, %125
br i1 %126, label %127, label %204
127: ; preds = %123
%128 = load i8**, i8*** %7
%129 = load i8*, i8** %128
%130 = load i32, i32* %16
%131 = zext i32 %130 to i64
%132 = getelementptr inbounds i8, i8* %129, i64 %131
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = icmp sge i32 %134, 97
br i1 %135, label %136, label %163
136: ; preds = %127
%137 = load i8**, i8*** %7
%138 = load i8*, i8** %137
%139 = load i32, i32* %16
%140 = zext i32 %139 to i64
%141 = getelementptr inbounds i8, i8* %138, i64 %140
%142 = load i8, i8* %141
%143 = sext i8 %142 to i32
%144 = icmp sle i32 %143, 122
br i1 %144, label %145, label %163
145: ; preds = %136
%146 = load i8**, i8*** %7
%147 = load i8*, i8** %146
%148 = load i32, i32* %16
%149 = zext i32 %148 to i64
%150 = getelementptr inbounds i8, i8* %147, i64 %149
%151 = load i8, i8* %150
%152 = sext i8 %151 to i32
%153 = sub nsw i32 %152, 97
%154 = add nsw i32 %153, 13
%155 = srem i32 %154, 26
%156 = add nsw i32 %155, 97
%157 = trunc i32 %156 to i8
%158 = load i8**, i8*** %7
%159 = load i8*, i8** %158
%160 = load i32, i32* %16
%161 = zext i32 %160 to i64
%162 = getelementptr inbounds i8, i8* %159, i64 %161
store i8 %157, i8* %162
br label %200
163: ; preds = %136, %127
%164 = load i8**, i8*** %7
%165 = load i8*, i8** %164
%166 = load i32, i32* %16
%167 = zext i32 %166 to i64
%168 = getelementptr inbounds i8, i8* %165, i64 %167
%169 = load i8, i8* %168
%170 = sext i8 %169 to i32
%171 = icmp sge i32 %170, 65
br i1 %171, label %172, label %199
172: ; preds = %163
%173 = load i8**, i8*** %7
%174 = load i8*, i8** %173
%175 = load i32, i32* %16
%176 = zext i32 %175 to i64
%177 = getelementptr inbounds i8, i8* %174, i64 %176
%178 = load i8, i8* %177
%179 = sext i8 %178 to i32
%180 = icmp sle i32 %179, 90
br i1 %180, label %181, label %199
181: ; preds = %172
%182 = load i8**, i8*** %7
%183 = load i8*, i8** %182
%184 = load i32, i32* %16
%185 = zext i32 %184 to i64
%186 = getelementptr inbounds i8, i8* %183, i64 %185
%187 = load i8, i8* %186
%188 = sext i8 %187 to i32
%189 = sub nsw i32 %188, 65
%190 = add nsw i32 %189, 13
%191 = srem i32 %190, 26
%192 = add nsw i32 %191, 65
%193 = trunc i32 %192 to i8
%194 = load i8**, i8*** %7
%195 = load i8*, i8** %194
%196 = load i32, i32* %16
%197 = zext i32 %196 to i64
%198 = getelementptr inbounds i8, i8* %195, i64 %197
store i8 %193, i8* %198
br label %199
199: ; preds = %181, %172, %163
br label %200
200: ; preds = %199, %145
br label %201
201: ; preds = %200
%202 = load i32, i32* %16
%203 = add i32 %202, 1
store i32 %203, i32* %16
br label %123
204: ; preds = %123
br label %205
205: ; preds = %204, %114
%206 = load i32*, i32** %12
%207 = call i32 @fclose(i32* %206)
store i32 0, i32* %6
br label %223
208: ; preds = %108, %94, %86, %64, %33, %21
%209 = load i8**, i8*** %7
%210 = load i8*, i8** %209
%211 = icmp ne i8* %210, null
br i1 %211, label %212, label %216
212: ; preds = %208
%213 = load i8**, i8*** %7
%214 = load i8*, i8** %213
%215 = call i32 @free(i8* %214)
br label %216
216: ; preds = %212, %208
%217 = load i32*, i32** %12
%218 = icmp ne i32* %217, null
br i1 %218, label %219, label %222
219: ; preds = %216
%220 = load i32*, i32** %12
%221 = call i32 @fclose(i32* %220)
br label %222
222: ; preds = %219, %216
store i32 -1, i32* %6
br label %223
223: ; preds = %222, %205
%224 = load i32, i32* %6
ret i32 %224
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"Error opening fortune file \22%s\22: fopen(): %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [46 x i8] c"Error seeking fortune file \22%s\22: fseek(): %s\0A\00"
@EOF = global i32 0
@.str.3 = [59 x i8] c"Error reading fortune from \22%s\22: End delimiter not found.\0A\00"
@.str.4 = [46 x i8] c"Error reading fortune from \22%s\22: fgetc(): %s\0A\00"
@.str.5 = [46 x i8] c"Error allocating memory for fortune. malloc()\00"
@.str.6 = [49 x i8] c"Error seeking in fortune file \22%s\22: fseek(): %s\0A\00"
@.str.7 = [46 x i8] c"Error reading fortune from \22%s\22: fread(): %s\0A\00"
define i32 @read_fortune(i8** nocapture %0, i8* %1, i32 %2, i32 %3, i32 %4) {
store i8* null, i8** %0
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %11)
br label %102
13: ; preds = %5
%14 = load i32, i32* @SEEK_SET
%15 = tail call i64 @fseek(i32* %6, i32 %2, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = tail call i32 @fgetc(i32* %6)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %26, label %40
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %24)
br label %102
26: ; preds = %47, %17
%27 = tail call i64 @feof(i32* %6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %102
32: ; preds = %26
%33 = tail call i64 @ferror(i32* %6)
%34 = icmp eq i64 %33, 0
br i1 %34, label %102, label %35
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = tail call i8* @strerror(i32 %37)
%39 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %38)
br label %102
40: ; preds = %17, %47
%41 = phi i32 [ %49, %47 ], [ %18, %17 ]
%42 = phi i32 [ %41, %47 ], [ 0, %17 ]
%43 = phi i32 [ %48, %47 ], [ 0, %17 ]
%44 = icmp eq i32 %42, %3
%45 = icmp eq i32 %41, 10
%46 = and i1 %44, %45
br i1 %46, label %52, label %47
47: ; preds = %40
%48 = add i32 %43, 1
%49 = tail call i32 @fgetc(i32* %6)
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %49, %50
br i1 %51, label %26, label %40
52: ; preds = %40
%53 = add i32 %43, -1
%54 = tail call i8* @malloc(i32 %43)
store i8* %54, i8** %0
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = tail call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
br label %102
58: ; preds = %52
%59 = load i32, i32* @SEEK_SET
%60 = tail call i64 @fseek(i32* %6, i32 %2, i32 %59)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = tail call i8* @strerror(i32 %64)
%66 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %1, i8* %65)
br label %102
67: ; preds = %58
%68 = load i8*, i8** %0
%69 = tail call i32 @fread(i8* %68, i32 1, i32 %53, i32* %6)
%70 = icmp ult i32 %69, %53
br i1 %70, label %71, label %76
71: ; preds = %67
%72 = load i32, i32* @stderr
%73 = load i32, i32* @errno
%74 = tail call i8* @strerror(i32 %73)
%75 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i8* %1, i8* %74)
br label %102
76: ; preds = %67
%77 = load i8*, i8** %0
%78 = zext i32 %53 to i64
%79 = getelementptr inbounds i8, i8* %77, i64 %78
store i8 0, i8* %79
%80 = icmp ne i32 %4, 0
%81 = icmp ne i32 %53, 0
%82 = and i1 %80, %81
br i1 %82, label %83, label %108
83: ; preds = %76, %99
%84 = phi i64 [ %100, %99 ], [ 0, %76 ]
%85 = load i8*, i8** %0
%86 = getelementptr inbounds i8, i8* %85, i64 %84
%87 = load i8, i8* %86
%88 = add i8 %87, -97
%89 = icmp ult i8 %88, 26
br i1 %89, label %93, label %90
90: ; preds = %83
%91 = add i8 %87, -65
%92 = icmp ult i8 %91, 26
br i1 %92, label %93, label %99
93: ; preds = %90, %83
%94 = phi i8 [ -84, %83 ], [ -52, %90 ]
%95 = phi i8 [ 97, %83 ], [ 65, %90 ]
%96 = add i8 %94, %87
%97 = urem i8 %96, 26
%98 = add nuw nsw i8 %97, %95
store i8 %98, i8* %86
br label %99
99: ; preds = %93, %90
%100 = add nuw nsw i64 %84, 1
%101 = icmp eq i64 %100, %78
br i1 %101, label %108, label %83
102: ; preds = %29, %35, %32, %71, %62, %56, %21, %8
%103 = load i8*, i8** %0
%104 = icmp eq i8* %103, null
br i1 %104, label %107, label %105
105: ; preds = %102
%106 = tail call i32 @free(i8* %103)
br label %107
107: ; preds = %105, %102
br i1 %7, label %111, label %108
108: ; preds = %99, %107, %76
%109 = phi i32 [ 0, %76 ], [ -1, %107 ], [ 0, %99 ]
%110 = tail call i32 @fclose(i32* %6)
br label %111
111: ; preds = %108, %107
%112 = phi i32 [ -1, %107 ], [ %109, %108 ]
ret i32 %112
}