#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*/ cleanFilename(char *);
int /*<<< orphan*/ interrupt(int, int, char *, ...);
scalar_t__ strncmp(char *, char *, int);
int main() {
  char buffer[80];
  char *filename;
  char fileContentBuffer[13312];
  while (1) {
    buffer[0] = '\0';
    filename = 0;
    fileContentBuffer[0] = '\0';
    interrupt(0x21, 0, "SHELL> ", 0, 0);
    interrupt(0x21, 1, buffer, 0, 0);
    if (strncmp(buffer, "type ", 5)) {
      filename = buffer + 5;
      cleanFilename(filename);
      interrupt(0x21, 3, filename, fileContentBuffer, 0);
      interrupt(0x21, 0, fileContentBuffer, 0, 0);
    } else if (strncmp(buffer, "execute ", 8)) {
      filename = buffer + 8;
      cleanFilename(filename);
      interrupt(0x21, 4, filename, 0x2000, 0);
    } else if (strncmp(buffer, "exit ", 5)) {
      return 0;
    } else {
      interrupt(0x21, 0, "Bad Command!\r\n", 0, 0);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3470,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movb   $0x0,-0x3470(%rbp)
mov    $0x21,%edi
xor    %r8d,%r8d
lea    0xe9c(%rip),%rdx
mov    %r8d,%esi
mov    %r8d,%ecx
mov    $0x0,%al
call   1050 <interrupt@plt>
lea    -0x60(%rbp),%rdx
mov    $0x21,%edi
mov    $0x1,%esi
xor    %r8d,%r8d
mov    %r8d,%ecx
mov    $0x0,%al
call   1050 <interrupt@plt>
lea    -0x60(%rbp),%rdi
lea    0xe71(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1200 <main+0xd0>
lea    -0x60(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
call   1030 <cleanFilename@plt>
mov    -0x68(%rbp),%rdx
lea    -0x3470(%rbp),%rcx
mov    $0x21,%edi
mov    $0x3,%esi
xor    %r8d,%r8d
mov    $0x0,%al
call   1050 <interrupt@plt>
lea    -0x3470(%rbp),%rdx
mov    $0x21,%edi
xor    %r8d,%r8d
mov    %r8d,%esi
mov    %r8d,%ecx
mov    $0x0,%al
call   1050 <interrupt@plt>
jmp    12a6 <main+0x176>
lea    -0x60(%rbp),%rdi
lea    0xe03(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1256 <main+0x126>
lea    -0x60(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
call   1030 <cleanFilename@plt>
mov    -0x68(%rbp),%rdx
mov    $0x21,%edi
mov    $0x4,%esi
mov    $0x2000,%ecx
xor    %r8d,%r8d
mov    $0x0,%al
call   1050 <interrupt@plt>
jmp    12a1 <main+0x171>
lea    -0x60(%rbp),%rdi
lea    0xdb6(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1280 <main+0x150>
xor    %eax,%eax
add    $0x3470,%rsp
pop    %rbp
ret
mov    $0x21,%edi
xor    %r8d,%r8d
lea    0xd8e(%rip),%rdx
mov    %r8d,%esi
mov    %r8d,%ecx
mov    $0x0,%al
call   1050 <interrupt@plt>
jmp    12a1 <main+0x171>
jmp    12a6 <main+0x176>
jmp    1142 <main+0x12>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3458,%rsp
lea    0x5(%rsp),%r12
lea    0x8(%rsp),%r14
lea    0xeae(%rip),%r15
mov    %rsp,%rbx
lea    0xeac(%rip),%r13
lea    0x50(%rsp),%rbp
jmp    11b1 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
lea    0xe94(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1235 <main+0x105>
mov    %r14,%rdi
call   1030 <cleanFilename@plt>
mov    $0x21,%edi
mov    $0x4,%esi
mov    %r14,%rdx
mov    $0x2000,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1050 <interrupt@plt>
movb   $0x0,(%rsp)
movb   $0x0,0x50(%rsp)
mov    $0x21,%edi
xor    %esi,%esi
mov    %r15,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1050 <interrupt@plt>
mov    $0x21,%edi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1050 <interrupt@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1170 <main+0x40>
mov    %r12,%rdi
call   1030 <cleanFilename@plt>
mov    $0x21,%edi
mov    $0x3,%esi
mov    %r12,%rdx
mov    %rbp,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1050 <interrupt@plt>
mov    $0x21,%edi
xor    %esi,%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
jmp    11a7 <main+0x77>
mov    %rbx,%rdi
lea    0xdd8(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    125e <main+0x12e>
mov    $0x21,%edi
xor    %esi,%esi
lea    0xdc1(%rip),%rdx
jmp    122e <main+0xfe>
xor    %eax,%eax
add    $0x3458,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"SHELL> \00"
@.str.1 = [6 x i8] c"type \00"
@.str.2 = [9 x i8] c"execute \00"
@.str.3 = [6 x i8] c"exit \00"
@.str.4 = [15 x i8] c"Bad Command!\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i8*
%4 = alloca [13312 x i8]
store i32 0, i32* %1
br label %5
5: ; preds = %0, %44
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
store i8 0, i8* %6
store i8* null, i8** %3
%7 = getelementptr inbounds [13312 x i8], [13312 x i8]* %4, i64 0, i64 0
store i8 0, i8* %7
%8 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%10 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 1, i8* %9, i32 0, i32 0)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%12 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %5
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds i8, i8* %15, i64 5
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = call i32 @cleanFilename(i8* %17)
%19 = load i8*, i8** %3
%20 = getelementptr inbounds [13312 x i8], [13312 x i8]* %4, i64 0, i64 0
%21 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 3, i8* %19, i8* %20, i32 0)
%22 = getelementptr inbounds [13312 x i8], [13312 x i8]* %4, i64 0, i64 0
%23 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 0, i8* %22, i32 0, i32 0)
br label %44
24: ; preds = %5
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 8
store i8* %30, i8** %3
%31 = load i8*, i8** %3
%32 = call i32 @cleanFilename(i8* %31)
%33 = load i8*, i8** %3
%34 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 4, i8* %33, i32 8192, i32 0)
br label %43
35: ; preds = %24
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%37 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
ret i32 0
40: ; preds = %35
%41 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0)
br label %42
42: ; preds = %40
br label %43
43: ; preds = %42, %28
br label %44
44: ; preds = %43, %14
br label %5
}

LLVM IR (-O2):
@.str = [8 x i8] c"SHELL> \00"
@.str.1 = [6 x i8] c"type \00"
@.str.2 = [9 x i8] c"execute \00"
@.str.3 = [6 x i8] c"exit \00"
@.str.4 = [15 x i8] c"Bad Command!\0D\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [13312 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [13312 x i8], [13312 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 5
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 8
br label %7
7: ; preds = %22, %0
store i8 0, i8* %3
store i8 0, i8* %4
%8 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%9 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 1, i8* %3, i32 0, i32 0)
%10 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = call i32 @cleanFilename(i8* %5)
%14 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 3, i8* %5, i8* %4, i32 0)
%15 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 0, i8* %4, i32 0, i32 0)
br label %22
16: ; preds = %7
%17 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = call i32 @cleanFilename(i8* %6)
%21 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 4, i8* %6, i32 8192, i32 0)
br label %22
22: ; preds = %19, %27, %12
br label %7
23: ; preds = %16
%24 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%25 = icmp eq i64 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %23
ret i32 0
27: ; preds = %23
%28 = call i32 (i32, i32, i8*, ...) @interrupt(i32 33, i32 0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0)
br label %22
}