#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*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
char *malloc(size_t);
int run(char *);
int /*<<< orphan*/ stderr;
int run_file(char *path) {
  char *buffer = NULL;
  FILE *file = NULL;
  size_t length;
  file = fopen(path, "rb");
  if (file == NULL) {
    fputs("Input file not opened", stderr);
    exit(EXIT_FAILURE);
  }
  fseek(file, 0, SEEK_END);
  length = (size_t)ftell(file);
  fseek(file, 0, SEEK_SET);
  buffer = malloc(length);
  if (buffer) {
    fread(buffer, 1, length, file);
  }
  fclose(file);
  return run(buffer);
}


x86 assembly (clang, -O0):
<run_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ee <run_file+0x5e>
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
lea    0xe28(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1251 <run_file+0xc1>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1050 <run@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_file>:
push   %r15
push   %r14
push   %rbx
lea    0xe64(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1212 <run_file+0x82>
mov    %rax,%rbx
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r14
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11fd <run_file+0x6d>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <run@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
lea    0xde1(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [22 x i8] c"Input file not opened\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @run_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
store i32* null, i32** %4
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load i32*, i32** %4
%17 = load i32, i32* @SEEK_END
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = load i32*, i32** %4
%20 = call i64 @ftell(i32* %19)
store i64 %20, i64* %5
%21 = load i32*, i32** %4
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i64, i64* %5
%25 = call i8* @malloc(i64 %24)
store i8* %25, i8** %3
%26 = load i8*, i8** %3
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %33
28: ; preds = %15
%29 = load i8*, i8** %3
%30 = load i64, i64* %5
%31 = load i32*, i32** %4
%32 = call i32 @fread(i8* %29, i32 1, i64 %30, i32* %31)
br label %33
33: ; preds = %28, %15
%34 = load i32*, i32** %4
%35 = call i32 @fclose(i32* %34)
%36 = load i8*, i8** %3
%37 = call i32 @run(i8* %36)
ret i32 %37
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [22 x i8] c"Input file not opened\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @run_file(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %2, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %2)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %2, i32 0, i32 %13)
%15 = tail call i8* @malloc(i64 %12)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %9
%18 = tail call i32 @fread(i8* %15, i32 1, i64 %12, i32* %2)
br label %19
19: ; preds = %17, %9
%20 = tail call i32 @fclose(i32* %2)
%21 = tail call i32 @run(i8* %15)
ret i32 %21
}