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

/* Variables and functions */
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ process(char *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char buf[4096 * 1024];
  char *p;
  if (argc != 2) {
    printf("Usage: %s INPUT_FILE\n\n", argv[0]);
    exit(-1);
  }
  if (access(argv[1], F_OK)) {
    printf("Error: INPUT_FILE %s does not exist\n\n", argv[1]);
    exit(-1);
  }
  freopen(argv[1], "r", stdin);
  while (fgets(buf, sizeof(buf), stdin)) {
    process(buf);
  }
  fclose(stdin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b0 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%rax
je     11ee <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
lea    0xe37(%rip),%rsi
call   1050 <freopen@plt>
lea    -0x400010(%rbp),%rdi
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    $0x400000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1240 <main+0xd0>
lea    -0x400010(%rbp),%rdi
call   1060 <process@plt>
jmp    120b <main+0x9b>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x400020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x400008,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1212 <main+0xa2>
mov    0x8(%rbx),%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
mov    0x8(%rbx),%rcx
test   %rax,%rax
jne    121e <main+0xae>
mov    0x2e40(%rip),%r14
mov    (%r14),%edx
lea    0xe8b(%rip),%rsi
mov    %rcx,%rdi
call   1050 <freopen@plt>
mov    (%r14),%edx
mov    %rsp,%rdi
mov    $0x400000,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     11fd <main+0x8d>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <process@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x400000,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    11e0 <main+0x70>
mov    (%r14),%edi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x400008,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rbx),%rsi
lea    0xde4(%rip),%rdi
jmp    1228 <main+0xb8>
lea    0xdf2(%rip),%rdi
mov    %rcx,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Usage: %s INPUT_FILE\0A\0A\00"
@F_OK = global i32 0
@.str.1 = [38 x i8] c"Error: INPUT_FILE %s does not exist\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4194304 x i8]
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @F_OK
%21 = call i64 @access(i8* %19, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %16
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* @stdin
%34 = call i32 @freopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %40, %29
%36 = getelementptr inbounds [4194304 x i8], [4194304 x i8]* %6, i64 0, i64 0
%37 = load i32, i32* @stdin
%38 = call i64 @fgets(i8* %36, i32 4194304, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = getelementptr inbounds [4194304 x i8], [4194304 x i8]* %6, i64 0, i64 0
%42 = call i32 @process(i8* %41)
br label %35
43: ; preds = %35
%44 = load i32, i32* @stdin
%45 = call i32 @fclose(i32 %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Usage: %s INPUT_FILE\0A\0A\00"
@F_OK = global i32 0
@.str.1 = [38 x i8] c"Error: INPUT_FILE %s does not exist\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4194304 x i8]
%4 = getelementptr inbounds [4194304 x i8], [4194304 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @F_OK
%14 = tail call i64 @access(i8* %12, i32 %13)
%15 = icmp eq i64 %14, 0
%16 = load i8*, i8** %11
br i1 %15, label %20, label %17
17: ; preds = %10
%18 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %10
%21 = load i32, i32* @stdin
%22 = tail call i32 @freopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @stdin
%24 = call i64 @fgets(i8* %4, i32 4194304, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %20, %26
%27 = call i32 @process(i8* %4)
%28 = load i32, i32* @stdin
%29 = call i64 @fgets(i8* %4, i32 4194304, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %26
31: ; preds = %26, %20
%32 = load i32, i32* @stdin
%33 = call i32 @fclose(i32 %32)
ret i32 0
}