#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 /*<<< orphan*/);
int /*<<< orphan*/ go();
int /*<<< orphan*/ help();
int /*<<< orphan*/ mdump(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rdump(int /*<<< orphan*/ *);
int /*<<< orphan*/ run(int);
int /*<<< orphan*/ scanf(char *, ...);
void get_command(FILE *dumpsim_file) {
  char buffer[20];
  int start, stop, cycles;
  printf("LC-3b-SIM> ");
  scanf("%s", buffer);
  printf("\n");
  switch (buffer[0]) {
  case 'G':
  case 'g':
    go();
    break;
  case 'M':
  case 'm':
    scanf("%i %i", &start, &stop);
    mdump(dumpsim_file, start, stop);
    break;
  case '?':
    help();
    break;
  case 'Q':
  case 'q':
    printf("Bye.\n");
    exit(0);
  case 'R':
  case 'r':
    if (buffer[1] == 'd' || buffer[1] == 'D')
      rdump(dumpsim_file);
    else {
      scanf("%d", &cycles);
      run(cycles);
    }
    break;
  default:
    printf("Invalid Command\n");
    break;
  }
}


x86 assembly (clang, -O0):
<get_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xf3d(%rip),%rdi
call   1050 <printf@plt>
lea    0xf3d(%rip),%rdi
xor    %eax,%eax
lea    -0x20(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xf38(%rip),%rdi
call   1050 <printf@plt>
movsbl -0x20(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x33,%eax
ja     127c <get_command+0xfc>
mov    -0x38(%rbp),%rax
lea    0xe29(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1040 <go@plt>
jmp    1288 <get_command+0x108>
lea    0xeec(%rip),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1080 <mdump@plt>
jmp    1288 <get_command+0x108>
mov    $0x0,%al
call   1090 <help@plt>
jmp    1288 <get_command+0x108>
lea    0xebc(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
movsbl -0x1f(%rbp),%eax
cmp    $0x64,%eax
je     124f <get_command+0xcf>
movsbl -0x1f(%rbp),%eax
cmp    $0x44,%eax
jne    125d <get_command+0xdd>
mov    -0x8(%rbp),%rdi
call   1060 <rdump@plt>
jmp    1277 <get_command+0xf7>
lea    0xe87(%rip),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x2c(%rbp),%edi
call   1030 <run@plt>
jmp    1288 <get_command+0x108>
lea    0xe6b(%rip),%rdi
call   1050 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_command>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
lea    0xf21(%rip),%rdi
call   1070 <printf@plt>
lea    0xf21(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsbl 0x10(%rsp),%eax
add    $0xffffffc1,%eax
cmp    $0x33,%eax
ja     123e <get_command+0x9e>
lea    0xe1b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
call   1060 <go@plt>
jmp    1268 <get_command+0xc8>
lea    0xee1(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
call   10a0 <mdump@plt>
jmp    1268 <get_command+0xc8>
mov    0x11(%rsp),%al
and    $0xdf,%al
cmp    $0x44,%al
jne    124c <get_command+0xac>
mov    %rbx,%rdi
call   1080 <rdump@plt>
jmp    1268 <get_command+0xc8>
xor    %eax,%eax
call   10b0 <help@plt>
jmp    1268 <get_command+0xc8>
lea    0xea8(%rip),%rdi
call   1040 <puts@plt>
jmp    1268 <get_command+0xc8>
lea    0xe92(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0x8(%rsp),%edi
call   1050 <run@plt>
add    $0x30,%rsp
pop    %rbx
ret
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"LC-3b-SIM> \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c"%i %i\00"
@.str.4 = [6 x i8] c"Bye.\0A\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [17 x i8] c"Invalid Command\0A\00"
define void @get_command(i32* %0) {
%2 = alloca i32*
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
%7 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %45 [
i32 71, label %14
i32 103, label %14
i32 77, label %16
i32 109, label %16
i32 63, label %22
i32 81, label %24
i32 113, label %24
i32 82, label %27
i32 114, label %27
]
14: ; preds = %1, %1
%15 = call i32 (...) @go()
br label %47
16: ; preds = %1, %1
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %4, i32* %5)
%18 = load i32*, i32** %2
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = call i32 @mdump(i32* %18, i32 %19, i32 %20)
br label %47
22: ; preds = %1
%23 = call i32 (...) @help()
br label %47
24: ; preds = %1, %1
%25 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %1, %1
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 100
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 68
br i1 %36, label %37, label %40
37: ; preds = %32, %27
%38 = load i32*, i32** %2
%39 = call i32 @rdump(i32* %38)
br label %44
40: ; preds = %32
%41 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %6)
%42 = load i32, i32* %6
%43 = call i32 @run(i32 %42)
br label %44
44: ; preds = %40, %37
br label %47
45: ; preds = %1
%46 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %47
47: ; preds = %45, %44, %22, %16, %14
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"LC-3b-SIM> \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"%i %i\00"
@.str.5 = [3 x i8] c"%d\00"
@str = [5 x i8] c"Bye.\00"
@str.7 = [16 x i8] c"Invalid Command\00"
define void @get_command(i32* %0) {
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%12 = call i32 @putchar(i32 10)
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
switch i32 %14, label %38 [
i32 71, label %15
i32 103, label %15
i32 77, label %17
i32 109, label %17
i32 63, label %22
i32 81, label %24
i32 113, label %24
i32 82, label %27
i32 114, label %27
]
15: ; preds = %1, %1
%16 = call i32 (...) @go()
br label %40
17: ; preds = %1, %1
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4)
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = call i32 @mdump(i32* %0, i32 %19, i32 %20)
br label %40
22: ; preds = %1
%23 = call i32 (...) @help()
br label %40
24: ; preds = %1, %1
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %1, %1
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 1
%29 = load i8, i8* %28
%30 = and i8 %29, -33
%31 = icmp eq i8 %30, 68
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @rdump(i32* %0)
br label %40
34: ; preds = %27
%35 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %5)
%36 = load i32, i32* %5
%37 = call i32 @run(i32 %36)
br label %40
38: ; preds = %1
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
br label %40
40: ; preds = %32, %34, %38, %22, %17, %15
ret void
}