#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ gen_cfg_file(char *);
int /*<<< orphan*/ gen_patch_file(char *, scalar_t__);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ stderr;
char *strdup(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int opt;
  char *in_file = NULL;
  uint32_t ppos = 0;
  while ((opt = getopt(argc, argv, "i:o:")) != -1) {
    switch (opt) {
    case 'i':
      in_file = strdup(optarg);
      break;
    default:
      fprintf(stderr, "Usage: %s -f <fw file>\n", argv[0]);
    }
  }
  if (!in_file) {
    fprintf(stderr, "required arguments not provided\n");
    exit(-1);
  };
  ppos = gen_cfg_file(in_file);
  if (ppos)
    gen_patch_file(in_file, ppos);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11f0 <main+0x90>
mov    -0x14(%rbp),%eax
sub    $0x69,%eax
jne    11cd <main+0x6d>
jmp    11b6 <main+0x56>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    11eb <main+0x8b>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1186 <main+0x26>
cmpq   $0x0,-0x20(%rbp)
jne    121c <main+0xbc>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <gen_cfg_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1241 <main+0xe1>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <gen_patch_file@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe89(%rip),%r15
mov    0x2e5a(%rip),%r13
lea    0xe80(%rip),%r12
xor    %r14d,%r14d
jmp    11a1 <main+0x41>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    (%rbx),%rdx
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
cmp    $0xffffffff,%eax
je     11cb <main+0x6b>
cmp    $0x69,%eax
jne    1190 <main+0x30>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1080 <strdup@plt>
mov    %rax,%r14
jmp    11a1 <main+0x41>
test   %r14,%r14
je     11f9 <main+0x99>
mov    %r14,%rdi
call   1030 <gen_cfg_file@plt>
test   %rax,%rax
je     11e8 <main+0x88>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <gen_patch_file@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%r13),%edi
lea    0xe19(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"i:o:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"Usage: %s -f <fw file>\0A\00"
@.str.2 = [33 x i8] c"required arguments not provided\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i64 0, i64* %8
br label %9
9: ; preds = %25, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %6
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = load i32, i32* %6
switch i32 %15, label %19 [
i32 105, label %16
]
16: ; preds = %14
%17 = load i32, i32* @optarg
%18 = call i8* @strdup(i32 %17)
store i8* %18, i8** %7
br label %25
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %19, %16
br label %9
26: ; preds = %9
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %26
%34 = load i8*, i8** %7
%35 = call i64 @gen_cfg_file(i8* %34)
store i64 %35, i64* %8
%36 = load i64, i64* %8
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i8*, i8** %7
%40 = load i64, i64* %8
%41 = call i32 @gen_patch_file(i8* %39, i64 %40)
br label %42
42: ; preds = %38, %33
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"i:o:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"Usage: %s -f <fw file>\0A\00"
@.str.2 = [33 x i8] c"required arguments not provided\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %7, %2
%4 = phi i8* [ %9, %7 ], [ null, %2 ]
br label %5
5: ; preds = %3, %10
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %10 [
i32 -1, label %14
i32 105, label %7
]
7: ; preds = %5
%8 = load i32, i32* @optarg
%9 = tail call i8* @strdup(i32 %8)
br label %3
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %5
14: ; preds = %5
%15 = icmp eq i8* %4, null
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %14
%21 = tail call i64 @gen_cfg_file(i8* %4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @gen_patch_file(i8* %4, i64 %21)
br label %25
25: ; preds = %23, %20
ret i32 0
}