#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ init_dispatcher(int /*<<< orphan*/ *);
char *malloc(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_file(int /*<<< orphan*/ *, char *, unsigned int);
int /*<<< orphan*/ start_dispatcher();
int main(int argc, char *argv[]) {
  char *fileName = NULL;
  if (argc > 1)
    fileName = argv[1];
  else {
    unsigned int SIZE = 2048;
    char *buffer = malloc(SIZE);
    FILE *readme = fopen("readme.txt", "r");
    if (readme == NULL) {
      printf("ERROR - Could not open readme file\n");
      exit(EXIT_FAILURE);
    }
    read_file(readme, buffer, SIZE);
    printf("%s", buffer);
    fclose(readme);
    return 0;
  }
  FILE *file = fopen(fileName, "r");
  if (file == NULL) {
    printf("ERROR - Could not open file \"%s\"\n", fileName);
    exit(EXIT_FAILURE);
  }
  init_dispatcher(file);
  fclose(file);
  start_dispatcher();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b9 <main+0x39>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1241 <main+0xc1>
movl   $0x800,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
lea    0xe2d(%rip),%rdi
lea    0xe31(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    120a <main+0x8a>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <read_file@plt>
mov    -0x28(%rbp),%rsi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <main+0x120>
mov    -0x18(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1280 <main+0x100>
mov    -0x18(%rbp),%rsi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x38(%rbp),%rdi
call   1050 <init_dispatcher@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x0,%al
call   1070 <start_dispatcher@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11cd <main+0x3d>
mov    0x8(%rsi),%r14
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1228 <main+0x98>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <init_dispatcher@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
call   1080 <start_dispatcher@plt>
jmp    121e <main+0x8e>
mov    $0x800,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0xe1f(%rip),%rdi
lea    0xe23(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     123b <main+0xab>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x800,%edx
call   1070 <read_file@plt>
lea    0xe01(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xde1(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1247 <main+0xb7>
lea    0xdf0(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"readme.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"ERROR - Could not open readme file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [34 x i8] c"ERROR - Could not open file \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
br label %36
17: ; preds = %2
store i32 2048, i32* %7
%18 = load i32, i32* %7
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %8
%20 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %9
%21 = load i32*, i32** %9
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %17
%28 = load i32*, i32** %9
%29 = load i8*, i8** %8
%30 = load i32, i32* %7
%31 = call i32 @read_file(i32* %28, i8* %29, i32 %30)
%32 = load i8*, i8** %8
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i32*, i32** %9
%35 = call i32 @fclose(i32* %34)
store i32 0, i32* %3
br label %52
36: ; preds = %13
%37 = load i8*, i8** %6
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %10
%39 = load i32*, i32** %10
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i8*, i8** %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %36
%47 = load i32*, i32** %10
%48 = call i32 @init_dispatcher(i32* %47)
%49 = load i32*, i32** %10
%50 = call i32 @fclose(i32* %49)
%51 = call i32 (...) @start_dispatcher()
store i32 0, i32* %3
br label %52
52: ; preds = %46, %27
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [11 x i8] c"readme.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [34 x i8] c"ERROR - Could not open file \22%s\22\0A\00"
@str = [35 x i8] c"ERROR - Could not open readme file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %21, label %25
9: ; preds = %2
%10 = tail call dereferenceable_or_null(2048) i8* @malloc(i32 2048)
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %9
%18 = tail call i32 @read_file(i32* %11, i8* %10, i32 2048)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%20 = tail call i32 @fclose(i32* %11)
br label %29
21: ; preds = %4
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %4
%26 = tail call i32 @init_dispatcher(i32* %7)
%27 = tail call i32 @fclose(i32* %7)
%28 = tail call i32 (...) @start_dispatcher()
br label %29
29: ; preds = %25, %17
ret i32 0
}