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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
size_t lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(size_t);
int open(char *, char);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, size_t);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  if (argc == 1) {
    printf("%s: [file]\n", argv[0]);
    return EXIT_SUCCESS;
  }
  int file = open(argv[1], 'r');
  size_t size = lseek(file, 0, SEEK_END);
  lseek(file, 0, SEEK_SET);
  if (size == -1) {
    perror(argv[0]);
    return EXIT_FAILURE;
  }
  char *contents = malloc(size);
  read(file, contents, size);
  close(file);
  printf("%s\n", contents);
  fflush(stdout);
  return EXIT_SUCCESS;
}


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   $0x1,-0x8(%rbp)
jne    11c4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127a <main+0xfa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x72,%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    122b <main+0xab>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <perror@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127a <main+0xfa>
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <read@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rsi
lea    0xdb1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jne    119d <main+0x1d>
mov    (%r14),%rsi
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
jmp    1216 <main+0x96>
mov    0x8(%r14),%rdi
mov    $0x72,%esi
call   1090 <open@plt>
mov    %eax,%ebp
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,%rbx
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0xffffffffffffffff,%rbx
je     1224 <main+0xa4>
mov    %rbx,%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1060 <read@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe0c(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%r14),%rdi
call   10a0 <perror@plt>
mov    0x2d9d(%rip),%rax
jmp    121d <main+0x9d>

LLVM IR (-O0):
@.str = [12 x i8] c"%s: [file]\0A\00"
@EXIT_SUCCESS = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
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 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_SUCCESS
store i32 %16, i32* %3
br label %50
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @open(i8* %20, i8 signext 114)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = load i32, i32* @SEEK_END
%24 = call i64 @lseek(i32 %22, i32 0, i32 %23)
store i64 %24, i64* %7
%25 = load i32, i32* %6
%26 = load i32, i32* @SEEK_SET
%27 = call i64 @lseek(i32 %25, i32 0, i32 %26)
%28 = load i64, i64* %7
%29 = icmp eq i64 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %17
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @perror(i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %50
36: ; preds = %17
%37 = load i64, i64* %7
%38 = call i8* @malloc(i64 %37)
store i8* %38, i8** %8
%39 = load i32, i32* %6
%40 = load i8*, i8** %8
%41 = load i64, i64* %7
%42 = call i32 @read(i32 %39, i8* %40, i64 %41)
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
%45 = load i8*, i8** %8
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @stdout
%48 = call i32 @fflush(i32 %47)
%49 = load i32, i32* @EXIT_SUCCESS
store i32 %49, i32* %3
br label %50
50: ; preds = %36, %30, %11
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s: [file]\0A\00"
@EXIT_SUCCESS = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %26
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @open(i8* %9, i8 signext 114)
%11 = load i32, i32* @SEEK_END
%12 = tail call i64 @lseek(i32 %10, i32 0, i32 %11)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i64 @lseek(i32 %10, i32 0, i32 %13)
%15 = icmp eq i64 %12, -1
br i1 %15, label %16, label %19
16: ; preds = %7
%17 = load i8*, i8** %1
%18 = tail call i32 @perror(i8* %17)
br label %26
19: ; preds = %7
%20 = tail call i8* @malloc(i64 %12)
%21 = tail call i32 @read(i32 %10, i8* %20, i64 %12)
%22 = tail call i32 @close(i32 %10)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%24 = load i32, i32* @stdout
%25 = tail call i32 @fflush(i32 %24)
br label %26
26: ; preds = %16, %19, %4
%27 = phi i32* [ @EXIT_SUCCESS, %4 ], [ @EXIT_FAILURE, %16 ], [ @EXIT_SUCCESS, %19 ]
%28 = load i32, i32* %27
ret i32 %28
}