#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 */
struct MINI_Section {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
char *calloc(int, size_t);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
struct MINI_Section *mini_load(char *);
struct MINI_Section *mini_load_file(char *file) {
  size_t size;
  FILE *f = fopen(file, "rb");
  if (f == NULL) {
    return NULL;
  }
  fseek(f, 0, SEEK_END);
  size = ftell(f);
  fseek(f, 0, SEEK_SET);
  char *str;
  str = calloc(1, size + 1);
  if (str == NULL) {
    return NULL;
  }
  fread(str, size, 1, f);
  if (ferror(f)) {
    free(str);
    fclose(f);
    return NULL;
  }
  struct MINI_Section *ini = mini_load(str);
  free(str);
  fclose(f);
  return ini;
}


x86 assembly (clang, -O0):
<mini_load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c8 <mini_load_file+0x38>
movq   $0x0,-0x8(%rbp)
jmp    129a <mini_load_file+0x10a>
mov    -0x20(%rbp),%rdi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122b <mini_load_file+0x9b>
movq   $0x0,-0x8(%rbp)
jmp    129a <mini_load_file+0x10a>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1050 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1273 <mini_load_file+0xe3>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    129a <mini_load_file+0x10a>
mov    -0x28(%rbp),%rdi
call   10b0 <mini_load@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mini_load_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe61(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     121c <mini_load_file+0x8c>
mov    %rax,%rbx
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r12
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0x1(%r12),%rsi
mov    $0x1,%edi
call   1070 <calloc@plt>
test   %rax,%rax
je     123c <mini_load_file+0xac>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1221 <mini_load_file+0x91>
xor    %r14d,%r14d
jmp    122c <mini_load_file+0x9c>
xor    %r14d,%r14d
jmp    123c <mini_load_file+0xac>
mov    %r15,%rdi
call   10b0 <mini_load@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.MINI_Section = type { i32 }
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define %struct.MINI_Section* @mini_load_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 %23, label %4
4: ; preds = %1
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %2, i32 0, i32 %5)
%7 = tail call i64 @ftell(i32* %2)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %2, i32 0, i32 %8)
%10 = add i64 %7, 1
%11 = tail call i8* @calloc(i32 1, i64 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %13
13: ; preds = %4
%14 = tail call i32 @fread(i8* %11, i64 %7, i32 1, i32* %2)
%15 = tail call i64 @ferror(i32* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call %struct.MINI_Section* @mini_load(i8* %11)
br label %19
19: ; preds = %13, %17
%20 = phi %struct.MINI_Section* [ %18, %17 ], [ null, %13 ]
%21 = tail call i32 @free(i8* %11)
%22 = tail call i32 @fclose(i32* %2)
br label %23
23: ; preds = %19, %4, %1
%24 = phi %struct.MINI_Section* [ null, %1 ], [ null, %4 ], [ %20, %19 ]
ret %struct.MINI_Section* %24
}