#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 extract_file_from_cbfs(char *, char *, char *);
void *loadrom(char *);
int /*<<< orphan*/ printf(char *, ...);
int cbfs_extract(int argc, char **argv) {
  char *romname = argv[1];
  char *cmd = argv[2];
  void *rom = loadrom(romname);
  if (rom == NULL) {
    printf("Could not load ROM image '%s'.\n", romname);
    return 1;
  }
  if (argc != 5) {
    printf("Error: you must specify a CBFS name and a file to dump it in.\n");
    return 1;
  }
  return extract_file_from_cbfs(romname, argv[3], argv[4]);
}


x86 assembly (clang, -O0):
<cbfs_extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <loadrom@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118d <cbfs_extract+0x5d>
mov    -0x18(%rbp),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cd <cbfs_extract+0x9d>
cmpl   $0x5,-0x8(%rbp)
je     11b1 <cbfs_extract+0x81>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cd <cbfs_extract+0x9d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
call   1040 <extract_file_from_cbfs@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbfs_extract>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%r14
mov    %r14,%rdi
call   1060 <loadrom@plt>
test   %rax,%rax
je     1173 <cbfs_extract+0x33>
cmp    $0x5,%ebp
jne    1186 <cbfs_extract+0x46>
mov    0x18(%rbx),%rsi
mov    0x20(%rbx),%rdx
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <extract_file_from_cbfs@plt>
lea    0xe86(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1192 <cbfs_extract+0x52>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Could not load ROM image '%s'.\0A\00"
@.str.1 = [63 x i8] c"Error: you must specify a CBFS name and a file to dump it in.\0A\00"
define i32 @cbfs_extract(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
store i8* %11, i8** %6
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 2
%14 = load i8*, i8** %13
store i8* %14, i8** %7
%15 = load i8*, i8** %6
%16 = call i8* @loadrom(i8* %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %36
22: ; preds = %2
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 5
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %36
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 4
%34 = load i8*, i8** %33
%35 = call i32 @extract_file_from_cbfs(i8* %28, i8* %31, i8* %34)
store i32 %35, i32* %3
br label %36
36: ; preds = %27, %25, %19
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [32 x i8] c"Could not load ROM image '%s'.\0A\00"
@str = [62 x i8] c"Error: you must specify a CBFS name and a file to dump it in.\00"
define i32 @cbfs_extract(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i8* @loadrom(i8* %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %19
9: ; preds = %2
%10 = icmp eq i32 %0, 5
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
br label %19
13: ; preds = %9
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = tail call i32 @extract_file_from_cbfs(i8* %4, i8* %15, i8* %17)
br label %19
19: ; preds = %13, %11, %7
%20 = phi i32 [ 1, %7 ], [ 1, %11 ], [ %18, %13 ]
ret i32 %20
}