#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 *, ...);
int 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)) {
    printf("%d\n", 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     11b2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%rax
je     11f2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
lea    0xe33(%rip),%rsi
call   1050 <freopen@plt>
lea    -0x400010(%rbp),%rdi
mov    0x2dcb(%rip),%rax
mov    (%rax),%edx
mov    $0x400000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1254 <main+0xe4>
lea    -0x400010(%rbp),%rdi
call   1060 <process@plt>
mov    %eax,%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120f <main+0x9f>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x400020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400000,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1220 <main+0xb0>
mov    0x8(%rbx),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
mov    0x8(%rbx),%rcx
test   %rax,%rax
jne    122c <main+0xbc>
mov    0x2e3a(%rip),%r15
mov    (%r15),%edx
lea    0xe85(%rip),%rsi
mov    %rcx,%rdi
call   1050 <freopen@plt>
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x400000,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1209 <main+0x99>
mov    %rsp,%rbx
lea    0xe60(%rip),%r14
nop
mov    %rbx,%rdi
call   1060 <process@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x400000,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    11e0 <main+0x70>
mov    (%r15),%edi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x400000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%rbx),%rsi
lea    0xdd6(%rip),%rdi
jmp    1236 <main+0xc6>
lea    0xde4(%rip),%rdi
mov    %rcx,%rsi
xor    %eax,%eax
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
@.str.3 = [4 x i8] c"%d\0A\00"
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 (i8*, ...) @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 (i8*, ...) @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 %44
40: ; preds = %35
%41 = getelementptr inbounds [4194304 x i8], [4194304 x i8]* %6, i64 0, i64 0
%42 = call i32 @process(i8* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %42)
br label %35
44: ; preds = %35
%45 = load i32, i32* @stdin
%46 = call i32 @fclose(i32 %45)
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
@.str.3 = [4 x i8] c"%d\0A\00"
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 (i8*, ...) @printf(i8* dereferenceable(1) 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 (i8*, ...) @printf(i8* dereferenceable(1) 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 %32, label %26
26: ; preds = %20, %26
%27 = call i32 @process(i8* %4)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @stdin
%30 = call i64 @fgets(i8* %4, i32 4194304, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %26
32: ; preds = %26, %20
%33 = load i32, i32* @stdin
%34 = call i32 @fclose(i32 %33)
ret i32 0
}