#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 option {
  char *member_0;
  float member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
};
struct machine {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ debug_printf(int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getopt_long(int, char **, char *, struct option *, int *);
int /*<<< orphan*/ machine_load_file_executable(struct machine *,
                                                int /*<<< orphan*/ *);
struct machine *machine_new();
#define no_argument 129
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *);
#define required_argument 128
int main(int argc, char **argv) {
  debug_printf(4, "Begin Program\n");
  char *executable_file = NULL;
  int c;
  int option_index = 0;
  while (optind < argc) {
    static struct option long_options[] = {{"file", required_argument, 0, 'f'},
                                           {"help", no_argument, 0, 'h'}};
    c = getopt_long(argc, argv, "f:h", long_options, &option_index);
    switch (c) {
    case 'f':
      executable_file = optarg;
      break;
    case 'h':
      printf("[-f  --file] [file]\n");
      printf("    load $file into memory to be executed\n");
      printf("[-h --help]\n");
      printf("    display this message\n");
      return 0;
    case '?':
      debug_printf(2, "Program exit due to invalid option\n");
      return -1;
    default:
      debug_printf(
          1, "Program exit due to an unknown error during argument parsing\n");
      return -1;
    }
  }
  struct machine *machine = machine_new();
  FILE *fp = NULL;
  if (executable_file) {
    fp = fopen(executable_file, "r");
  } else {
    debug_printf(3, "Executble file is NULL\n");
    return 1;
  }
  machine_load_file_executable(machine, fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4,%edi
lea    0xe6e(%rip),%rsi
call   1040 <debug_printf@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    129d <main+0x12d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe53(%rip),%rdx
lea    0x2e93(%rip),%rcx
lea    -0x20(%rbp),%r8
call   1060 <getopt_long@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3f,%eax
je     125e <main+0xee>
jmp    11ed <main+0x7d>
mov    -0x34(%rbp),%eax
sub    $0x66,%eax
je     120f <main+0x9f>
jmp    11fe <main+0x8e>
mov    -0x34(%rbp),%eax
sub    $0x68,%eax
je     1222 <main+0xb2>
jmp    127b <main+0x10b>
mov    0x2de2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1298 <main+0x128>
lea    0xdf4(%rip),%rdi
call   1070 <printf@plt>
lea    0xdfd(%rip),%rdi
call   1070 <printf@plt>
lea    0xe1c(%rip),%rdi
call   1070 <printf@plt>
lea    0xe1d(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    130e <main+0x19e>
mov    $0x2,%edi
lea    0xe1a(%rip),%rsi
call   1040 <debug_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130e <main+0x19e>
mov    $0x1,%edi
lea    0xe21(%rip),%rsi
call   1040 <debug_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130e <main+0x19e>
jmp    11a6 <main+0x36>
mov    $0x0,%al
call   1080 <machine_new@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12d4 <main+0x164>
mov    -0x18(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
jmp    12f1 <main+0x181>
mov    $0x3,%edi
lea    0xe08(%rip),%rsi
call   1040 <debug_printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130e <main+0x19e>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <machine_load_file_executable@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%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    0xe79(%rip),%rsi
mov    $0x4,%edi
call   1050 <debug_printf@plt>
movl   $0x0,0x4(%rsp)
mov    0x2e40(%rip),%r13
cmp    %ebp,0x0(%r13)
jge    1223 <main+0xb3>
lea    0xe6c(%rip),%r14
lea    0x2eac(%rip),%r15
lea    0x4(%rsp),%r12
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1070 <getopt_long@plt>
cmp    $0x66,%eax
jne    1242 <main+0xd2>
cmp    %ebp,0x0(%r13)
jl     11c0 <main+0x50>
mov    0x2e13(%rip),%rax
mov    (%rax),%rbp
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <machine_new@plt>
test   %rbp,%rbp
je     122a <main+0xba>
mov    %rax,%r14
lea    0xe7f(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <machine_load_file_executable@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
jmp    12a4 <main+0x134>
xor    %eax,%eax
call   1080 <machine_new@plt>
lea    0xe50(%rip),%rsi
mov    $0x3,%edi
call   1050 <debug_printf@plt>
mov    $0x1,%ebx
jmp    12a4 <main+0x134>
cmp    $0x3f,%eax
je     1280 <main+0x110>
cmp    $0x68,%eax
jne    128e <main+0x11e>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    12a4 <main+0x134>
lea    0xd96(%rip),%rsi
mov    $0x2,%edi
jmp    129a <main+0x12a>
lea    0xdac(%rip),%rsi
mov    $0x1,%edi
call   1050 <debug_printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, float, i32, i32 }
%struct.machine = type { i32 }
@.str = [15 x i8] c"Begin Program\0A\00"
@optind = global i32 0
@main.long_options = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), float 1.280000e+02, i32 0, i32 102 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), float 1.290000e+02, i32 0, i32 104 }]
@.str.1 = [5 x i8] c"file\00"
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [4 x i8] c"f:h\00"
@optarg = global i8* null
@.str.4 = [21 x i8] c"[-f --file] [file]\0A\00"
@.str.5 = [43 x i8] c" load $file into memory to be executed\0A\00"
@.str.6 = [13 x i8] c"[-h --help]\0A\00"
@.str.7 = [26 x i8] c" display this message\0A\00"
@.str.8 = [36 x i8] c"Program exit due to invalid option\0A\00"
@.str.9 = [62 x i8] c"Program exit due to an unknown error during argument parsing\0A\00"
@.str.10 = [2 x i8] c"r\00"
@.str.11 = [24 x i8] c"Executble file is NULL\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.machine*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @debug_printf(i32 4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %6
store i32 0, i32* %8
br label %12
12: ; preds = %32, %2
%13 = load i32, i32* @optind
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt_long(i32 %17, i8** %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %8)
store i32 %19, i32* %7
%20 = load i32, i32* %7
switch i32 %20, label %30 [
i32 102, label %21
i32 104, label %23
i32 63, label %28
]
21: ; preds = %16
%22 = load i8*, i8** @optarg
store i8* %22, i8** %6
br label %32
23: ; preds = %16
%24 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
br label %48
28: ; preds = %16
%29 = call i32 @debug_printf(i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %48
30: ; preds = %16
%31 = call i32 @debug_printf(i32 1, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.9, i64 0, i64 0))
store i32 -1, i32* %3
br label %48
32: ; preds = %21
br label %12
33: ; preds = %12
%34 = call %struct.machine* (...) @machine_new()
store %struct.machine* %34, %struct.machine** %9
store i32* null, i32** %10
%35 = load i8*, i8** %6
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i8*, i8** %6
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i32* %39, i32** %10
br label %42
40: ; preds = %33
%41 = call i32 @debug_printf(i32 3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %48
42: ; preds = %37
%43 = load %struct.machine*, %struct.machine** %9
%44 = load i32*, i32** %10
%45 = call i32 @machine_load_file_executable(%struct.machine* %43, i32* %44)
%46 = load i32*, i32** %10
%47 = call i32 @fclose(i32* %46)
store i32 0, i32* %3
br label %48
48: ; preds = %42, %40, %30, %28, %23
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.option = type { i8*, float, i32, i32 }
%struct.machine = type { i32 }
@.str = [15 x i8] c"Begin Program\0A\00"
@optind = global i32 0
@main.long_options = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), float 1.280000e+02, i32 0, i32 102 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), float 1.290000e+02, i32 0, i32 104 }]
@.str.1 = [5 x i8] c"file\00"
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [4 x i8] c"f:h\00"
@optarg = global i8* null
@.str.8 = [36 x i8] c"Program exit due to invalid option\0A\00"
@.str.9 = [62 x i8] c"Program exit due to an unknown error during argument parsing\0A\00"
@.str.10 = [2 x i8] c"r\00"
@.str.11 = [24 x i8] c"Executble file is NULL\0A\00"
@str = [20 x i8] c"[-f --file] [file]\00"
@str.12 = [42 x i8] c" load $file into memory to be executed\00"
@str.13 = [12 x i8] c"[-h --help]\00"
@str.14 = [25 x i8] c" display this message\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = tail call i32 @debug_printf(i32 4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = load i32, i32* @optind
%7 = icmp slt i32 %6, %0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call %struct.machine* (...) @machine_new()
br label %32
10: ; preds = %2, %12
%11 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %3)
switch i32 %11, label %22 [
i32 102, label %12
i32 104, label %15
i32 63, label %20
]
12: ; preds = %10
%13 = load i32, i32* @optind
%14 = icmp slt i32 %13, %0
br i1 %14, label %10, label %24
15: ; preds = %10
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.12, i64 0, i64 0))
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.14, i64 0, i64 0))
br label %34
20: ; preds = %10
%21 = call i32 @debug_printf(i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
br label %34
22: ; preds = %10
%23 = call i32 @debug_printf(i32 1, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.9, i64 0, i64 0))
br label %34
24: ; preds = %12
%25 = load i8*, i8** @optarg
%26 = call %struct.machine* (...) @machine_new()
%27 = icmp eq i8* %25, null
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%30 = call i32 @machine_load_file_executable(%struct.machine* %26, i32* %29)
%31 = call i32 @fclose(i32* %29)
br label %34
32: ; preds = %8, %24
%33 = call i32 @debug_printf(i32 3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
br label %34
34: ; preds = %32, %28, %22, %20, %15
%35 = phi i32 [ -1, %22 ], [ -1, %20 ], [ 0, %15 ], [ 0, %28 ], [ 1, %32 ]
ret i32 %35
}