#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_END;
char *calloc(long, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *get_file_content(char *filename, long *len, char **buffer) {
  FILE *pFile;
  long lSize;
  size_t result;
  pFile = fopen(filename, "rb");
  if (pFile == NULL) {
    return 0;
  }
  fseek(pFile, 0, SEEK_END);
  lSize = ftell(pFile);
  rewind(pFile);
  *buffer = calloc(lSize, sizeof(char));
  if (*buffer == NULL) {
    fputs("Memory error", stderr);
  }
  result = fread(*buffer, 1, lSize, pFile);
  if (result != lSize) {
    fputs("Reading error", stderr);
  }
  fclose(pFile);
  *len = lSize;
  return 0;
}


x86 assembly (clang, -O0):
<get_file_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c0 <get_file_content+0x40>
movq   $0x0,-0x8(%rbp)
jmp    1281 <get_file_content+0x101>
mov    -0x28(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1225 <get_file_content+0xa5>
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
lea    0xde3(%rip),%rdi
call   1060 <fputs@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     1265 <get_file_content+0xe5>
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
lea    0xdb0(%rip),%rdi
call   1060 <fputs@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_content>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
lea    0xe6b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1233 <get_file_content+0xb3>
mov    %rax,%rbx
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
jne    11fb <get_file_content+0x7b>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
lea    0xe11(%rip),%rdi
call   1060 <fputs@plt>
mov    (%r12),%rax
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    %r15,%rax
je     1228 <get_file_content+0xa8>
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
lea    0xded(%rip),%rdi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [13 x i8] c"Memory error\00"
@stderr = global i32 0
@.str.2 = [14 x i8] c"Reading error\00"
define i8* @get_file_content(i8* %0, i64* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %5
store i64* %1, i64** %6
store i8** %2, i8*** %7
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i8* null, i8** %4
br label %50
16: ; preds = %3
%17 = load i32*, i32** %8
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %17, i32 0, i32 %18)
%20 = load i32*, i32** %8
%21 = call i64 @ftell(i32* %20)
store i64 %21, i64* %9
%22 = load i32*, i32** %8
%23 = call i32 @rewind(i32* %22)
%24 = load i64, i64* %9
%25 = call i8* @calloc(i64 %24, i32 1)
%26 = load i8**, i8*** %7
store i8* %25, i8** %26
%27 = load i8**, i8*** %7
%28 = load i8*, i8** %27
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %16
%31 = load i32, i32* @stderr
%32 = call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %16
%34 = load i8**, i8*** %7
%35 = load i8*, i8** %34
%36 = load i64, i64* %9
%37 = load i32*, i32** %8
%38 = call i64 @fread(i8* %35, i32 1, i64 %36, i32* %37)
store i64 %38, i64* %10
%39 = load i64, i64* %10
%40 = load i64, i64* %9
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %33
%43 = load i32, i32* @stderr
%44 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42, %33
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
%48 = load i64, i64* %9
%49 = load i64*, i64** %6
store i64 %48, i64* %49
store i8* null, i8** %4
br label %50
50: ; preds = %45, %15
%51 = load i8*, i8** %4
ret i8* %51
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [13 x i8] c"Memory error\00"
@stderr = global i32 0
@.str.2 = [14 x i8] c"Reading error\00"
define noalias i8* @get_file_content(i8* nocapture %0, i64* nocapture writeonly %1, i8** nocapture %2) {
%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 %26, label %6
6: ; preds = %3
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %4, i32 0, i32 %7)
%9 = tail call i64 @ftell(i32* %4)
%10 = tail call i32 @rewind(i32* %4)
%11 = tail call i8* @calloc(i64 %9, i32 1)
store i8* %11, i8** %2
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = load i32, i32* @stderr
%15 = tail call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %2
br label %17
17: ; preds = %13, %6
%18 = phi i8* [ %16, %13 ], [ %11, %6 ]
%19 = tail call i64 @fread(i8* %18, i32 1, i64 %9, i32* %4)
%20 = icmp eq i64 %19, %9
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = tail call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %17
%25 = tail call i32 @fclose(i32* %4)
store i64 %9, i64* %1
br label %26
26: ; preds = %3, %24
ret i8* null
}