#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*/ assemble(int /*<<< orphan*/);
int /*<<< orphan*/ disassemble(int /*<<< orphan*/);
int /*<<< orphan*/ emulate(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
scalar_t__ opterr;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char usage[] = "Usage: %s -ade <filename> | -h\n";
  if (argc < 2) {
    printf(usage, argv[0]);
    exit(1);
  }
  opterr = 0;
  int c;
  while ((c = getopt(argc, argv, "a:d:e:h")) != -1) {
    switch (c) {
    case 'a':
      assemble(optarg);
      break;
    case 'd':
      disassemble(optarg);
      break;
    case 'e':
      emulate(optarg);
      break;
    case 'h':
      printf(usage, argv[0]);
      printf(" -a   assemble 8080 assembly\n");
      printf(" -d   disassmble 8080 assembly\n");
      printf(" -e   emulate an 8080 processer with a given binary file\n");
      printf(" -h   print this message\n");
      break;
    default:
      break;
    }
  }
  exit(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    0xea3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe9d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c8 <main+0x68>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e09(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5c(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     12b0 <main+0x150>
mov    -0x34(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x7,%eax
ja     12a6 <main+0x146>
mov    -0x40(%rbp),%rax
lea    0xdeb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1040 <assemble@plt>
jmp    12ab <main+0x14b>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1060 <disassemble@plt>
jmp    12ab <main+0x14b>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1050 <emulate@plt>
jmp    12ab <main+0x14b>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ab <main+0x14b>
jmp    12ab <main+0x14b>
jmp    11d6 <main+0x76>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
movaps 0xea8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe8c(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x1,%edi
jg     11b4 <main+0x44>
mov    (%rbx),%rsi
mov    %rsp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %edi,%ebp
mov    0x2e1b(%rip),%rax
movq   $0x0,(%rax)
lea    0xe75(%rip),%r14
lea    0xe2e(%rip),%r13
mov    0x2e1f(%rip),%r15
lea    0xedd(%rip),%r12
jmp    1220 <main+0xb0>
mov    (%rbx),%rsi
mov    %rsp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
lea    -0x61(%rax),%ecx
cmp    $0x7,%ecx
ja     125d <main+0xed>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
mov    (%r15),%edi
call   1050 <assemble@plt>
jmp    1220 <main+0xb0>
mov    (%r15),%edi
call   1070 <disassemble@plt>
jmp    1220 <main+0xb0>
mov    (%r15),%edi
call   1060 <emulate@plt>
jmp    1220 <main+0xb0>
cmp    $0xffffffff,%eax
jne    1220 <main+0xb0>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.usage = [32 x i8] c"Usage: %s -ade <filename> | -h\0A\00"
@opterr = global i64 0
@.str = [8 x i8] c"a:d:e:h\00"
@optarg = global i32 0
@.str.1 = [30 x i8] c" -a assemble 8080 assembly\0A\00"
@.str.2 = [32 x i8] c" -d disassmble 8080 assembly\0A\00"
@.str.3 = [58 x i8] c" -e emulate an 8080 processer with a given binary file\0A\00"
@.str.4 = [26 x i8] c" -h print this message\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [32 x i8]* %6 to i8*
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* %12, i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
store i64 0, i64* @opterr
br label %19
19: ; preds = %46, %18
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %22, i32* %7
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %47
24: ; preds = %19
%25 = load i32, i32* %7
switch i32 %25, label %45 [
i32 97, label %26
i32 100, label %29
i32 101, label %32
i32 104, label %35
]
26: ; preds = %24
%27 = load i32, i32* @optarg
%28 = call i32 @assemble(i32 %27)
br label %46
29: ; preds = %24
%30 = load i32, i32* @optarg
%31 = call i32 @disassemble(i32 %30)
br label %46
32: ; preds = %24
%33 = load i32, i32* @optarg
%34 = call i32 @emulate(i32 %33)
br label %46
35: ; preds = %24
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* %36, i8* %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %46
45: ; preds = %24
br label %46
46: ; preds = %45, %35, %32, %29, %26
br label %19
47: ; preds = %19
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.usage = [32 x i8] c"Usage: %s -ade <filename> | -h\0A\00"
@opterr = global i64 0
@.str = [8 x i8] c"a:d:e:h\00"
@optarg = global i32 0
@str = [29 x i8] c" -a assemble 8080 assembly\00"
@str.5 = [31 x i8] c" -d disassmble 8080 assembly\00"
@str.6 = [57 x i8] c" -e emulate an 8080 processer with a given binary file\00"
@str.7 = [25 x i8] c" -h print this message\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = call i32 (i8*, ...) @printf(i8* %4, i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
store i64 0, i64* @opterr
br label %11
11: ; preds = %13, %10
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %12, label %13 [
i32 -1, label %30
i32 97, label %14
i32 100, label %17
i32 101, label %20
i32 104, label %23
]
13: ; preds = %11, %23, %20, %17, %14
br label %11
14: ; preds = %11
%15 = load i32, i32* @optarg
%16 = tail call i32 @assemble(i32 %15)
br label %13
17: ; preds = %11
%18 = load i32, i32* @optarg
%19 = tail call i32 @disassemble(i32 %18)
br label %13
20: ; preds = %11
%21 = load i32, i32* @optarg
%22 = tail call i32 @emulate(i32 %21)
br label %13
23: ; preds = %11
%24 = load i8*, i8** %1
%25 = call i32 (i8*, ...) @printf(i8* %4, i8* %24)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.6, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
br label %13
30: ; preds = %11
%31 = tail call i32 @exit(i32 0)
unreachable
}