#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 */

/* Variables and functions */
int /*<<< orphan*/ Debug_ErrorMsgArg(char *, ...);
int /*<<< orphan*/ FileLoad(char const *, void **, size_t *);
int /*<<< orphan*/ GB_Cardridge_Set_Filename(char const *);
scalar_t__ GB_CartridgeLoad(void *, size_t);
int /*<<< orphan*/ GB_PowerOn();
int /*<<< orphan*/ GB_SRAM_Load();
int /*<<< orphan*/ GB_SkipFrame(int /*<<< orphan*/);
int /*<<< orphan*/ free(void *);
int GB_ROMLoad(const char *rom_path) {
  void *ptr;
  size_t size;
  FileLoad(rom_path, &ptr, &size);
  if (ptr == NULL) {
    Debug_ErrorMsgArg("Couldn't load data from %s.", rom_path);
    return 0;
  }
  if (GB_CartridgeLoad(ptr, size) == 0) {
    Debug_ErrorMsgArg("Error while loading cartridge.\n"
                      "Read the console output for details.");
    free(ptr);
    return 0;
  }
  GB_Cardridge_Set_Filename(rom_path);
  GB_SRAM_Load();
  GB_PowerOn();
  GB_SkipFrame(0);
  return 1;
}


x86 assembly (clang, -O0):
<GB_ROMLoad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <FileLoad@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <GB_ROMLoad+0x46>
mov    -0x10(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   10a0 <Debug_ErrorMsgArg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1225 <GB_ROMLoad+0xa5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <GB_CartridgeLoad@plt>
cmp    $0x0,%rax
jne    1200 <GB_ROMLoad+0x80>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   10a0 <Debug_ErrorMsgArg@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1225 <GB_ROMLoad+0xa5>
mov    -0x10(%rbp),%rdi
call   1040 <GB_Cardridge_Set_Filename@plt>
mov    $0x0,%al
call   1090 <GB_SRAM_Load@plt>
mov    $0x0,%al
call   1080 <GB_PowerOn@plt>
xor    %edi,%edi
call   1060 <GB_SkipFrame@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GB_ROMLoad>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1070 <FileLoad@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11d5 <GB_ROMLoad+0x55>
mov    0x10(%rsp),%rsi
call   1050 <GB_CartridgeLoad@plt>
test   %rax,%rax
je     11ea <GB_ROMLoad+0x6a>
mov    %rbx,%rdi
call   1040 <GB_Cardridge_Set_Filename@plt>
xor    %eax,%eax
call   1090 <GB_SRAM_Load@plt>
xor    %eax,%eax
call   1080 <GB_PowerOn@plt>
xor    %edi,%edi
call   1060 <GB_SkipFrame@plt>
mov    $0x1,%ebp
jmp    1204 <GB_ROMLoad+0x84>
lea    0xe24(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <Debug_ErrorMsgArg@plt>
jmp    1204 <GB_ROMLoad+0x84>
lea    0xe2b(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <Debug_ErrorMsgArg@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Couldn't load data from %s.\00"
@.str.1 = [68 x i8] c"Error while loading cartridge.\0ARead the console output for details.\00"
define i32 @GB_ROMLoad(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @FileLoad(i8* %6, i8** %4, i64* %5)
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @Debug_ErrorMsgArg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 0, i32* %2
br label %28
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = call i64 @GB_CartridgeLoad(i8* %14, i64 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = call i32 (i8*, ...) @Debug_ErrorMsgArg(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
store i32 0, i32* %2
br label %28
22: ; preds = %13
%23 = load i8*, i8** %3
%24 = call i32 @GB_Cardridge_Set_Filename(i8* %23)
%25 = call i32 (...) @GB_SRAM_Load()
%26 = call i32 (...) @GB_PowerOn()
%27 = call i32 @GB_SkipFrame(i32 0)
store i32 1, i32* %2
br label %28
28: ; preds = %22, %18, %10
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [28 x i8] c"Couldn't load data from %s.\00"
@.str.1 = [68 x i8] c"Error while loading cartridge.\0ARead the console output for details.\00"
define i32 @GB_ROMLoad(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
%5 = bitcast i64* %3 to i8*
%6 = call i32 @FileLoad(i8* %0, i8** %2, i64* %3)
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @Debug_ErrorMsgArg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %24
11: ; preds = %1
%12 = load i64, i64* %3
%13 = call i64 @GB_CartridgeLoad(i8* %7, i64 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = call i32 (i8*, ...) @Debug_ErrorMsgArg(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %2
%18 = call i32 @free(i8* %17)
br label %24
19: ; preds = %11
%20 = call i32 @GB_Cardridge_Set_Filename(i8* %0)
%21 = call i32 (...) @GB_SRAM_Load()
%22 = call i32 (...) @GB_PowerOn()
%23 = call i32 @GB_SkipFrame(i32 0)
br label %24
24: ; preds = %19, %15, %9
%25 = phi i32 [ 0, %9 ], [ 0, %15 ], [ 1, %19 ]
ret i32 %25
}