#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int simMIPS(char *disassembly, char *instrMemory, char *dataMemory,
            int instr_start_address, int data_start_address) {
  FILE *disfile;
  FILE *simfile;
  FILE *instrFile;
  FILE *dataFile;
  int *dataMem;
  unsigned int *instrMem;
  int count = 0, shiftby = 0;
  unsigned int instr;
  int data;
  int instrCount, dataCount = 0;
  printf("Starting Simulation\n");
  disfile = fopen(disassembly, "r");
  if (!disfile) {
    printf("Invalid file name / file open error");
    return 1;
  }
  instrFile = fopen(instrMemory, "r");
  if (!instrFile) {
    printf("Invalid file name / file open error");
    return 1;
  }
  dataFile = fopen(dataMemory, "r");
  if (!dataFile) {
    printf("Invalid file name / file open error");
    return 1;
  }
  simfile = fopen("simulation.txt", "w");
  if (!simfile) {
    printf("Invalid file name / file open error");
    return 1;
  }
  while (EOF != (fscanf(instrFile, "%*[^\n]"), fscanf(instrFile, "%*c")))
    ++instrCount;
  instrMem = (unsigned int *)malloc(sizeof(unsigned int) * instrCount);
  while (EOF != (fscanf(dataFile, "%*[^\n]"), fscanf(dataFile, "%*c")))
    ++dataCount;
  dataMem = (int *)malloc(sizeof(int) * dataCount);
  rewind(instrFile);
  rewind(dataFile);
  for (count = 0; count < instrCount; count++) {
    fscanf(instrFile, "%d", &instr);
    instrMem[count] = instr;
  }
  for (count = 0; count < dataCount; count++) {
    fscanf(dataFile, "%d", &data);
    dataMem[count] = data;
  }
  fprintf(simfile, "Data\n");
  while (shiftby != dataCount) {
    if (shiftby % 8 == 0)
      fprintf(simfile, "%d:\t", data_start_address + 4 * shiftby);
    if ((shiftby + 1) % 8 == 0)
      fprintf(simfile, "%d\n", dataMem[shiftby++]);
    else
      fprintf(simfile, "%d\t", dataMem[shiftby++]);
  }
  fclose(simfile);
  fclose(instrFile);
  fclose(dataFile);
  fclose(disfile);
  return 0;
}


x86 assembly (clang, -O0):
<simMIPS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x70(%rbp)
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e6 <simMIPS+0x76>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14de <simMIPS+0x36e>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    121d <simMIPS+0xad>
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14de <simMIPS+0x36e>
mov    -0x20(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1254 <simMIPS+0xe4>
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14de <simMIPS+0x36e>
lea    0xdde(%rip),%rdi
lea    0xde6(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    128e <simMIPS+0x11e>
lea    0xd98(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14de <simMIPS+0x36e>
jmp    1293 <simMIPS+0x123>
mov    0x2d4e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x78(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x40(%rbp),%rdi
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
cmp    %rcx,%rax
je     12e3 <simMIPS+0x173>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1293 <simMIPS+0x123>
movslq -0x6c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xd3b(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x48(%rbp),%rdi
lea    0xd30(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
cmp    %rcx,%rax
je     1346 <simMIPS+0x1d6>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    12f6 <simMIPS+0x186>
movslq -0x70(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x48(%rbp),%rdi
call   1050 <rewind@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jge    13b0 <simMIPS+0x240>
mov    -0x40(%rbp),%rdi
lea    0xccc(%rip),%rsi
lea    -0x64(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x64(%rbp),%edx
mov    -0x58(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1372 <simMIPS+0x202>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x70(%rbp),%eax
jge    13f5 <simMIPS+0x285>
mov    -0x48(%rbp),%rdi
lea    0xc87(%rip),%rsi
lea    -0x68(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x68(%rbp),%edx
mov    -0x50(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    13b7 <simMIPS+0x247>
mov    -0x38(%rbp),%rdi
lea    0xc58(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x60(%rbp),%eax
cmp    -0x70(%rbp),%eax
je     14b3 <simMIPS+0x343>
mov    -0x60(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1444 <simMIPS+0x2d4>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x60(%rbp),%eax
shl    $0x2,%eax
add    %eax,%edx
lea    0xc21(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1487 <simMIPS+0x317>
mov    -0x38(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x60(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xbe8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    14ae <simMIPS+0x33e>
mov    -0x38(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x60(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xbc0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1407 <simMIPS+0x297>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simMIPS>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8d,%r15d
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe65(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1413 <simMIPS+0x283>
mov    %rax,%rbp
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1413 <simMIPS+0x283>
mov    %rax,%rbx
lea    0xe2f(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     1413 <simMIPS+0x283>
lea    0xe14(%rip),%rdi
lea    0xe1c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1413 <simMIPS+0x283>
mov    %r15d,0x14(%rsp)
mov    %rbp,0x40(%rsp)
mov    $0xfffffffc,%ebp
mov    0x2da8(%rip),%r14
lea    0xdee(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    (%r14),%r15
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    %rbx,%rdi
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
add    $0x1,%r13d
add    $0x4,%ebp
cmp    %rax,%r15
jne    1250 <simMIPS+0xc0>
mov    %rbx,0x28(%rsp)
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,0x38(%rsp)
mov    $0xffffffffffffffff,%r15
mov    $0xfffffffc,%ebp
mov    0x18(%rsp),%rbx
nop
mov    (%r14),%r12
mov    %rbx,%rdi
lea    0xd88(%rip),%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    %rbx,%rdi
lea    0xd7e(%rip),%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
add    $0x1,%r15
add    $0x4,%ebp
cmp    %rax,%r12
jne    12a0 <simMIPS+0x110>
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,0x30(%rsp)
mov    %rbx,%rbp
mov    0x28(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %rbp,%rdi
call   1060 <rewind@plt>
test   %r13d,%r13d
mov    0x38(%rsp),%r12
jle    1335 <simMIPS+0x1a5>
mov    %r13d,%ebp
lea    0x24(%rsp),%r13
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xd26(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0x24(%rsp),%eax
mov    %eax,(%r12,%r14,4)
add    $0x1,%r14
cmp    %r14,%rbp
jne    1310 <simMIPS+0x180>
test   %r15d,%r15d
je     1433 <simMIPS+0x2a3>
lea    0xcfb(%rip),%r14
lea    0x20(%rsp),%r13
xor    %ebp,%ebp
mov    0x18(%rsp),%rbx
mov    0x30(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0x20(%rsp),%eax
mov    %eax,(%r12,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1360 <simMIPS+0x1d0>
lea    0xcbb(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    0x8(%rsp),%rcx
call   10b0 <fwrite@plt>
test   %r15d,%r15d
je     1453 <simMIPS+0x2c3>
lea    0xca6(%rip),%r13
xor    %r14d,%r14d
jmp    13f4 <simMIPS+0x264>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%r14),%rbp
test   $0x7,%bpl
mov    (%r12,%r14,4),%edx
mov    %r13,%rsi
lea    0xc78(%rip),%rax
cmove  %rax,%rsi
mov    0x8(%rsp),%rdi
xor    %eax,%eax
call   1080 <fprintf@plt>
addl   $0x4,0x14(%rsp)
mov    %rbp,%r14
add    $0xffffffffffffffff,%r15
je     1453 <simMIPS+0x2c3>
test   $0x7,%r14b
jne    13c0 <simMIPS+0x230>
mov    0x8(%rsp),%rdi
lea    0xc43(%rip),%rsi
mov    0x14(%rsp),%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    13c0 <simMIPS+0x230>
lea    0xbe6(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc09(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    0x8(%rsp),%rcx
call   10b0 <fwrite@plt>
mov    0x18(%rsp),%rbx
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x28(%rsp),%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x40(%rsp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1424 <simMIPS+0x294>

LLVM IR (-O0):
@.str = [21 x i8] c"Starting Simulation\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"Invalid file name / file open error\00"
@.str.3 = [15 x i8] c"simulation.txt\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i64 0
@.str.5 = [7 x i8] c"%*[^\0A]\00"
@.str.6 = [4 x i8] c"%*c\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [6 x i8] c"Data\0A\00"
@.str.9 = [5 x i8] c"%d:\09\00"
@.str.10 = [4 x i8] c"%d\0A\00"
@.str.11 = [4 x i8] c"%d\09\00"
define i32 @simMIPS(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 0, i32* %18
store i32 0, i32* %19
store i32 0, i32* %23
%24 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%25 = load i8*, i8** %7
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %12
%27 = load i32*, i32** %12
%28 = icmp ne i32* %27, null
br i1 %28, label %31, label %29
29: ; preds = %5
%30 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %172
31: ; preds = %5
%32 = load i8*, i8** %8
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %14
%34 = load i32*, i32** %14
%35 = icmp ne i32* %34, null
br i1 %35, label %38, label %36
36: ; preds = %31
%37 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %172
38: ; preds = %31
%39 = load i8*, i8** %9
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %15
%41 = load i32*, i32** %15
%42 = icmp ne i32* %41, null
br i1 %42, label %45, label %43
43: ; preds = %38
%44 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %172
45: ; preds = %38
%46 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %46, i32** %13
%47 = load i32*, i32** %13
%48 = icmp ne i32* %47, null
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %172
51: ; preds = %45
br label %52
52: ; preds = %59, %51
%53 = load i64, i64* @EOF
%54 = load i32*, i32** %14
%55 = call i64 (i32*, i8*, ...) @fscanf(i32* %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%56 = load i32*, i32** %14
%57 = call i64 (i32*, i8*, ...) @fscanf(i32* %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%58 = icmp ne i64 %53, %57
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = load i32, i32* %22
%61 = add nsw i32 %60, 1
store i32 %61, i32* %22
br label %52
62: ; preds = %52
%63 = load i32, i32* %22
%64 = sext i32 %63 to i64
%65 = mul i64 4, %64
%66 = trunc i64 %65 to i32
%67 = call i64 @malloc(i32 %66)
%68 = inttoptr i64 %67 to i32*
store i32* %68, i32** %17
br label %69
69: ; preds = %76, %62
%70 = load i64, i64* @EOF
%71 = load i32*, i32** %15
%72 = call i64 (i32*, i8*, ...) @fscanf(i32* %71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32*, i32** %15
%74 = call i64 (i32*, i8*, ...) @fscanf(i32* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%75 = icmp ne i64 %70, %74
br i1 %75, label %76, label %79
76: ; preds = %69
%77 = load i32, i32* %23
%78 = add nsw i32 %77, 1
store i32 %78, i32* %23
br label %69
79: ; preds = %69
%80 = load i32, i32* %23
%81 = sext i32 %80 to i64
%82 = mul i64 4, %81
%83 = trunc i64 %82 to i32
%84 = call i64 @malloc(i32 %83)
%85 = inttoptr i64 %84 to i32*
store i32* %85, i32** %16
%86 = load i32*, i32** %14
%87 = call i32 @rewind(i32* %86)
%88 = load i32*, i32** %15
%89 = call i32 @rewind(i32* %88)
store i32 0, i32* %18
br label %90
90: ; preds = %102, %79
%91 = load i32, i32* %18
%92 = load i32, i32* %22
%93 = icmp slt i32 %91, %92
br i1 %93, label %94, label %105
94: ; preds = %90
%95 = load i32*, i32** %14
%96 = call i64 (i32*, i8*, ...) @fscanf(i32* %95, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %20)
%97 = load i32, i32* %20
%98 = load i32*, i32** %17
%99 = load i32, i32* %18
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i32, i32* %98, i64 %100
store i32 %97, i32* %101
br label %102
102: ; preds = %94
%103 = load i32, i32* %18
%104 = add nsw i32 %103, 1
store i32 %104, i32* %18
br label %90
105: ; preds = %90
store i32 0, i32* %18
br label %106
106: ; preds = %118, %105
%107 = load i32, i32* %18
%108 = load i32, i32* %23
%109 = icmp slt i32 %107, %108
br i1 %109, label %110, label %121
110: ; preds = %106
%111 = load i32*, i32** %15
%112 = call i64 (i32*, i8*, ...) @fscanf(i32* %111, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %21)
%113 = load i32, i32* %21
%114 = load i32*, i32** %16
%115 = load i32, i32* %18
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %114, i64 %116
store i32 %113, i32* %117
br label %118
118: ; preds = %110
%119 = load i32, i32* %18
%120 = add nsw i32 %119, 1
store i32 %120, i32* %18
br label %106
121: ; preds = %106
%122 = load i32*, i32** %13
%123 = call i32 (i32*, i8*, ...) @fprintf(i32* %122, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %124
124: ; preds = %162, %121
%125 = load i32, i32* %19
%126 = load i32, i32* %23
%127 = icmp ne i32 %125, %126
br i1 %127, label %128, label %163
128: ; preds = %124
%129 = load i32, i32* %19
%130 = srem i32 %129, 8
%131 = icmp eq i32 %130, 0
br i1 %131, label %132, label %139
132: ; preds = %128
%133 = load i32*, i32** %13
%134 = load i32, i32* %11
%135 = load i32, i32* %19
%136 = mul nsw i32 4, %135
%137 = add nsw i32 %134, %136
%138 = call i32 (i32*, i8*, ...) @fprintf(i32* %133, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %137)
br label %139
139: ; preds = %132, %128
%140 = load i32, i32* %19
%141 = add nsw i32 %140, 1
%142 = srem i32 %141, 8
%143 = icmp eq i32 %142, 0
br i1 %143, label %144, label %153
144: ; preds = %139
%145 = load i32*, i32** %13
%146 = load i32*, i32** %16
%147 = load i32, i32* %19
%148 = add nsw i32 %147, 1
store i32 %148, i32* %19
%149 = sext i32 %147 to i64
%150 = getelementptr inbounds i32, i32* %146, i64 %149
%151 = load i32, i32* %150
%152 = call i32 (i32*, i8*, ...) @fprintf(i32* %145, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32 %151)
br label %162
153: ; preds = %139
%154 = load i32*, i32** %13
%155 = load i32*, i32** %16
%156 = load i32, i32* %19
%157 = add nsw i32 %156, 1
store i32 %157, i32* %19
%158 = sext i32 %156 to i64
%159 = getelementptr inbounds i32, i32* %155, i64 %158
%160 = load i32, i32* %159
%161 = call i32 (i32*, i8*, ...) @fprintf(i32* %154, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i32 %160)
br label %162
162: ; preds = %153, %144
br label %124
163: ; preds = %124
%164 = load i32*, i32** %13
%165 = call i32 @fclose(i32* %164)
%166 = load i32*, i32** %14
%167 = call i32 @fclose(i32* %166)
%168 = load i32*, i32** %15
%169 = call i32 @fclose(i32* %168)
%170 = load i32*, i32** %12
%171 = call i32 @fclose(i32* %170)
store i32 0, i32* %6
br label %172
172: ; preds = %163, %49, %43, %36, %29
%173 = load i32, i32* %6
ret i32 %173
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"Invalid file name / file open error\00"
@.str.3 = [15 x i8] c"simulation.txt\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i64 0
@.str.5 = [7 x i8] c"%*[^\0A]\00"
@.str.6 = [4 x i8] c"%*c\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [6 x i8] c"Data\0A\00"
@.str.9 = [5 x i8] c"%d:\09\00"
@.str.10 = [4 x i8] c"%d\0A\00"
@.str.11 = [4 x i8] c"%d\09\00"
@str = [20 x i8] c"Starting Simulation\00"
define i32 @simMIPS(i8* nocapture %0, i8* nocapture %1, i8* nocapture %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %6 to i8*
%9 = bitcast i32* %7 to i8*
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %104
15: ; preds = %5
%16 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %104
20: ; preds = %15
%21 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %104
25: ; preds = %20
%26 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %104
30: ; preds = %25, %30
%31 = phi i32 [ %36, %30 ], [ undef, %25 ]
%32 = load i64, i64* @EOF
%33 = tail call i64 (i32*, i8*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%34 = tail call i64 (i32*, i8*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%35 = icmp eq i64 %32, %34
%36 = add nsw i32 %31, 1
br i1 %35, label %37, label %30
37: ; preds = %30
%38 = shl i32 %31, 2
%39 = tail call i64 @malloc(i32 %38)
br label %40
40: ; preds = %40, %37
%41 = phi i32 [ 0, %37 ], [ %46, %40 ]
%42 = load i64, i64* @EOF
%43 = tail call i64 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%44 = tail call i64 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%45 = icmp eq i64 %42, %44
%46 = add nuw nsw i32 %41, 1
br i1 %45, label %47, label %40
47: ; preds = %40
%48 = inttoptr i64 %39 to i32*
%49 = shl i32 %41, 2
%50 = tail call i64 @malloc(i32 %49)
%51 = inttoptr i64 %50 to i32*
%52 = tail call i32 @rewind(i32* %16)
%53 = tail call i32 @rewind(i32* %21)
%54 = icmp sgt i32 %31, 0
br i1 %54, label %55, label %57
55: ; preds = %47
%56 = zext i32 %31 to i64
br label %63
57: ; preds = %63, %47
%58 = icmp eq i32 %41, 0
br i1 %58, label %59, label %61
59: ; preds = %57
%60 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i64 5, i64 1, i32* %26)
br label %99
61: ; preds = %57
%62 = zext i32 %41 to i64
br label %70
63: ; preds = %55, %63
%64 = phi i64 [ 0, %55 ], [ %68, %63 ]
%65 = call i64 (i32*, i8*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %6)
%66 = load i32, i32* %6
%67 = getelementptr inbounds i32, i32* %48, i64 %64
store i32 %66, i32* %67
%68 = add nuw nsw i64 %64, 1
%69 = icmp eq i64 %68, %56
br i1 %69, label %57, label %63
70: ; preds = %61, %70
%71 = phi i64 [ 0, %61 ], [ %75, %70 ]
%72 = call i64 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %7)
%73 = load i32, i32* %7
%74 = getelementptr inbounds i32, i32* %51, i64 %71
store i32 %73, i32* %74
%75 = add nuw nsw i64 %71, 1
%76 = icmp eq i64 %75, %62
br i1 %76, label %77, label %70
77: ; preds = %70
%78 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i64 5, i64 1, i32* %26)
br i1 %58, label %99, label %79
79: ; preds = %77
%80 = zext i32 %41 to i64
br label %81
81: ; preds = %79, %90
%82 = phi i64 [ 0, %79 ], [ %91, %90 ]
%83 = trunc i64 %82 to i32
%84 = and i32 %83, 7
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %90
86: ; preds = %81
%87 = shl nsw i32 %83, 2
%88 = add nsw i32 %87, %4
%89 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %88)
br label %90
90: ; preds = %86, %81
%91 = add nuw nsw i64 %82, 1
%92 = and i64 %91, 7
%93 = icmp eq i64 %92, 0
%94 = getelementptr inbounds i32, i32* %51, i64 %82
%95 = load i32, i32* %94
%96 = select i1 %93, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0)
%97 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* %96, i32 %95)
%98 = icmp eq i64 %91, %80
br i1 %98, label %99, label %81
99: ; preds = %90, %59, %77
%100 = call i32 @fclose(i32* %26)
%101 = call i32 @fclose(i32* %16)
%102 = call i32 @fclose(i32* %21)
%103 = call i32 @fclose(i32* %11)
br label %104
104: ; preds = %99, %28, %23, %18, %13
%105 = phi i32 [ 0, %99 ], [ 1, %28 ], [ 1, %23 ], [ 1, %18 ], [ 1, %13 ]
ret i32 %105
}