#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_SET;
int /*<<< orphan*/ error_handling(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int get_file_size(char *);
unsigned char *file_read(char *_fname, unsigned char *_file_Buf) {
  int file_size = get_file_size(_fname);
  FILE *fp = fopen(_fname, "rb");
  if (fp == NULL)
    error_handling("file can't read\n");
  fseek(fp, 0, SEEK_SET);
  if (fread(_file_Buf, sizeof(char), file_size, fp) == -1)
    error_handling("fread error\n");
  fclose(fp);
  return _file_Buf;
}


x86 assembly (clang, -O0):
<file_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <get_file_size@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a7 <file_read+0x47>
lea    0xe61(%rip),%rdi
call   1050 <error_handling@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    $0xffffffff,%eax
jne    11e5 <file_read+0x85>
lea    0xe34(%rip),%rdi
call   1050 <error_handling@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1070 <get_file_size@plt>
mov    %eax,%ebp
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1194 <file_read+0x34>
lea    0xe74(%rip),%rdi
call   1050 <error_handling@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0xffffffff,%eax
jne    11ca <file_read+0x6a>
lea    0xe4f(%rip),%rdi
call   1050 <error_handling@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [17 x i8] c"file can't read\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [13 x i8] c"fread error\0A\00"
define i8* @file_read(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @get_file_size(i8* %7)
store i32 %8, i32* %5
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @error_handling(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i32*, i32** %6
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = load i32*, i32** %6
%22 = call i32 @fread(i8* %19, i32 1, i32 %20, i32* %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %15
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
%29 = load i8*, i8** %4
ret i8* %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [17 x i8] c"file can't read\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [13 x i8] c"fread error\0A\00"
define i8* @file_read(i8* %0, i8* returned %1) {
%3 = tail call i32 @get_file_size(i8* %0)
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @error_handling(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %4, i32 0, i32 %9)
%11 = tail call i32 @fread(i8* %1, i32 1, i32 %3, i32* %4)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = tail call i32 @fclose(i32* %4)
ret i8* %1
}