#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ get_command(int /*<<< orphan*/ *);
int /*<<< orphan*/ initialize(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *dumpsim_file;
  if (argc < 2) {
    printf("Error: usage: %s <program_file_1> <program_file_2> ...\n", argv[0]);
    exit(1);
  }
  printf("LC-3b Simulator\n\n");
  initialize(argv[1], argc - 1);
  if ((dumpsim_file = fopen("dumpsim", "w")) == NULL) {
    printf("Error: Can't open dumpsim file\n");
    exit(-1);
  }
  while (1)
    get_command(dumpsim_file);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1040 <initialize@plt>
lea    0xe93(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e9 <main+0x99>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11ee <main+0x9e>
mov    -0x18(%rbp),%rdi
call   1050 <get_command@plt>
jmp    11ee <main+0x9e>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jle    11ba <main+0x5a>
mov    %edi,%ebx
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rdi
add    $0xffffffff,%ebx
mov    %ebx,%esi
call   1050 <initialize@plt>
lea    0xea9(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d5 <main+0x75>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <get_command@plt>
jmp    11b0 <main+0x50>
mov    (%r14),%rsi
lea    0xe3c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [56 x i8] c"Error: usage: %s <program_file_1> <program_file_2> ...\0A\00"
@.str.1 = [18 x i8] c"LC-3b Simulator\0A\0A\00"
@.str.2 = [8 x i8] c"dumpsim\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [32 x i8] c"Error: Can't open dumpsim file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
%22 = call i32 @initialize(i8* %19, i32 %21)
%23 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %23, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %15
br label %29
29: ; preds = %28, %29
%30 = load i32*, i32** %6
%31 = call i32 @get_command(i32* %30)
br label %29
}

LLVM IR (-O2):
@.str = [56 x i8] c"Error: usage: %s <program_file_1> <program_file_2> ...\0A\00"
@.str.2 = [8 x i8] c"dumpsim\00"
@.str.3 = [2 x i8] c"w\00"
@str = [17 x i8] c"LC-3b Simulator\0A\00"
@str.5 = [31 x i8] c"Error: Can't open dumpsim file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = add nsw i32 %0, -1
%13 = tail call i32 @initialize(i8* %11, i32 %12)
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %8, %19
%20 = tail call i32 @get_command(i32* %14)
br label %19
}