#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  FILE *fp = NULL;
  char *buf = NULL;
  struct stat st;
  if (argc < 2) {
    fprintf(stderr, "Error: no file given\n");
    exit(EXIT_FAILURE);
  }
  if (stat(argv[1], &st) == -1) {
    fprintf(stderr, "Error: cannot stat `%s': %s\n", argv[1], strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((buf = malloc((size_t)st.st_size)) == NULL) {
    fprintf(stderr, "Error: cannot allocate memory for `%s': %s\n", argv[1],
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((fp = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Error: cannot open `%s': %s\n", argv[1], strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (fread(buf, 1, (size_t)st.st_size, fp) < (size_t)st.st_size) {
  }
  if (fclose(fp) == EOF) {
    fprintf(stderr, "Warning: cannot close `%s': %s\n", argv[1],
            strerror(errno));
  }
  free(buf);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e5 <main+0x55>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    124b <main+0xbb>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12ae <main+0x11e>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda2(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    131c <main+0x18c>
mov    0x2d01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x28(%rbp),%rax
jae    1341 <main+0x1b1>
jmp    1341 <main+0x1b1>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2c97(%rip),%rcx
cmp    (%rcx),%rax
jne    1398 <main+0x208>
mov    0x2c77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xced(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c18(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1262 <main+0xd2>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
je     127b <main+0xeb>
mov    (%rsp),%r12
mov    %r12,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     129f <main+0x10f>
mov    %rax,%r15
mov    0x8(%r14),%rdi
lea    0xe83(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c3 <main+0x133>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%rax
jne    1245 <main+0xb5>
mov    0x2dbd(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%r14
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe48(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12f4 <main+0x164>
mov    0x2d56(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%r14
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd79(%rip),%rsi
jmp    12e5 <main+0x155>
mov    0x2d32(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%r14
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd72(%rip),%rsi
jmp    12e5 <main+0x155>
mov    0x2d0e(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%r14
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd7c(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [22 x i8] c"Error: no file given\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [29 x i8] c"Error: cannot stat `%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [44 x i8] c"Error: cannot allocate memory for `%s': %s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [29 x i8] c"Error: cannot open `%s': %s\0A\00"
@EOF = global i64 0
@.str.5 = [32 x i8] c"Warning: cannot close `%s': %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i8* null, i8** %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @stat(i8* %19, %struct.stat* %8)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %32
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %16
%33 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%34 = load i64, i64* %33
%35 = call i8* @malloc(i64 %34)
store i8* %35, i8** %7
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %47
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %41, i8* %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %32
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %51, i32** %6
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %63
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %57, i8* %59)
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %47
%64 = load i8*, i8** %7
%65 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%66 = load i64, i64* %65
%67 = load i32*, i32** %6
%68 = call i64 @fread(i8* %64, i32 1, i64 %66, i32* %67)
%69 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%70 = load i64, i64* %69
%71 = icmp ult i64 %68, %70
br i1 %71, label %72, label %73
72: ; preds = %63
br label %73
73: ; preds = %72, %63
%74 = load i32*, i32** %6
%75 = call i64 @fclose(i32* %74)
%76 = load i64, i64* @EOF
%77 = icmp eq i64 %75, %76
br i1 %77, label %78, label %86
78: ; preds = %73
%79 = load i32, i32* @stderr
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 1
%82 = load i8*, i8** %81
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %82, i8* %84)
br label %86
86: ; preds = %78, %73
%87 = load i8*, i8** %7
%88 = call i32 @free(i8* %87)
%89 = load i32, i32* @EXIT_SUCCESS
ret i32 %89
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [22 x i8] c"Error: no file given\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [29 x i8] c"Error: cannot stat `%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [44 x i8] c"Error: cannot allocate memory for `%s': %s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [29 x i8] c"Error: cannot open `%s': %s\0A\00"
@EOF = global i64 0
@.str.5 = [32 x i8] c"Warning: cannot close `%s': %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @stat(i8* %13, %struct.stat* %3)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %11
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%26 = load i64, i64* %25
%27 = tail call i8* @malloc(i64 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %12
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %24
%38 = load i8*, i8** %12
%39 = tail call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %49
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %12
%44 = load i32, i32* @errno
%45 = tail call i8* @strerror(i32 %44)
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %43, i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @exit(i32 %47)
unreachable
49: ; preds = %37
%50 = tail call i64 @fread(i8* %27, i32 1, i64 %26, i32* %39)
%51 = tail call i64 @fclose(i32* %39)
%52 = load i64, i64* @EOF
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %12
%57 = load i32, i32* @errno
%58 = tail call i8* @strerror(i32 %57)
%59 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %56, i8* %58)
br label %60
60: ; preds = %54, %49
%61 = tail call i32 @free(i8* %27)
%62 = load i32, i32* @EXIT_SUCCESS
ret i32 %62
}