#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 */
char *calloc(int, int);
int /*<<< orphan*/ debug(double *, double *, int *, int *, int *, int *);
int /*<<< orphan*/ debugDump(double *, double *, int *, int *, int *, int *,
                             int);
scalar_t__ execute(double *, double *, int *, int *, int *, int *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ load(double *, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ puts(char *);
int scanf(char *, char *);
int main(void) {
  FILE *bootMsgPtr;
  double memory[(1000)] = {0};
  char *genericError = "*** Simpletron execution abnormally terminated ***";
  char *bufferPtr;
  double accumulator = {0};
  int instructionCounter = {00};
  int instructionRegister = {0000};
  int operationCode = {00};
  int operand = {00};
  int debugMode = 0;
  if ((bootMsgPtr = fopen("bootMsg.txt", "r")) == NULL) {
    puts(genericError);
    printf("%s %s %s", "*** ", "bootMsg.txt", "not found ***");
  } else {
    bufferPtr = calloc(80, sizeof(char));
    while (!feof(bootMsgPtr)) {
      fgets(bufferPtr, 80, bootMsgPtr);
      printf("%s", bufferPtr);
    }
    fclose(bootMsgPtr);
    puts("");
    puts("");
    printf("%s", "Run in Debug Mode(type Y)? ");
    if ((debugMode = scanf("%1[Yy]", bufferPtr)) == 1) {
      puts("Now you are in debug mode YHEA!");
    } else {
      scanf("%c", bufferPtr);
      puts("");
    }
    free(bufferPtr);
    load(memory, operand);
    if (0 == execute(memory, &accumulator, &instructionCounter,
                     &instructionRegister, &operationCode, &operand,
                     debugMode)) {
      debug(memory, &accumulator, &instructionCounter, &instructionRegister,
            &operationCode, &operand);
      debugDump(memory, &accumulator, &instructionCounter, &instructionRegister,
                &operationCode, &operand, debugMode);
    }
  }
  debugDump(memory, &accumulator, &instructionCounter, &instructionRegister,
            &operationCode, &operand, debugMode);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1f50(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f40,%edx
call   1090 <memset@plt>
lea    0xdf4(%rip),%rax
mov    %rax,-0x1f58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1f68(%rbp)
ff
movl   $0x0,-0x1f6c(%rbp)
movl   $0x0,-0x1f70(%rbp)
movl   $0x0,-0x1f74(%rbp)
movl   $0x0,-0x1f78(%rbp)
movl   $0x0,-0x1f7c(%rbp)
lea    0xddc(%rip),%rdi
lea    0xde1(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    12a5 <main+0xc5>
mov    -0x1f58(%rbp),%rdi
call   1040 <puts@plt>
lea    0xdbd(%rip),%rdi
lea    0xdbf(%rip),%rsi
lea    0xda1(%rip),%rdx
lea    0xdb6(%rip),%rcx
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1460 <main+0x280>
mov    $0x50,%edi
mov    $0x1,%esi
call   10c0 <calloc@plt>
mov    %rax,-0x1f60(%rbp)
mov    -0x10(%rbp),%rdi
call   10d0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12d9 <main+0xf9>
jmp    1308 <main+0x128>
mov    -0x1f60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   10b0 <fgets@plt>
mov    -0x1f60(%rbp),%rsi
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    12bb <main+0xdb>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xd36(%rip),%rdi
call   1040 <puts@plt>
lea    0xd2a(%rip),%rdi
call   1040 <puts@plt>
lea    0xd17(%rip),%rdi
lea    0xd26(%rip),%rsi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x1f60(%rbp),%rsi
lea    0xd2d(%rip),%rdi
call   10e0 <scanf@plt>
mov    %eax,-0x1f7c(%rbp)
cmp    $0x1,%eax
jne    1371 <main+0x191>
lea    0xd19(%rip),%rdi
call   1040 <puts@plt>
jmp    1390 <main+0x1b0>
mov    -0x1f60(%rbp),%rsi
lea    0xd21(%rip),%rdi
call   10e0 <scanf@plt>
lea    0xcc3(%rip),%rdi
call   1040 <puts@plt>
mov    -0x1f60(%rbp),%rdi
call   1030 <free@plt>
lea    -0x1f50(%rbp),%rdi
mov    -0x1f78(%rbp),%esi
call   1100 <load@plt>
lea    -0x1f50(%rbp),%rdi
mov    -0x1f7c(%rbp),%eax
lea    -0x1f68(%rbp),%rsi
lea    -0x1f6c(%rbp),%rdx
lea    -0x1f70(%rbp),%rcx
lea    -0x1f74(%rbp),%r8
lea    -0x1f78(%rbp),%r9
mov    %eax,(%rsp)
call   10a0 <execute@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    145b <main+0x27b>
lea    -0x1f50(%rbp),%rdi
lea    -0x1f68(%rbp),%rsi
lea    -0x1f6c(%rbp),%rdx
lea    -0x1f70(%rbp),%rcx
lea    -0x1f74(%rbp),%r8
lea    -0x1f78(%rbp),%r9
call   1070 <debug@plt>
lea    -0x1f50(%rbp),%rdi
mov    -0x1f7c(%rbp),%eax
lea    -0x1f68(%rbp),%rsi
lea    -0x1f6c(%rbp),%rdx
lea    -0x1f70(%rbp),%rcx
lea    -0x1f74(%rbp),%r8
lea    -0x1f78(%rbp),%r9
mov    %eax,(%rsp)
call   1050 <debugDump@plt>
jmp    1460 <main+0x280>
lea    -0x1f50(%rbp),%rdi
mov    -0x1f7c(%rbp),%eax
lea    -0x1f68(%rbp),%rsi
lea    -0x1f6c(%rbp),%rdx
lea    -0x1f70(%rbp),%rcx
lea    -0x1f74(%rbp),%r8
lea    -0x1f78(%rbp),%r9
mov    %eax,(%rsp)
call   1050 <debugDump@plt>
xor    %eax,%eax
add    $0x1f90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f68,%rsp
lea    0x20(%rsp),%rdi
xor    %r14d,%r14d
mov    $0x1f40,%edx
xor    %esi,%esi
call   10a0 <memset@plt>
movq   $0x0,0x18(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xdee(%rip),%rdi
lea    0xdf3(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     130f <main+0x11f>
mov    %rax,%rbp
mov    $0x50,%edi
mov    $0x1,%esi
call   10d0 <calloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   10e0 <feof@plt>
test   %eax,%eax
jne    12b9 <main+0xc9>
lea    0xdc5(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %rbp,%rdx
call   10c0 <fgets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
call   10e0 <feof@plt>
test   %eax,%eax
je     1290 <main+0xa0>
mov    %rbp,%rdi
call   1070 <fclose@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xd6b(%rip),%rdi
lea    0xd7a(%rip),%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xd88(%rip),%rdi
mov    %rbx,%rsi
call   10f0 <scanf@plt>
mov    %eax,%r14d
cmp    $0x1,%eax
jne    1343 <main+0x153>
lea    0xd78(%rip),%rdi
call   1050 <puts@plt>
jmp    135c <main+0x16c>
lea    0xcea(%rip),%rdi
call   1050 <puts@plt>
lea    0xd1f(%rip),%rdi
lea    0xd21(%rip),%rsi
lea    0xd03(%rip),%rdx
lea    0xd18(%rip),%rcx
xor    %eax,%eax
call   1090 <printf@plt>
jmp    13ec <main+0x1fc>
lea    0xd56(%rip),%rdi
mov    %rbx,%rsi
call   10f0 <scanf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1110 <load@plt>
mov    %r14d,(%rsp)
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
mov    %rbx,%rdi
call   10b0 <execute@plt>
test   %rax,%rax
jne    13ec <main+0x1fc>
lea    0x20(%rsp),%rbx
lea    0x18(%rsp),%rbp
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0x8(%rsp),%r9
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1080 <debug@plt>
mov    %r14d,(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
lea    0x8(%rsp),%r9
call   1060 <debugDump@plt>
mov    %r14d,(%rsp)
lea    0x20(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
call   1060 <debugDump@plt>
xor    %eax,%eax
add    $0x1f68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"*** Simpletron execution abnormally terminated ***\00"
@.str.1 = [12 x i8] c"bootMsg.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"%s %s %s\00"
@.str.4 = [5 x i8] c"*** \00"
@.str.5 = [14 x i8] c"not found ***\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [28 x i8] c"Run in Debug Mode(type Y)? \00"
@.str.9 = [7 x i8] c"%1[Yy]\00"
@.str.10 = [32 x i8] c"Now you are in debug mode YHEA!\00"
@.str.11 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1000 x double]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = bitcast [1000 x double]* %3 to i8*
store i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8** %4
store double 0.000000e+00, double* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%13 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %2
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = load i8*, i8** %4
%17 = call i32 @puts(i8* %16)
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %64
19: ; preds = %0
%20 = call i8* @calloc(i32 80, i32 1)
store i8* %20, i8** %5
br label %21
21: ; preds = %26, %19
%22 = load i32*, i32** %2
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = load i32*, i32** %2
%29 = call i32 @fgets(i8* %27, i32 80, i32* %28)
%30 = load i8*, i8** %5
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %30)
br label %21
32: ; preds = %21
%33 = load i32*, i32** %2
%34 = call i32 @fclose(i32* %33)
%35 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%36 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%38 = load i8*, i8** %5
%39 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* %38)
store i32 %39, i32* %11
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
br label %47
43: ; preds = %32
%44 = load i8*, i8** %5
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %44)
%46 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
br label %47
47: ; preds = %43, %41
%48 = load i8*, i8** %5
%49 = call i32 @free(i8* %48)
%50 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 0
%51 = load i32, i32* %10
%52 = call i32 @load(double* %50, i32 %51)
%53 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 0
%54 = load i32, i32* %11
%55 = call i64 @execute(double* %53, double* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32 %54)
%56 = icmp eq i64 0, %55
br i1 %56, label %57, label %63
57: ; preds = %47
%58 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 0
%59 = call i32 @debug(double* %58, double* %6, i32* %7, i32* %8, i32* %9, i32* %10)
%60 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 0
%61 = load i32, i32* %11
%62 = call i32 @debugDump(double* %60, double* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32 %61)
br label %63
63: ; preds = %57, %47
br label %64
64: ; preds = %63, %15
%65 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 0
%66 = load i32, i32* %11
%67 = call i32 @debugDump(double* %65, double* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32 %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [51 x i8] c"*** Simpletron execution abnormally terminated ***\00"
@.str.1 = [12 x i8] c"bootMsg.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"%s %s %s\00"
@.str.4 = [5 x i8] c"*** \00"
@.str.5 = [14 x i8] c"not found ***\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.8 = [28 x i8] c"Run in Debug Mode(type Y)? \00"
@.str.9 = [7 x i8] c"%1[Yy]\00"
@.str.10 = [32 x i8] c"Now you are in debug mode YHEA!\00"
@.str.11 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca [1000 x double]
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [1000 x double]* %1 to i8*
%8 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%12 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %48
18: ; preds = %0
%19 = tail call dereferenceable_or_null(80) i8* @calloc(i32 80, i32 1)
%20 = tail call i32 @feof(i32* %13)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18, %22
%23 = tail call i32 @fgets(i8* %19, i32 80, i32* %13)
%24 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%25 = tail call i32 @feof(i32* %13)
%26 = icmp eq i32 %25, 0
br i1 %26, label %22, label %27
27: ; preds = %22, %18
%28 = tail call i32 @fclose(i32* %13)
%29 = tail call i32 @putchar(i32 10)
%30 = tail call i32 @putchar(i32 10)
%31 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%32 = tail call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* %19)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
br label %39
36: ; preds = %27
%37 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %19)
%38 = tail call i32 @putchar(i32 10)
br label %39
39: ; preds = %36, %34
%40 = tail call i32 @free(i8* %19)
%41 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 0
%42 = call i32 @load(double* %41, i32 0)
%43 = call i64 @execute(double* %41, double* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32 %32)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = call i32 @debug(double* %41, double* %2, i32* %3, i32* %4, i32* %5, i32* %6)
%47 = call i32 @debugDump(double* %41, double* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32 %32)
br label %48
48: ; preds = %39, %45, %15
%49 = phi i32 [ 0, %15 ], [ %32, %45 ], [ %32, %39 ]
%50 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 0
%51 = call i32 @debugDump(double* %50, double* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32 %49)
ret i32 0
}