#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*/ uint8_t;
typedef scalar_t__ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, scalar_t__, int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(scalar_t__);
uint8_t *ReadFile(uint8_t *filename, uint32_t *size) {
  if (!filename || !size) {
    goto exit;
  }
  FILE *file = NULL;
  uint32_t file_len = 0;
  file = fopen(filename, "rb");
  if (!file) {
    goto exit;
  }
  fseek(file, 0, SEEK_END);
  file_len = ftell(file);
  fseek(file, 0, SEEK_SET);
  uint8_t *bin = (uint8_t *)malloc(file_len + 1);
  if (!bin) {
    goto fail_malloc;
  }
  if (!fread(bin, file_len, 1, file)) {
    goto fail_read;
  }
  *size = file_len;
  return bin;
fail_read:
  free(bin);
fail_malloc:
  fclose(file);
exit:
  return NULL;
}


x86 assembly (clang, -O0):
<ReadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1196 <ReadFile+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    119b <ReadFile+0x2b>
jmp    1273 <ReadFile+0x103>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cf <ReadFile+0x5f>
jmp    1273 <ReadFile+0x103>
mov    -0x20(%rbp),%rdi
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1225 <ReadFile+0xb5>
jmp    126a <ReadFile+0xfa>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%eax
jne    1249 <ReadFile+0xd9>
jmp    1261 <ReadFile+0xf1>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    127b <ReadFile+0x10b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     1214 <ReadFile+0xa4>
mov    %rsi,%r14
test   %rsi,%rsi
je     1214 <ReadFile+0xa4>
lea    0xe6a(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1212 <ReadFile+0xa2>
mov    %rax,%r15
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1060 <ftell@plt>
mov    %rax,%r12
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0x1(%r12),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     120a <ReadFile+0x9a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     1202 <ReadFile+0x92>
mov    %r12,(%r14)
jmp    1214 <ReadFile+0xa4>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
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
@SEEK_SET = global i32 0
define i32* @ReadFile(i32* %0, i64* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
store i32* %0, i32** %4
store i64* %1, i64** %5
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i64*, i64** %5
%13 = icmp ne i64* %12, null
br i1 %13, label %15, label %14
14: ; preds = %11, %2
br label %54
15: ; preds = %11
store i32* null, i32** %6
store i64 0, i64* %7
%16 = load i32*, i32** %4
%17 = call i32* @fopen(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %15
br label %54
21: ; preds = %15
%22 = load i32*, i32** %6
%23 = load i32, i32* @SEEK_END
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i32*, i32** %6
%26 = call i64 @ftell(i32* %25)
store i64 %26, i64* %7
%27 = load i32*, i32** %6
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %27, i32 0, i32 %28)
%30 = load i64, i64* %7
%31 = add nsw i64 %30, 1
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to i32*
store i32* %33, i32** %8
%34 = load i32*, i32** %8
%35 = icmp ne i32* %34, null
br i1 %35, label %37, label %36
36: ; preds = %21
br label %51
37: ; preds = %21
%38 = load i32*, i32** %8
%39 = load i64, i64* %7
%40 = load i32*, i32** %6
%41 = call i32 @fread(i32* %38, i64 %39, i32 1, i32* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %37
br label %48
44: ; preds = %37
%45 = load i64, i64* %7
%46 = load i64*, i64** %5
store i64 %45, i64* %46
%47 = load i32*, i32** %8
store i32* %47, i32** %3
br label %55
48: ; preds = %43
%49 = load i32*, i32** %8
%50 = call i32 @free(i32* %49)
br label %51
51: ; preds = %48, %36
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
br label %54
54: ; preds = %51, %20, %14
store i32* null, i32** %3
br label %55
55: ; preds = %54, %44
%56 = load i32*, i32** %3
ret i32* %56
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32* @ReadFile(i32* %0, i64* writeonly %1) {
%3 = icmp ne i32* %0, null
%4 = icmp ne i64* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %27
6: ; preds = %2
%7 = tail call i32* @fopen(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %27, label %9
9: ; preds = %6
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %7, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %7)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %7, i32 0, i32 %13)
%15 = add nsw i64 %12, 1
%16 = tail call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i32*
%18 = icmp eq i64 %16, 0
br i1 %18, label %25, label %19
19: ; preds = %9
%20 = tail call i32 @fread(i32* %17, i64 %12, i32 1, i32* %7)
%21 = icmp eq i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %19
store i64 %12, i64* %1
br label %27
23: ; preds = %19
%24 = tail call i32 @free(i32* %17)
br label %25
25: ; preds = %9, %23
%26 = tail call i32 @fclose(i32* %7)
br label %27
27: ; preds = %25, %2, %6, %22
%28 = phi i32* [ %17, %22 ], [ null, %6 ], [ null, %2 ], [ null, %25 ]
ret i32* %28
}