#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*/ SEEK_END;
int /*<<< orphan*/ do_file(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
size_t fread(char *, size_t, int, int /*<<< orphan*/ *);
long fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
main(int argc, char **argv) {
  FILE *in;
  char *progname;
  long lsize;
  size_t size, nread;
  char *buffer, *bufend;
  progname = *argv;
  if (argc != 2) {
    fprintf(stderr, "usage: %s input-file\n", progname);
    exit(1);
  }
  if ((in = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "%s Can't open input file\n", progname);
    exit(2);
  }
  if ((lsize = fseek(in, 0L, SEEK_END)) < 0L) {
    fprintf(stderr, "%s fseek() fails\n", progname);
    exit(3);
  }
  lsize = ftell(in);
  rewind(in);
  size = (size_t)lsize;
  if (lsize != (long)size) {
    fprintf(stderr, "%s file too large\n", progname);
    exit(4);
  }
  if ((buffer = (char *)malloc(size)) == NULL) {
    fprintf(stderr, "%s malloc() failed\n", progname);
    exit(5);
  }
  bufend = buffer + size;
  if ((nread = fread(buffer, size, 1, in)) != 1) {
    fprintf(stderr, "%s fread() failed\n", progname);
    exit(6);
  }
  do_file(buffer, bufend);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     11d7 <main+0x47>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe38(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe30(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121c <main+0x8c>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe0b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    1263 <main+0xd3>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdde(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     12b2 <main+0x122>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xda1(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    12ec <main+0x15c>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd7a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x1,%rax
je     133f <main+0x1af>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd3b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x6,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1030 <do_file@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%r14
cmp    $0x2,%edi
jne    123c <main+0xac>
mov    0x8(%rsi),%rdi
lea    0xe67(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     125e <main+0xce>
mov    %rax,%r12
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
test   %rax,%rax
js     1280 <main+0xf0>
mov    %r12,%rdi
call   1070 <ftell@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1050 <rewind@plt>
mov    %r15,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     12a2 <main+0x112>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    $0x1,%rax
jne    12c4 <main+0x134>
mov    %rbx,%rsi
add    %r15,%rsi
mov    %rbx,%rdi
call   1030 <do_file@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x6,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s input-file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"%s Can't open input file\0A\00"
@SEEK_END = global i32 0
@.str.3 = [18 x i8] c"%s fseek() fails\0A\00"
@.str.4 = [19 x i8] c"%s file too large\0A\00"
@.str.5 = [20 x i8] c"%s malloc() failed\0A\00"
@.str.6 = [19 x i8] c"%s fread() failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = load i8**, i8*** %4
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %6
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %5
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %6
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 2)
unreachable
32: ; preds = %21
%33 = load i32*, i32** %5
%34 = load i32, i32* @SEEK_END
%35 = call i64 @fseek(i32* %33, i64 0, i32 %34)
store i64 %35, i64* %7
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %6
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 3)
unreachable
42: ; preds = %32
%43 = load i32*, i32** %5
%44 = call i64 @ftell(i32* %43)
store i64 %44, i64* %7
%45 = load i32*, i32** %5
%46 = call i32 @rewind(i32* %45)
%47 = load i64, i64* %7
store i64 %47, i64* %8
%48 = load i64, i64* %7
%49 = load i64, i64* %8
%50 = icmp ne i64 %48, %49
br i1 %50, label %51, label %56
51: ; preds = %42
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %6
%54 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 4)
unreachable
56: ; preds = %42
%57 = load i64, i64* %8
%58 = call i64 @malloc(i64 %57)
%59 = inttoptr i64 %58 to i8*
store i8* %59, i8** %10
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %66
61: ; preds = %56
%62 = load i32, i32* @stderr
%63 = load i8*, i8** %6
%64 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %63)
%65 = call i32 @exit(i32 5)
unreachable
66: ; preds = %56
%67 = load i8*, i8** %10
%68 = load i64, i64* %8
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8* %69, i8** %11
%70 = load i8*, i8** %10
%71 = load i64, i64* %8
%72 = load i32*, i32** %5
%73 = call i64 @fread(i8* %70, i64 %71, i32 1, i32* %72)
store i64 %73, i64* %9
%74 = icmp ne i64 %73, 1
br i1 %74, label %75, label %80
75: ; preds = %66
%76 = load i32, i32* @stderr
%77 = load i8*, i8** %6
%78 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %77)
%79 = call i32 @exit(i32 6)
unreachable
80: ; preds = %66
%81 = load i8*, i8** %10
%82 = load i8*, i8** %11
%83 = call i32 @do_file(i8* %81, i8* %82)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s input-file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"%s Can't open input file\0A\00"
@SEEK_END = global i32 0
@.str.3 = [18 x i8] c"%s fseek() fails\0A\00"
@.str.5 = [20 x i8] c"%s malloc() failed\0A\00"
@.str.6 = [19 x i8] c"%s fread() failed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %3)
%8 = tail call i32 @exit(i32 1)
unreachable
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 i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %9
%19 = load i32, i32* @SEEK_END
%20 = tail call i64 @fseek(i32* %12, i64 0, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%25 = tail call i32 @exit(i32 3)
unreachable
26: ; preds = %18
%27 = tail call i64 @ftell(i32* %12)
%28 = tail call i32 @rewind(i32* %12)
%29 = tail call i64 @malloc(i64 %27)
%30 = inttoptr i64 %29 to i8*
%31 = icmp eq i64 %29, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%35 = tail call i32 @exit(i32 5)
unreachable
36: ; preds = %26
%37 = tail call i64 @fread(i8* %30, i64 %27, i32 1, i32* %12)
%38 = icmp eq i64 %37, 1
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %3)
%42 = tail call i32 @exit(i32 6)
unreachable
43: ; preds = %36
%44 = getelementptr inbounds i8, i8* %30, i64 %27
%45 = tail call i32 @do_file(i8* %30, i8* %44)
ret i32 0
}