#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 EINVAL;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ parse(size_t, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, const char *argv[]) {
  if (argc != 2) {
    printf("Usage: %s <filename>\n", argv[0]);
    return EINVAL;
  }
  FILE *f = fopen(argv[1], "r");
  char *buffer = malloc(1000000);
  size_t len = fread(buffer, 1, 1000000, f);
  if (!feof(f)) {
    printf("read error\n");
  }
  parse(len, buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a6 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    121b <main+0xbb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0xf4240,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xf4240,%edx
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
jne    1207 <main+0xa7>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <parse@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11d9 <main+0x69>
mov    0x8(%rsi),%rdi
lea    0xe9a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    $0xf4240,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0xf4240,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11ca <main+0x5a>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <parse@plt>
xor    %eax,%eax
jmp    11f3 <main+0x83>
mov    (%rsi),%rsi
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Usage: %s <filename>\0A\00"
@EINVAL = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"read error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EINVAL
store i32 %16, i32* %3
br label %35
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = call i8* @malloc(i32 1000000)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = load i32*, i32** %6
%25 = call i64 @fread(i8* %23, i32 1, i32 1000000, i32* %24)
store i64 %25, i64* %8
%26 = load i32*, i32** %6
%27 = call i32 @feof(i32* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %17
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %17
%32 = load i64, i64* %8
%33 = load i8*, i8** %7
%34 = call i32 @parse(i64 %32, i8* %33)
store i32 0, i32* %3
br label %35
35: ; preds = %31, %11
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [22 x i8] c"Usage: %s <filename>\0A\00"
@EINVAL = global i32 0
@.str.1 = [2 x i8] c"r\00"
@str = [11 x i8] c"read error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @EINVAL
br label %20
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call dereferenceable_or_null(1000000) i8* @malloc(i32 1000000)
%13 = tail call i64 @fread(i8* %12, i32 1, i32 1000000, i32* %11)
%14 = tail call i32 @feof(i32* %11)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %8
%19 = tail call i32 @parse(i64 %13, i8* %12)
br label %20
20: ; preds = %18, %4
%21 = phi i32 [ %7, %4 ], [ 0, %18 ]
ret i32 %21
}