#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 char uint8_t;
struct stat {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
void main(int argc, char *argv[]) {
  char *file = "/text.txt";
  if (argv && argc > 1)
    file = argv[1];
  int fd = open(file, O_RDONLY);
  if (fd == -1) {
    printf("ERROR in open\n");
    exit(1);
  }
  struct stat st;
  stat(file, &st);
  uint8_t *buf = malloc(st.st_size);
  memset(buf, 0, st.st_size);
  read(fd, buf, st.st_size);
  printf("%s", buf);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ab <main+0x3b>
cmpl   $0x1,-0x4(%rbp)
jle    11ab <main+0x3b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e2 <main+0x72>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x20(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <read@plt>
mov    -0x28(%rbp),%rsi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe71(%rip),%rbx
cmp    $0x2,%edi
jl     119d <main+0x1d>
test   %rsi,%rsi
je     119d <main+0x1d>
mov    0x8(%rsi),%rbx
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    11c9 <main+0x49>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <stat@plt>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <read@plt>
lea    0xe05(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [10 x i8] c"/text.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [15 x i8] c"ERROR in open\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %5
%9 = load i8**, i8*** %4
%10 = icmp ne i8** %9, null
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %5
br label %18
18: ; preds = %14, %11, %2
%19 = load i8*, i8** %5
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = load i8*, i8** %5
%29 = call i32 @stat(i8* %28, %struct.stat* %7)
%30 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i8* @malloc(i32 %31)
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @memset(i8* %33, i32 0, i32 %35)
%37 = load i32, i32* %6
%38 = load i8*, i8** %8
%39 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @read(i32 %37, i8* %38, i32 %40)
%42 = load i8*, i8** %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [10 x i8] c"/text.txt\00"
@O_RDONLY = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@str = [14 x i8] c"ERROR in open\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = icmp ne i8** %1, null
%5 = icmp sgt i32 %0, 1
%6 = and i1 %5, %4
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
br label %10
10: ; preds = %7, %2
%11 = phi i8* [ %9, %7 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = bitcast %struct.stat* %3 to i8*
%20 = call i32 @stat(i8* %11, %struct.stat* %3)
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%22 = load i32, i32* %21
%23 = tail call i8* @malloc(i32 %22)
%24 = tail call i32 @memset(i8* %23, i32 0, i32 %22)
%25 = tail call i32 @read(i32 %13, i8* %23, i32 %22)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%27 = tail call i32 @exit(i32 0)
unreachable
}