#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*/ FILE;

/* Variables and functions */
long custom_random(long);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long fread(char *, int, int, int /*<<< orphan*/ *);
long fsize(int /*<<< orphan*/ *);
int /*<<< orphan*/ print_default_verse();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *file;
  long int filesize;
  char buffer[2048 + 1];
  long int buffersize;
  long int start;
  long int bufferstart;
  char *startpointer;
  char *currentpointer;
  if (argc <= 1) {
    printf("No verse file specified!\n");
    print_default_verse();
    return -1;
  }
  file = fopen(argv[1], "r");
  if (!file) {
    printf("Could not open file %1\n", argv[1]);
    print_default_verse();
    return -1;
  }
  filesize = fsize(file);
  start = custom_random(filesize);
  bufferstart = ((0) > (start - 1024) ? (0) : (start - 1024));
  buffersize = fread(buffer, 1, 2048, file);
  fclose(file);
  if (buffersize <= 0) {
    printf("Error reading file!\n");
    print_default_verse();
    return -1;
  }
  buffer[buffersize] = 0;
  start = start - bufferstart;
  startpointer = &buffer[start];
  while (startpointer >= buffer && *startpointer != '%')
    startpointer--;
  if (*startpointer == '%')
    startpointer++;
  currentpointer = startpointer;
  while (*currentpointer) {
    if (*currentpointer == '%') {
      *currentpointer = 0;
      break;
    }
    currentpointer++;
  }
  printf("%s", startpointer);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11b4 <main+0x44>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <print_default_verse@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e8 <main+0x278>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1200 <main+0x90>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <print_default_verse@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e8 <main+0x278>
mov    -0x18(%rbp),%rdi
call   1080 <fsize@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <custom_random@plt>
mov    %rax,-0x840(%rbp)
mov    -0x840(%rbp),%rcx
sub    $0x400,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    1244 <main+0xd4>
xor    %eax,%eax
mov    %rax,-0x860(%rbp)
jmp    1258 <main+0xe8>
mov    -0x840(%rbp),%rax
sub    $0x400,%rax
mov    %rax,-0x860(%rbp)
mov    -0x860(%rbp),%rax
mov    %rax,-0x848(%rbp)
lea    -0x830(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1030 <fread@plt>
mov    %rax,-0x838(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x838(%rbp)
jg     12bf <main+0x14f>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <print_default_verse@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e8 <main+0x278>
mov    -0x838(%rbp),%rax
movb   $0x0,-0x830(%rbp,%rax,1)
mov    -0x840(%rbp),%rax
sub    -0x848(%rbp),%rax
mov    %rax,-0x840(%rbp)
lea    -0x830(%rbp),%rax
add    -0x840(%rbp),%rax
mov    %rax,-0x850(%rbp)
mov    -0x850(%rbp),%rcx
lea    -0x830(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x861(%rbp)
jb     132d <main+0x1bd>
mov    -0x850(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
setne  %al
mov    %al,-0x861(%rbp)
mov    -0x861(%rbp),%al
test   $0x1,%al
jne    1340 <main+0x1d0>
jmp    1357 <main+0x1e7>
mov    -0x850(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x850(%rbp)
jmp    12f8 <main+0x188>
mov    -0x850(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    137c <main+0x20c>
mov    -0x850(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x850(%rbp)
mov    -0x850(%rbp),%rax
mov    %rax,-0x858(%rbp)
mov    -0x858(%rbp),%rax
cmpb   $0x0,(%rax)
je     13d3 <main+0x263>
mov    -0x858(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    13bc <main+0x24c>
mov    -0x858(%rbp),%rax
movb   $0x0,(%rax)
jmp    13d3 <main+0x263>
mov    -0x858(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x858(%rbp)
jmp    138a <main+0x21a>
mov    -0x850(%rbp),%rsi
lea    0xc68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
cmp    $0x1,%edi
jg     11a4 <main+0x24>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
jmp    1264 <main+0xe4>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1252 <main+0xd2>
mov    %rax,%r12
mov    %rax,%rdi
call   1090 <fsize@plt>
mov    %rax,%rdi
call   1080 <custom_random@plt>
mov    %rax,%r15
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <fclose@plt>
test   %rbx,%rbx
jle    1281 <main+0x101>
movb   $0x0,(%rsp,%rbx,1)
cmp    $0x400,%r15
mov    $0x400,%ecx
cmovl  %r15,%rcx
lea    (%rsp,%rcx,1),%rax
test   %rcx,%rcx
js     122e <main+0xae>
nop
cmpb   $0x25,(%rax)
je     122e <main+0xae>
add    $0xffffffffffffffff,%rax
cmp    %r14,%rax
jae    1220 <main+0xa0>
xor    %esi,%esi
cmpb   $0x25,(%rax)
sete   %sil
add    %rax,%rsi
mov    %rsi,%rax
nopl   (%rax)
movzbl (%rax),%ecx
test   %cl,%cl
je     1290 <main+0x110>
cmp    $0x25,%cl
je     128d <main+0x10d>
add    $0x1,%rax
jmp    1240 <main+0xc0>
mov    0x8(%rbx),%rsi
lea    0xda5(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <print_default_verse@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd95(%rip),%rdi
jmp    119a <main+0x1a>
movb   $0x0,(%rax)
lea    0xd83(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1270 <main+0xf0>

LLVM IR (-O0):
@.str = [26 x i8] c"No verse file specified!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Could not open file %1\0A\00"
@.str.3 = [21 x i8] c"Error reading file!\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca [2049 x i8]
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (...) @print_default_verse()
store i32 -1, i32* %3
br label %105
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp ne i32* %24, null
br i1 %25, label %32, label %26
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = call i32 (...) @print_default_verse()
store i32 -1, i32* %3
br label %105
32: ; preds = %19
%33 = load i32*, i32** %6
%34 = call i64 @fsize(i32* %33)
store i64 %34, i64* %7
%35 = load i64, i64* %7
%36 = call i64 @custom_random(i64 %35)
store i64 %36, i64* %10
%37 = load i64, i64* %10
%38 = sub nsw i64 %37, 1024
%39 = icmp sgt i64 0, %38
br i1 %39, label %40, label %41
40: ; preds = %32
br label %44
41: ; preds = %32
%42 = load i64, i64* %10
%43 = sub nsw i64 %42, 1024
br label %44
44: ; preds = %41, %40
%45 = phi i64 [ 0, %40 ], [ %43, %41 ]
store i64 %45, i64* %11
%46 = getelementptr inbounds [2049 x i8], [2049 x i8]* %8, i64 0, i64 0
%47 = load i32*, i32** %6
%48 = call i64 @fread(i8* %46, i32 1, i32 2048, i32* %47)
store i64 %48, i64* %9
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
%51 = load i64, i64* %9
%52 = icmp sle i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %44
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 (...) @print_default_verse()
store i32 -1, i32* %3
br label %105
56: ; preds = %44
%57 = load i64, i64* %9
%58 = getelementptr inbounds [2049 x i8], [2049 x i8]* %8, i64 0, i64 %57
store i8 0, i8* %58
%59 = load i64, i64* %10
%60 = load i64, i64* %11
%61 = sub nsw i64 %59, %60
store i64 %61, i64* %10
%62 = load i64, i64* %10
%63 = getelementptr inbounds [2049 x i8], [2049 x i8]* %8, i64 0, i64 %62
store i8* %63, i8** %12
br label %64
64: ; preds = %75, %56
%65 = load i8*, i8** %12
%66 = getelementptr inbounds [2049 x i8], [2049 x i8]* %8, i64 0, i64 0
%67 = icmp uge i8* %65, %66
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = load i8*, i8** %12
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp ne i32 %71, 37
br label %73
73: ; preds = %68, %64
%74 = phi i1 [ false, %64 ], [ %72, %68 ]
br i1 %74, label %75, label %78
75: ; preds = %73
%76 = load i8*, i8** %12
%77 = getelementptr inbounds i8, i8* %76, i32 -1
store i8* %77, i8** %12
br label %64
78: ; preds = %73
%79 = load i8*, i8** %12
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 37
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = load i8*, i8** %12
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %12
br label %86
86: ; preds = %83, %78
%87 = load i8*, i8** %12
store i8* %87, i8** %13
br label %88
88: ; preds = %99, %86
%89 = load i8*, i8** %13
%90 = load i8, i8* %89
%91 = icmp ne i8 %90, 0
br i1 %91, label %92, label %102
92: ; preds = %88
%93 = load i8*, i8** %13
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 37
br i1 %96, label %97, label %99
97: ; preds = %92
%98 = load i8*, i8** %13
store i8 0, i8* %98
br label %102
99: ; preds = %92
%100 = load i8*, i8** %13
%101 = getelementptr inbounds i8, i8* %100, i32 1
store i8* %101, i8** %13
br label %88
102: ; preds = %97, %88
%103 = load i8*, i8** %12
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %103)
br label %105
105: ; preds = %102, %53, %26, %16
%106 = load i32, i32* %3
ret i32 %106
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Could not open file %1\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@str = [20 x i8] c"Error reading file!\00"
@str.5 = [25 x i8] c"No verse file specified!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2049 x i8]
%4 = getelementptr inbounds [2049 x i8], [2049 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 (...) @print_default_verse()
br label %54
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32 (...) @print_default_verse()
br label %54
18: ; preds = %9
%19 = tail call i64 @fsize(i32* %12)
%20 = tail call i64 @custom_random(i64 %19)
%21 = call i64 @fread(i8* %4, i32 1, i32 2048, i32* %12)
%22 = tail call i32 @fclose(i32* %12)
%23 = icmp slt i64 %21, 1
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%26 = tail call i32 (...) @print_default_verse()
br label %54
27: ; preds = %18
%28 = getelementptr inbounds [2049 x i8], [2049 x i8]* %3, i64 0, i64 %21
store i8 0, i8* %28
%29 = icmp slt i64 %20, 1024
%30 = select i1 %29, i64 %20, i64 1024
%31 = getelementptr inbounds [2049 x i8], [2049 x i8]* %3, i64 0, i64 %30
%32 = icmp slt i64 %30, 0
br i1 %32, label %40, label %33
33: ; preds = %27, %37
%34 = phi i8* [ %38, %37 ], [ %31, %27 ]
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 37
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = getelementptr inbounds i8, i8* %34, i64 -1
%39 = icmp ult i8* %38, %4
br i1 %39, label %40, label %33
40: ; preds = %33, %37, %27
%41 = phi i8* [ %31, %27 ], [ %38, %37 ], [ %34, %33 ]
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 37
%44 = zext i1 %43 to i64
%45 = getelementptr i8, i8* %41, i64 %44
br label %46
46: ; preds = %50, %40
%47 = phi i8* [ %45, %40 ], [ %51, %50 ]
%48 = load i8, i8* %47
switch i8 %48, label %50 [
i8 0, label %52
i8 37, label %49
]
49: ; preds = %46
store i8 0, i8* %47
br label %52
50: ; preds = %46
%51 = getelementptr inbounds i8, i8* %47, i64 1
br label %46
52: ; preds = %46, %49
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %45)
br label %54
54: ; preds = %52, %24, %14, %6
%55 = phi i32 [ -1, %6 ], [ -1, %24 ], [ 0, %52 ], [ -1, %14 ]
ret i32 %55
}