#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *load_file_memory(char *file_name) {
  FILE *file = NULL;
  char *buffer_file = NULL;
  long file_size = 0;
  size_t result = 0;
  file = fopen(file_name, "r");
  fseek(file, 0, SEEK_END);
  file_size = ftell(file);
  rewind(file);
  if (file_size <= 0) {
    printf("File %s is empty.\n", file_name);
    exit(EXIT_FAILURE);
  }
  file_size += 1;
  buffer_file = (char *)malloc(sizeof(char) * file_size);
  if (!buffer_file) {
    printf("Memory error!\n");
    exit(EXIT_FAILURE);
  }
  result = fread(buffer_file, 1, (file_size - 1), file);
  if (result != (file_size - 1)) {
    printf("Reading error!\n");
    exit(EXIT_FAILURE);
  }
  buffer_file[file_size] = '\0';
  fclose(file);
  return buffer_file;
}


x86 assembly (clang, -O0):
<load_file_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <rewind@plt>
cmpq   $0x0,-0x20(%rbp)
jg     1225 <load_file_memory+0x95>
mov    -0x8(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    126b <load_file_memory+0xdb>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
je     12ba <load_file_memory+0x12a>
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file_memory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe4e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
call   1080 <ftell@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1070 <rewind@plt>
test   %r12,%r12
jle    122e <load_file_memory+0x8e>
lea    0x1(%r12),%r14
mov    %r14d,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1241 <load_file_memory+0xa1>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r15,%rcx
call   1040 <fread@plt>
cmp    %r12,%rax
jne    124a <load_file_memory+0xaa>
movb   $0x0,(%rbx,%r14,1)
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdcd(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1256 <load_file_memory+0xb6>
lea    0xdcd(%rip),%rdi
jmp    1251 <load_file_memory+0xb1>
lea    0xdd2(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.1 = [19 x i8] c"File %s is empty.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [15 x i8] c"Memory error!\0A\00"
@.str.3 = [16 x i8] c"Reading error!\0A\00"
define i8* @load_file_memory(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %2
store i32* null, i32** %3
store i8* null, i8** %4
store i64 0, i64* %5
store i64 0, i64* %6
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = load i32, i32* @SEEK_END
%11 = call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = load i32*, i32** %3
%13 = call i64 @ftell(i32* %12)
store i64 %13, i64* %5
%14 = load i32*, i32** %3
%15 = call i32 @rewind(i32* %14)
%16 = load i64, i64* %5
%17 = icmp sle i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %1
%19 = load i8*, i8** %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %1
%24 = load i64, i64* %5
%25 = add nsw i64 %24, 1
store i64 %25, i64* %5
%26 = load i64, i64* %5
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %4
%31 = load i8*, i8** %4
%32 = icmp ne i8* %31, null
br i1 %32, label %37, label %33
33: ; preds = %23
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %23
%38 = load i8*, i8** %4
%39 = load i64, i64* %5
%40 = sub nsw i64 %39, 1
%41 = load i32*, i32** %3
%42 = call i64 @fread(i8* %38, i32 1, i64 %40, i32* %41)
store i64 %42, i64* %6
%43 = load i64, i64* %6
%44 = load i64, i64* %5
%45 = sub nsw i64 %44, 1
%46 = icmp ne i64 %43, %45
br i1 %46, label %47, label %51
47: ; preds = %37
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %37
%52 = load i8*, i8** %4
%53 = load i64, i64* %5
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8 0, i8* %54
%55 = load i32*, i32** %3
%56 = call i32 @fclose(i32* %55)
%57 = load i8*, i8** %4
ret i8* %57
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.1 = [19 x i8] c"File %s is empty.\0A\00"
@EXIT_FAILURE = global i32 0
@str = [14 x i8] c"Memory error!\00"
@str.4 = [15 x i8] c"Reading error!\00"
define i8* @load_file_memory(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @SEEK_END
%4 = tail call i32 @fseek(i32* %2, i32 0, i32 %3)
%5 = tail call i64 @ftell(i32* %2)
%6 = tail call i32 @rewind(i32* %2)
%7 = icmp slt i64 %5, 1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = add nuw nsw i64 %5, 1
%14 = trunc i64 %13 to i32
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
%23 = tail call i64 @fread(i8* %16, i32 1, i64 %5, i32* %2)
%24 = icmp eq i64 %23, %5
br i1 %24, label %29, label %25
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %22
%30 = getelementptr inbounds i8, i8* %16, i64 %13
store i8 0, i8* %30
%31 = tail call i32 @fclose(i32* %2)
ret i8* %16
}