#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*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ help();
int /*<<< orphan*/ mem_init();
int mem_load(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sys_dump(int);
int /*<<< orphan*/ sys_halt(int);
int /*<<< orphan*/ version();
int /*<<< orphan*/ vm_run();
int main(int argc, char *argv[]) {
  int c;
  char *file;
  while ((c = getopt(argc, argv, "vh")) != -1) {
    switch (c) {
    case 'v':
      version();
      exit(0);
    case 'h':
      help();
      exit(0);
    }
  }
  if (argc > 1) {
    file = argv[argc - 1];
  } else {
    printf("Error: no filename specified.\n");
    sys_dump(0x0);
    sys_halt(0x0);
  }
  mem_init();
  int st = mem_load(file);
  if (st == -1) {
    printf("Error: invalid file (%s).\n", file);
    sys_dump(0x0);
    sys_halt(0x0);
  }
  vm_run();
}


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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3c(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     121b <main+0x7b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x68,%eax
je     1208 <main+0x68>
jmp    11e9 <main+0x49>
mov    -0x28(%rbp),%eax
sub    $0x76,%eax
jne    1216 <main+0x76>
jmp    11fa <main+0x5a>
mov    $0x0,%al
call   1090 <version@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   10b0 <help@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    11b6 <main+0x16>
cmpl   $0x1,-0x8(%rbp)
jle    123f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
jmp    125b <main+0xbb>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <sys_dump@plt>
xor    %edi,%edi
call   1050 <sys_halt@plt>
mov    $0x0,%al
call   1060 <mem_init@plt>
mov    -0x20(%rbp),%rdi
call   1080 <mem_load@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1298 <main+0xf8>
mov    -0x20(%rbp),%rsi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <sys_dump@plt>
xor    %edi,%edi
call   1050 <sys_halt@plt>
mov    $0x0,%al
call   1030 <vm_run@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe3f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <getopt@plt>
cmp    $0xffffffff,%eax
je     11fa <main+0x4a>
cmp    $0x68,%eax
je     1264 <main+0xb4>
cmp    $0x76,%eax
jne    11d0 <main+0x20>
xor    %eax,%eax
call   10a0 <version@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
cmp    $0x2,%ebx
jl     1208 <main+0x58>
add    $0xffffffff,%ebx
mov    (%r14,%rbx,8),%rbx
jmp    1222 <main+0x72>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <sys_dump@plt>
xor    %edi,%edi
call   1060 <sys_halt@plt>
xor    %eax,%eax
call   1070 <mem_init@plt>
mov    %rbx,%rdi
call   1090 <mem_load@plt>
cmp    $0xffffffff,%eax
jne    1255 <main+0xa5>
lea    0xdc6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <sys_dump@plt>
xor    %edi,%edi
call   1060 <sys_halt@plt>
xor    %eax,%eax
call   1040 <vm_run@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   10c0 <help@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"vh\00"
@.str.1 = [31 x i8] c"Error: no filename specified.\0A\00"
@.str.2 = [27 x i8] c"Error: invalid file (%s).\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %22, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %6
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* %6
switch i32 %15, label %22 [
i32 118, label %16
i32 104, label %19
]
16: ; preds = %14
%17 = call i32 (...) @version()
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %14
%20 = call i32 (...) @help()
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %14
br label %9
23: ; preds = %9
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 1
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
%32 = load i8*, i8** %31
store i8* %32, i8** %7
br label %37
33: ; preds = %23
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @sys_dump(i32 0)
%36 = call i32 @sys_halt(i32 0)
br label %37
37: ; preds = %33, %26
%38 = call i32 (...) @mem_init()
%39 = load i8*, i8** %7
%40 = call i32 @mem_load(i8* %39)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = load i8*, i8** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = call i32 @sys_dump(i32 0)
%47 = call i32 @sys_halt(i32 0)
br label %48
48: ; preds = %43, %37
%49 = call i32 (...) @vm_run()
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [3 x i8] c"vh\00"
@.str.2 = [27 x i8] c"Error: invalid file (%s).\0A\00"
@str = [30 x i8] c"Error: no filename specified.\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %4, label %3 [
i32 -1, label %11
i32 118, label %5
i32 104, label %8
]
5: ; preds = %3
%6 = tail call i32 (...) @version()
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %3
%9 = tail call i32 (...) @help()
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %3
%12 = icmp sgt i32 %0, 1
br i1 %12, label %13, label %18
13: ; preds = %11
%14 = add nsw i32 %0, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
br label %22
18: ; preds = %11
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%20 = tail call i32 @sys_dump(i32 0)
%21 = tail call i32 @sys_halt(i32 0)
br label %22
22: ; preds = %18, %13
%23 = phi i8* [ %17, %13 ], [ undef, %18 ]
%24 = tail call i32 (...) @mem_init()
%25 = tail call i32 @mem_load(i8* %23)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%29 = tail call i32 @sys_dump(i32 0)
%30 = tail call i32 @sys_halt(i32 0)
br label %31
31: ; preds = %27, %22
%32 = tail call i32 (...) @vm_run()
ret i32 0
}