#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 */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int get_file_content(char const *path, char **out, int verbose) {
  size_t len, read;
  FILE *fp;
  ((void)verbose);
  *out = NULL;
  fp = fopen(path, "rb");
  if (!fp)
    return 1;
  if (fseek(fp, 0, SEEK_END))
    goto error;
  if ((len = (size_t)ftell(fp)) == (size_t)EOF)
    goto error;
  if (fseek(fp, 0, SEEK_SET))
    goto error;
  *out = (char *)malloc(len);
  if (*out == NULL)
    goto error;
  read = fread(*out, 1, len, fp);
  if (read != len)
    goto error;
  fclose(fp);
  return 0;
error:
  fclose(fp);
  free(*out);
  *out = NULL;
  return 1;
}


x86 assembly (clang, -O0):
<get_file_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b9 <get_file_content+0x49>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <get_file_content+0x143>
mov    -0x38(%rbp),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     11dc <get_file_content+0x6c>
jmp    128c <get_file_content+0x11c>
mov    -0x38(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%rax
jne    11fe <get_file_content+0x8e>
jmp    128c <get_file_content+0x11c>
mov    -0x38(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     1221 <get_file_content+0xb1>
jmp    128c <get_file_content+0x11c>
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1247 <get_file_content+0xd7>
jmp    128c <get_file_content+0x11c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1277 <get_file_content+0x107>
jmp    128c <get_file_content+0x11c>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b3 <get_file_content+0x143>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_content>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
movq   $0x0,(%rsi)
lea    0xe78(%rip),%rsi
call   1090 <fopen@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     11f9 <get_file_content+0x89>
mov    %rax,%rbp
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
jne    11e2 <get_file_content+0x72>
mov    %rbp,%rdi
call   1060 <ftell@plt>
mov    %rax,%r15
mov    0x2e1b(%rip),%rax
cmp    (%rax),%r15
je     11e2 <get_file_content+0x72>
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
je     1207 <get_file_content+0x97>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx)
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1070 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11e2 <get_file_content+0x72>
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbp,%rcx
call   1040 <fread@plt>
cmp    %r15,%rax
jne    11e2 <get_file_content+0x72>
mov    %rbp,%rdi
call   1050 <fclose@plt>
xor    %r14d,%r14d
jmp    11f9 <get_file_content+0x89>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@EOF = global i64 0
@SEEK_SET = global i32 0
define i32 @get_file_content(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
%12 = load i8**, i8*** %6
store i8* null, i8** %12
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %10
%15 = load i32*, i32** %10
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %3
store i32 1, i32* %4
br label %65
18: ; preds = %3
%19 = load i32*, i32** %10
%20 = load i32, i32* @SEEK_END
%21 = call i64 @fseek(i32* %19, i32 0, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
br label %58
24: ; preds = %18
%25 = load i32*, i32** %10
%26 = call i64 @ftell(i32* %25)
store i64 %26, i64* %8
%27 = load i64, i64* @EOF
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %24
br label %58
30: ; preds = %24
%31 = load i32*, i32** %10
%32 = load i32, i32* @SEEK_SET
%33 = call i64 @fseek(i32* %31, i32 0, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
br label %58
36: ; preds = %30
%37 = load i64, i64* %8
%38 = call i64 @malloc(i64 %37)
%39 = inttoptr i64 %38 to i8*
%40 = load i8**, i8*** %6
store i8* %39, i8** %40
%41 = load i8**, i8*** %6
%42 = load i8*, i8** %41
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %45
44: ; preds = %36
br label %58
45: ; preds = %36
%46 = load i8**, i8*** %6
%47 = load i8*, i8** %46
%48 = load i64, i64* %8
%49 = load i32*, i32** %10
%50 = call i64 @fread(i8* %47, i32 1, i64 %48, i32* %49)
store i64 %50, i64* %9
%51 = load i64, i64* %9
%52 = load i64, i64* %8
%53 = icmp ne i64 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %45
br label %58
55: ; preds = %45
%56 = load i32*, i32** %10
%57 = call i32 @fclose(i32* %56)
store i32 0, i32* %4
br label %65
58: ; preds = %54, %44, %35, %29, %23
%59 = load i32*, i32** %10
%60 = call i32 @fclose(i32* %59)
%61 = load i8**, i8*** %6
%62 = load i8*, i8** %61
%63 = call i32 @free(i8* %62)
%64 = load i8**, i8*** %6
store i8* null, i8** %64
store i32 1, i32* %4
br label %65
65: ; preds = %58, %55, %17
%66 = load i32, i32* %4
ret i32 %66
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@EOF = global i64 0
@SEEK_SET = global i32 0
define i32 @get_file_content(i8* nocapture %0, i8** nocapture %1, i32 %2) {
store i8* null, i8** %1
%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 %31, label %6
6: ; preds = %3
%7 = load i32, i32* @SEEK_END
%8 = tail call i64 @fseek(i32* %4, i32 0, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %6
%11 = tail call i64 @ftell(i32* %4)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
br i1 %13, label %27, label %14
14: ; preds = %10
%15 = load i32, i32* @SEEK_SET
%16 = tail call i64 @fseek(i32* %4, i32 0, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = tail call i64 @malloc(i64 %11)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %1
%21 = icmp eq i64 %19, 0
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = tail call i64 @fread(i8* %20, i32 1, i64 %11, i32* %4)
%24 = icmp eq i64 %23, %11
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @fclose(i32* %4)
br label %31
27: ; preds = %22, %18, %14, %10, %6
%28 = tail call i32 @fclose(i32* %4)
%29 = load i8*, i8** %1
%30 = tail call i32 @free(i8* %29)
store i8* null, i8** %1
br label %31
31: ; preds = %3, %27, %25
%32 = phi i32 [ 1, %27 ], [ 0, %25 ], [ 1, %3 ]
ret i32 %32
}