#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 EXIT_FAILURE;
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char *opcodeArray[] = {"INS",   "LOAD",   "STORE", "ADD",      "SUBT",
                         "INPUT", "OUTPUT", "HALT",  "SKIPCOND", "JUMP",
                         "CLEAR", "ADDI",   "JUMPI"};
  FILE *program;
  short int ac = 0;
  unsigned short int pc;
  unsigned short int pcEnd;
  int first;
  int second;
  bool debug = false;
  if (argc < 2) {
    printf("usage: %s (-v) <nazwa pliku z programem>\n", argv[0]);
    exit(1);
  }
  if (strcmp(argv[1], "-v") == 0) {
    debug = true;
  }
  char *fileName = argv[argc - 1];
  unsigned short int array[16 * 16 * 16];
  for (int i = 0; i < 16 * 16 * 16; i++) {
    array[i] = 0;
  }
  program = fopen(fileName, "rb");
  if (program == NULL) {
    printf("Plik nie istnieje\n");
    exit(EXIT_FAILURE);
  }
  if (fgetc(program) != 255 || fgetc(program) != 255) {
    printf("Błędny plik\n");
    exit(EXIT_FAILURE);
  }
  pc = (unsigned short)(fgetc(program) | fgetc(program) << 8);
  pcEnd = (unsigned short)(fgetc(program) | fgetc(program) << 8);
  unsigned short pcBackup = pc;
  do {
    first = fgetc(program);
    second = fgetc(program);
    array[pcBackup] = (unsigned short)(second << 8 | first);
    pcBackup++;
    if (feof(program)) {
      break;
    }
  } while (1);
  unsigned short int command;
  unsigned short int opcode;
  unsigned short int address;
  while (1) {
    command = array[pc];
    address = command;
    address = (unsigned short)(address & 0xFFF);
    opcode = (unsigned short)(command >> (4 + 4 + 4) & 0xF);
    if (debug) {
      printf("\nPC:%-7xAC:%-8x %-8s %-12x  %-4x", pc, ac, opcodeArray[opcode],
             address, command);
    }
    pc++;
    int number;
    char new_ac;
    switch (opcode) {
    case 0:
      array[address] = pc;
      pc = (unsigned short)(address + 1);
      break;
    case 1:
      ac = address;
      break;
    case 2:
      array[address] = (unsigned short)ac;
      break;
    case 3:
      ac += address;
      break;
    case 4:
      ac -= address;
      break;
    case 5:
      scanf("%c", &new_ac);
      ac = new_ac;
      break;
    case 6:
      if (debug) {
        printf("\n");
      }
      printf("%c", (char)ac);
      break;
    case 7:
      exit(0);
      break;
    case 8:
      number = address;
      number = (number >> 10);
      number &= 0x3;
      if (number == 0 && ac < 0) {
        pc++;
        break;
      }
      if (number == 1 && ac == 0) {
        pc++;
        break;
      }
      if (number == 2 && ac > 0) {
        pc++;
        break;
      }
      break;
    case 9:
      pc = address;
      break;
    case 10:
      ac = 0;
      break;
    case 11:
      ac += array[address];
      break;
    case 12:
      pc = array[address];
      break;
    default:
      printf("\nNIEZNANY OPCODE: %d\n", opcode);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0x2c0c(%rip),%rsi
mov    $0x68,%edx
call   1070 <memcpy@plt>
movw   $0x0,-0x8a(%rbp)
movl   $0x0,-0x9c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ea <main+0x6a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeae(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1212 <main+0x92>
movl   $0x1,-0x9c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0xa8(%rbp)
movl   $0x0,-0x20b4(%rbp)
cmpl   $0x1000,-0x20b4(%rbp)
jge    1269 <main+0xe9>
movslq -0x20b4(%rbp),%rax
movw   $0x0,-0x20b0(%rbp,%rax,2)
mov    -0x20b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20b4(%rbp)
jmp    1234 <main+0xb4>
mov    -0xa8(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    12ad <main+0x12d>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x88(%rbp),%rdi
call   1040 <fgetc@plt>
cmp    $0xff,%eax
jne    12db <main+0x15b>
mov    -0x88(%rbp),%rdi
call   1040 <fgetc@plt>
cmp    $0xff,%eax
je     12f7 <main+0x177>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x88(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x20cc(%rbp)
mov    -0x88(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    -0x20cc(%rbp),%eax
shl    $0x8,%ecx
or     %ecx,%eax
mov    %ax,-0x8c(%rbp)
mov    -0x88(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x20c8(%rbp)
mov    -0x88(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    -0x20c8(%rbp),%eax
shl    $0x8,%ecx
or     %ecx,%eax
mov    %ax,-0x8e(%rbp)
mov    -0x8c(%rbp),%ax
mov    %ax,-0x20b6(%rbp)
mov    -0x88(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x94(%rbp)
mov    -0x88(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x98(%rbp)
mov    -0x98(%rbp),%eax
shl    $0x8,%eax
or     -0x94(%rbp),%eax
mov    %ax,%cx
movzwl -0x20b6(%rbp),%eax
mov    %cx,-0x20b0(%rbp,%rax,2)
ff
mov    -0x20b6(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x20b6(%rbp)
mov    -0x88(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     13db <main+0x25b>
jmp    13ef <main+0x26f>
jmp    13e0 <main+0x260>
mov    $0x1,%al
test   $0x1,%al
jne    1369 <main+0x1e9>
jmp    13ef <main+0x26f>
jmp    13f4 <main+0x274>
movzwl -0x8c(%rbp),%eax
mov    -0x20b0(%rbp,%rax,2),%ax
ff
mov    %ax,-0x20b8(%rbp)
mov    -0x20b8(%rbp),%ax
mov    %ax,-0x20bc(%rbp)
movzwl -0x20bc(%rbp),%eax
and    $0xfff,%eax
mov    %ax,-0x20bc(%rbp)
movzwl -0x20b8(%rbp),%eax
sar    $0xc,%eax
and    $0xf,%eax
mov    %ax,-0x20ba(%rbp)
cmpl   $0x0,-0x9c(%rbp)
je     1484 <main+0x304>
movzwl -0x8c(%rbp),%esi
movswl -0x8a(%rbp),%edx
movzwl -0x20ba(%rbp),%eax
mov    -0x80(%rbp,%rax,8),%rcx
movzwl -0x20bc(%rbp),%r8d
ff
movzwl -0x20b8(%rbp),%r9d
ff
lea    0xc52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8c(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x8c(%rbp)
movzwl -0x20ba(%rbp),%eax
mov    %rax,-0x20d8(%rbp)
sub    $0xc,%rax
ja     16e8 <main+0x568>
mov    -0x20d8(%rbp),%rax
lea    0xb44(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8c(%rbp),%cx
movzwl -0x20bc(%rbp),%eax
mov    %cx,-0x20b0(%rbp,%rax,2)
ff
movzwl -0x20bc(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0x8c(%rbp)
jmp    16fd <main+0x57d>
mov    -0x20bc(%rbp),%ax
mov    %ax,-0x8a(%rbp)
jmp    16fd <main+0x57d>
mov    -0x8a(%rbp),%cx
movzwl -0x20bc(%rbp),%eax
mov    %cx,-0x20b0(%rbp,%rax,2)
ff
jmp    16fd <main+0x57d>
movzwl -0x20bc(%rbp),%ecx
movswl -0x8a(%rbp),%eax
add    %ecx,%eax
mov    %ax,-0x8a(%rbp)
jmp    16fd <main+0x57d>
movzwl -0x20bc(%rbp),%ecx
movswl -0x8a(%rbp),%eax
sub    %ecx,%eax
mov    %ax,-0x8a(%rbp)
jmp    16fd <main+0x57d>
lea    0xb92(%rip),%rdi
lea    -0x20c1(%rbp),%rsi
call   1080 <scanf@plt>
movsbl -0x20c1(%rbp),%eax
mov    %ax,-0x8a(%rbp)
jmp    16fd <main+0x57d>
cmpl   $0x0,-0x9c(%rbp)
je     1598 <main+0x418>
lea    0xb14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8a(%rbp),%ax
movsbl %al,%esi
lea    0xb47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    16fd <main+0x57d>
xor    %edi,%edi
call   10a0 <exit@plt>
movzwl -0x20bc(%rbp),%eax
mov    %eax,-0x20c0(%rbp)
mov    -0x20c0(%rbp),%eax
sar    $0xa,%eax
mov    %eax,-0x20c0(%rbp)
mov    -0x20c0(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x20c0(%rbp)
cmpl   $0x0,-0x20c0(%rbp)
jne    161b <main+0x49b>
movswl -0x8a(%rbp),%eax
cmp    $0x0,%eax
jge    161b <main+0x49b>
mov    -0x8c(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x8c(%rbp)
jmp    16fd <main+0x57d>
cmpl   $0x1,-0x20c0(%rbp)
jne    164f <main+0x4cf>
movswl -0x8a(%rbp),%eax
cmp    $0x0,%eax
jne    164f <main+0x4cf>
mov    -0x8c(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x8c(%rbp)
jmp    16fd <main+0x57d>
cmpl   $0x2,-0x20c0(%rbp)
jne    1683 <main+0x503>
movswl -0x8a(%rbp),%eax
cmp    $0x0,%eax
jle    1683 <main+0x503>
mov    -0x8c(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x8c(%rbp)
jmp    16fd <main+0x57d>
jmp    16fd <main+0x57d>
mov    -0x20bc(%rbp),%ax
mov    %ax,-0x8c(%rbp)
jmp    16fd <main+0x57d>
movw   $0x0,-0x8a(%rbp)
jmp    16fd <main+0x57d>
movzwl -0x20bc(%rbp),%eax
movzwl -0x20b0(%rbp,%rax,2),%ecx
ff
movswl -0x8a(%rbp),%eax
add    %ecx,%eax
mov    %ax,-0x8a(%rbp)
jmp    16fd <main+0x57d>
movzwl -0x20bc(%rbp),%eax
mov    -0x20b0(%rbp,%rax,2),%ax
ff
mov    %ax,-0x8c(%rbp)
jmp    16fd <main+0x57d>
movzwl -0x20ba(%rbp),%esi
lea    0x9fd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    13f4 <main+0x274>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11d4 <main+0x34>
mov    (%r14),%rsi
lea    0xeee(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %edi,%ebp
mov    0x8(%r14),%rdi
lea    0xefa(%rip),%rsi
call   1080 <strcmp@plt>
mov    %rax,%rbx
add    $0xffffffff,%ebp
mov    (%r14,%rbp,8),%rbp
lea    0x10(%rsp),%rdi
mov    $0x2000,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xed6(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    1221 <main+0x81>
lea    0xf0d(%rip),%rdi
jmp    143e <main+0x29e>
mov    %rax,%r14
mov    %rbx,0x8(%rsp)
mov    %rax,%rdi
call   1070 <fgetc@plt>
cmp    $0xff,%eax
jne    1437 <main+0x297>
mov    %r14,%rdi
call   1070 <fgetc@plt>
cmp    $0xff,%eax
jne    1437 <main+0x297>
mov    %r14,%rdi
call   1070 <fgetc@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
or     %r15d,%ebp
mov    %r14,%rdi
call   1070 <fgetc@plt>
mov    %r14,%rdi
call   1070 <fgetc@plt>
mov    %ebp,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1070 <fgetc@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1070 <fgetc@plt>
shl    $0x8,%eax
or     %r15d,%eax
movzwl %bx,%ecx
mov    %ax,0x10(%rsp,%rcx,2)
add    $0x1,%ebx
mov    %r14,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     1280 <main+0xe0>
xor    %ebx,%ebx
mov    0x8(%rsp),%rcx
jmp    12d9 <main+0x139>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rcx
nopl   (%rax)
mov    %ebx,%r15d
mov    %r13d,%ebp
mov    %r15d,%ebx
movzwl %bp,%esi
movzwl 0x10(%rsp,%rsi,2),%r14d
mov    %r14d,%r15d
and    $0xfff,%r15d
mov    %r14,%r12
shr    $0xc,%r12
test   %rcx,%rcx
jne    1322 <main+0x182>
movswl %bx,%edx
lea    0xd32(%rip),%rax
movslq (%rax,%r12,4),%rcx
add    %rax,%rcx
lea    0xdd1(%rip),%rdi
mov    %r15d,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rcx
lea    0x1(%rbp),%r13d
movzwl %r12w,%esi
cmp    $0xc,%si
ja     12ba <main+0x11a>
lea    0xcc9(%rip),%rdx
movslq (%rdx,%rsi,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    %r13w,0x10(%rsp,%r15,2)
movzwl %r15w,%r13d
add    $0x1,%r13d
jmp    12d0 <main+0x130>
movzwl %r15w,%eax
mov    %bx,0x10(%rsp,%rax,2)
jmp    12d0 <main+0x130>
movzwl %r15w,%r15d
add    %ebx,%r15d
jmp    12d3 <main+0x133>
movzwl %r15w,%eax
sub    %eax,%ebx
jmp    12d0 <main+0x130>
lea    0xd86(%rip),%rdi
lea    0x7(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0x8(%rsp),%rcx
movsbl 0x7(%rsp),%r15d
jmp    12d3 <main+0x133>
test   %rcx,%rcx
jne    13a5 <main+0x205>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsbl %bl,%edi
call   1030 <putchar@plt>
mov    %ebx,%r15d
mov    0x8(%rsp),%rcx
jmp    12d3 <main+0x133>
shr    $0xa,%r14d
and    $0x3,%r14w
jne    1402 <main+0x262>
test   %bx,%bx
jns    1402 <main+0x262>
add    $0x2,%ebp
mov    %ebp,%r13d
jmp    12d0 <main+0x130>
mov    %r15d,%r13d
jmp    12d0 <main+0x130>
xor    %r15d,%r15d
jmp    12d3 <main+0x133>
movzwl %r15w,%eax
add    0x10(%rsp,%rax,2),%bx
jmp    12d0 <main+0x130>
movzwl %r15w,%eax
movzwl 0x10(%rsp,%rax,2),%r13d
jmp    12d0 <main+0x130>
cmp    $0x1,%r14w
jne    141c <main+0x27c>
test   %bx,%bx
jne    141c <main+0x27c>
add    $0x2,%ebp
xor    %r15d,%r15d
mov    %ebp,%r13d
jmp    12d3 <main+0x133>
add    $0x2,%ebp
test   %bx,%bx
cmovle %r13d,%ebp
cmp    $0x2,%r14w
cmovne %r13d,%ebp
mov    %ebp,%r13d
jmp    12d0 <main+0x130>
lea    0xcdd(%rip),%rdi
call   1040 <puts@plt>
mov    0x2b96(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"INS\00"
@.str.1 = [5 x i8] c"LOAD\00"
@.str.2 = [6 x i8] c"STORE\00"
@.str.3 = [4 x i8] c"ADD\00"
@.str.4 = [5 x i8] c"SUBT\00"
@.str.5 = [6 x i8] c"INPUT\00"
@.str.6 = [7 x i8] c"OUTPUT\00"
@.str.7 = [5 x i8] c"HALT\00"
@.str.8 = [9 x i8] c"SKIPCOND\00"
@.str.9 = [5 x i8] c"JUMP\00"
@.str.10 = [6 x i8] c"CLEAR\00"
@.str.11 = [5 x i8] c"ADDI\00"
@.str.12 = [6 x i8] c"JUMPI\00"
@__const.main.opcodeArray = [13 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i32 0, i32 0)]
@.str.13 = [42 x i8] c"usage: %s (-v) <nazwa pliku z programem>\0A\00"
@.str.14 = [3 x i8] c"-v\00"
@.str.15 = [3 x i8] c"rb\00"
@.str.16 = [19 x i8] c"Plik nie istnieje\0A\00"
@EXIT_FAILURE = global i32 0
@.str.17 = [15 x i8] c"B\C5\82\C4\99dny plik\0A\00"
@.str.18 = [33 x i8] c"\0APC:%-7xAC:%-8x %-8s %-12x %-4x\00"
@.str.19 = [3 x i8] c"%c\00"
@.str.20 = [2 x i8] c"\0A\00"
@.str.21 = [22 x i8] c"\0ANIEZNANY OPCODE: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [13 x i8*]
%7 = alloca i32*
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca [4096 x i16]
%16 = alloca i32
%17 = alloca i16
%18 = alloca i16
%19 = alloca i16
%20 = alloca i16
%21 = alloca i32
%22 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = bitcast [13 x i8*]* %6 to i8*
store i16 0, i16* %8
store i32 0, i32* %13
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %32
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %2
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %32
store i32 1, i32* %13
br label %39
39: ; preds = %38, %32
%40 = load i8**, i8*** %5
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %40, i64 %43
%45 = load i8*, i8** %44
store i8* %45, i8** %14
store i32 0, i32* %16
br label %46
46: ; preds = %53, %39
%47 = load i32, i32* %16
%48 = icmp slt i32 %47, 4096
br i1 %48, label %49, label %56
49: ; preds = %46
%50 = load i32, i32* %16
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [4096 x i16], [4096 x i16]* %15, i64 0, i64 %51
store i16 0, i16* %52
br label %53
53: ; preds = %49
%54 = load i32, i32* %16
%55 = add nsw i32 %54, 1
store i32 %55, i32* %16
br label %46
56: ; preds = %46
%57 = load i8*, i8** %14
%58 = call i32* @fopen(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
store i32* %58, i32** %7
%59 = load i32*, i32** %7
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %65
61: ; preds = %56
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.16, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %56
%66 = load i32*, i32** %7
%67 = call i32 @fgetc(i32* %66)
%68 = icmp ne i32 %67, 255
br i1 %68, label %73, label %69
69: ; preds = %65
%70 = load i32*, i32** %7
%71 = call i32 @fgetc(i32* %70)
%72 = icmp ne i32 %71, 255
br i1 %72, label %73, label %77
73: ; preds = %69, %65
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.17, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %69
%78 = load i32*, i32** %7
%79 = call i32 @fgetc(i32* %78)
%80 = load i32*, i32** %7
%81 = call i32 @fgetc(i32* %80)
%82 = shl i32 %81, 8
%83 = or i32 %79, %82
%84 = trunc i32 %83 to i16
store i16 %84, i16* %9
%85 = load i32*, i32** %7
%86 = call i32 @fgetc(i32* %85)
%87 = load i32*, i32** %7
%88 = call i32 @fgetc(i32* %87)
%89 = shl i32 %88, 8
%90 = or i32 %86, %89
%91 = trunc i32 %90 to i16
store i16 %91, i16* %10
%92 = load i16, i16* %9
store i16 %92, i16* %17
br label %93
93: ; preds = %113, %77
%94 = load i32*, i32** %7
%95 = call i32 @fgetc(i32* %94)
store i32 %95, i32* %11
%96 = load i32*, i32** %7
%97 = call i32 @fgetc(i32* %96)
store i32 %97, i32* %12
%98 = load i32, i32* %12
%99 = shl i32 %98, 8
%100 = load i32, i32* %11
%101 = or i32 %99, %100
%102 = trunc i32 %101 to i16
%103 = load i16, i16* %17
%104 = zext i16 %103 to i64
%105 = getelementptr inbounds [4096 x i16], [4096 x i16]* %15, i64 0, i64 %104
store i16 %102, i16* %105
%106 = load i16, i16* %17
%107 = add i16 %106, 1
store i16 %107, i16* %17
%108 = load i32*, i32** %7
%109 = call i64 @feof(i32* %108)
%110 = icmp ne i64 %109, 0
br i1 %110, label %111, label %112
111: ; preds = %93
br label %114
112: ; preds = %93
br label %113
113: ; preds = %112
br i1 true, label %93, label %114
114: ; preds = %113, %111
br label %115
115: ; preds = %114, %256
%116 = load i16, i16* %9
%117 = zext i16 %116 to i64
%118 = getelementptr inbounds [4096 x i16], [4096 x i16]* %15, i64 0, i64 %117
%119 = load i16, i16* %118
store i16 %119, i16* %18
%120 = load i16, i16* %18
store i16 %120, i16* %20
%121 = load i16, i16* %20
%122 = zext i16 %121 to i32
%123 = and i32 %122, 4095
%124 = trunc i32 %123 to i16
store i16 %124, i16* %20
%125 = load i16, i16* %18
%126 = zext i16 %125 to i32
%127 = ashr i32 %126, 12
%128 = and i32 %127, 15
%129 = trunc i32 %128 to i16
store i16 %129, i16* %19
%130 = load i32, i32* %13
%131 = icmp ne i32 %130, 0
br i1 %131, label %132, label %146
132: ; preds = %115
%133 = load i16, i16* %9
%134 = zext i16 %133 to i32
%135 = load i16, i16* %8
%136 = sext i16 %135 to i32
%137 = load i16, i16* %19
%138 = zext i16 %137 to i64
%139 = getelementptr inbounds [13 x i8*], [13 x i8*]* %6, i64 0, i64 %138
%140 = load i8*, i8** %139
%141 = load i16, i16* %20
%142 = zext i16 %141 to i32
%143 = load i16, i16* %18
%144 = zext i16 %143 to i32
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.18, i64 0, i64 0), i32 %134, i32 %136, i8* %140, i32 %142, i32 %144)
br label %146
146: ; preds = %132, %115
%147 = load i16, i16* %9
%148 = add i16 %147, 1
store i16 %148, i16* %9
%149 = load i16, i16* %19
%150 = zext i16 %149 to i32
switch i32 %150, label %252 [
i32 0, label %151
i32 1, label %160
i32 2, label %162
i32 3, label %167
i32 4, label %174
i32 5, label %181
i32 6, label %185
i32 7, label %195
i32 8, label %197
i32 9, label %234
i32 10, label %236
i32 11, label %237
i32 12, label %247
]
151: ; preds = %146
%152 = load i16, i16* %9
%153 = load i16, i16* %20
%154 = zext i16 %153 to i64
%155 = getelementptr inbounds [4096 x i16], [4096 x i16]* %15, i64 0, i64 %154
store i16 %152, i16* %155
%156 = load i16, i16* %20
%157 = zext i16 %156 to i32
%158 = add nsw i32 %157, 1
%159 = trunc i32 %158 to i16
store i16 %159, i16* %9
br label %256
160: ; preds = %146
%161 = load i16, i16* %20
store i16 %161, i16* %8
br label %256
162: ; preds = %146
%163 = load i16, i16* %8
%164 = load i16, i16* %20
%165 = zext i16 %164 to i64
%166 = getelementptr inbounds [4096 x i16], [4096 x i16]* %15, i64 0, i64 %165
store i16 %163, i16* %166
br label %256
167: ; preds = %146
%168 = load i16, i16* %20
%169 = zext i16 %168 to i32
%170 = load i16, i16* %8
%171 = sext i16 %170 to i32
%172 = add nsw i32 %171, %169
%173 = trunc i32 %172 to i16
store i16 %173, i16* %8
br label %256
174: ; preds = %146
%175 = load i16, i16* %20
%176 = zext i16 %175 to i32
%177 = load i16, i16* %8
%178 = sext i16 %177 to i32
%179 = sub nsw i32 %178, %176
%180 = trunc i32 %179 to i16
store i16 %180, i16* %8
br label %256
181: ; preds = %146
%182 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0), i8* %22)
%183 = load i8, i8* %22
%184 = sext i8 %183 to i16
store i16 %184, i16* %8
br label %256
185: ; preds = %146
%186 = load i32, i32* %13
%187 = icmp ne i32 %186, 0
br i1 %187, label %188, label %190
188: ; preds = %185
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.20, i64 0, i64 0))
br label %190
190: ; preds = %188, %185
%191 = load i16, i16* %8
%192 = trunc i16 %191 to i8
%193 = sext i8 %192 to i32
%194 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0), i32 %193)
br label %256
195: ; preds = %146
%196 = call i32 @exit(i32 0)
unreachable
197: ; preds = %146
%198 = load i16, i16* %20
%199 = zext i16 %198 to i32
store i32 %199, i32* %21
%200 = load i32, i32* %21
%201 = ashr i32 %200, 10
store i32 %201, i32* %21
%202 = load i32, i32* %21
%203 = and i32 %202, 3
store i32 %203, i32* %21
%204 = load i32, i32* %21
%205 = icmp eq i32 %204, 0
br i1 %205, label %206, label %213
206: ; preds = %197
%207 = load i16, i16* %8
%208 = sext i16 %207 to i32
%209 = icmp slt i32 %208, 0
br i1 %209, label %210, label %213
210: ; preds = %206
%211 = load i16, i16* %9
%212 = add i16 %211, 1
store i16 %212, i16* %9
br label %256
213: ; preds = %206, %197
%214 = load i32, i32* %21
%215 = icmp eq i32 %214, 1
br i1 %215, label %216, label %223
216: ; preds = %213
%217 = load i16, i16* %8
%218 = sext i16 %217 to i32
%219 = icmp eq i32 %218, 0
br i1 %219, label %220, label %223
220: ; preds = %216
%221 = load i16, i16* %9
%222 = add i16 %221, 1
store i16 %222, i16* %9
br label %256
223: ; preds = %216, %213
%224 = load i32, i32* %21
%225 = icmp eq i32 %224, 2
br i1 %225, label %226, label %233
226: ; preds = %223
%227 = load i16, i16* %8
%228 = sext i16 %227 to i32
%229 = icmp sgt i32 %228, 0
br i1 %229, label %230, label %233
230: ; preds = %226
%231 = load i16, i16* %9
%232 = add i16 %231, 1
store i16 %232, i16* %9
br label %256
233: ; preds = %226, %223
br label %256
234: ; preds = %146
%235 = load i16, i16* %20
store i16 %235, i16* %9
br label %256
236: ; preds = %146
store i16 0, i16* %8
br label %256
237: ; preds = %146
%238 = load i16, i16* %20
%239 = zext i16 %238 to i64
%240 = getelementptr inbounds [4096 x i16], [4096 x i16]* %15, i64 0, i64 %239
%241 = load i16, i16* %240
%242 = zext i16 %241 to i32
%243 = load i16, i16* %8
%244 = sext i16 %243 to i32
%245 = add nsw i32 %244, %242
%246 = trunc i32 %245 to i16
store i16 %246, i16* %8
br label %256
247: ; preds = %146
%248 = load i16, i16* %20
%249 = zext i16 %248 to i64
%250 = getelementptr inbounds [4096 x i16], [4096 x i16]* %15, i64 0, i64 %249
%251 = load i16, i16* %250
store i16 %251, i16* %9
br label %256
252: ; preds = %146
%253 = load i16, i16* %19
%254 = zext i16 %253 to i32
%255 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.21, i64 0, i64 0), i32 %254)
br label %256
256: ; preds = %252, %247, %237, %236, %234, %233, %230, %220, %210, %190, %181, %174, %167, %162, %160, %151
br label %115
}

LLVM IR (-O2):
@.str = [4 x i8] c"INS\00"
@.str.1 = [5 x i8] c"LOAD\00"
@.str.2 = [6 x i8] c"STORE\00"
@.str.3 = [4 x i8] c"ADD\00"
@.str.4 = [5 x i8] c"SUBT\00"
@.str.5 = [6 x i8] c"INPUT\00"
@.str.6 = [7 x i8] c"OUTPUT\00"
@.str.7 = [5 x i8] c"HALT\00"
@.str.8 = [9 x i8] c"SKIPCOND\00"
@.str.9 = [5 x i8] c"JUMP\00"
@.str.10 = [6 x i8] c"CLEAR\00"
@.str.11 = [5 x i8] c"ADDI\00"
@.str.12 = [6 x i8] c"JUMPI\00"
@reltable.main = [13 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.5 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.7 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.8 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.9 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.10 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.11 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.12 to i64), i64 ptrtoint ([13 x i32]* @reltable.main to i64)) to i32)]
@.str.13 = [42 x i8] c"usage: %s (-v) <nazwa pliku z programem>\0A\00"
@.str.14 = [3 x i8] c"-v\00"
@.str.15 = [3 x i8] c"rb\00"
@EXIT_FAILURE = global i32 0
@.str.18 = [33 x i8] c"\0APC:%-7xAC:%-8x %-8s %-12x %-4x\00"
@.str.19 = [3 x i8] c"%c\00"
@.str.21 = [22 x i8] c"\0ANIEZNANY OPCODE: %d\0A\00"
@str = [14 x i8] c"B\C5\82\C4\99dny plik\00"
@str.22 = [18 x i8] c"Plik nie istnieje\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i16]
%4 = bitcast [4096 x i16]* %3 to i8*
%5 = alloca i8
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%15 = add nsw i32 %0, -1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = icmp eq i64 %14, 0
%20 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %11
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.22, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %11
%27 = tail call i32 @fgetc(i32* %20)
%28 = icmp eq i32 %27, 255
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = tail call i32 @fgetc(i32* %20)
%31 = icmp eq i32 %30, 255
br i1 %31, label %36, label %32
32: ; preds = %29, %26
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %29
%37 = tail call i32 @fgetc(i32* %20)
%38 = tail call i32 @fgetc(i32* %20)
%39 = shl i32 %38, 8
%40 = or i32 %39, %37
%41 = trunc i32 %40 to i16
%42 = tail call i32 @fgetc(i32* %20)
%43 = tail call i32 @fgetc(i32* %20)
br label %44
44: ; preds = %44, %36
%45 = phi i16 [ %41, %36 ], [ %53, %44 ]
%46 = tail call i32 @fgetc(i32* %20)
%47 = tail call i32 @fgetc(i32* %20)
%48 = shl i32 %47, 8
%49 = or i32 %48, %46
%50 = trunc i32 %49 to i16
%51 = zext i16 %45 to i64
%52 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %51
store i16 %50, i16* %52
%53 = add i16 %45, 1
%54 = tail call i64 @feof(i32* %20)
%55 = icmp eq i64 %54, 0
br i1 %55, label %44, label %56
56: ; preds = %44, %134
%57 = phi i16 [ %135, %134 ], [ %41, %44 ]
%58 = phi i16 [ %136, %134 ], [ 0, %44 ]
%59 = zext i16 %57 to i64
%60 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %59
%61 = load i16, i16* %60
%62 = and i16 %61, 4095
%63 = lshr i16 %61, 12
br i1 %19, label %64, label %73
64: ; preds = %56
%65 = zext i16 %61 to i32
%66 = zext i16 %57 to i32
%67 = sext i16 %58 to i32
%68 = zext i16 %63 to i64
%69 = shl i64 %68, 2
%70 = call i8* @llvm.load.relative.i64(i8* bitcast ([13 x i32]* @reltable.main to i8*), i64 %69)
%71 = zext i16 %62 to i32
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.18, i64 0, i64 0), i32 %66, i32 %67, i8* %70, i32 %71, i32 %65)
br label %73
73: ; preds = %64, %56
%74 = add i16 %57, 1
%75 = zext i16 %63 to i32
switch i32 %75, label %132 [
i32 0, label %76
i32 1, label %134
i32 2, label %80
i32 3, label %83
i32 4, label %85
i32 5, label %87
i32 6, label %91
i32 7, label %99
i32 8, label %101
i32 9, label %121
i32 10, label %122
i32 11, label %123
i32 12, label %128
]
76: ; preds = %73
%77 = zext i16 %62 to i64
%78 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %77
store i16 %74, i16* %78
%79 = add nuw nsw i16 %62, 1
br label %134
80: ; preds = %73
%81 = zext i16 %62 to i64
%82 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %81
store i16 %58, i16* %82
br label %134
83: ; preds = %73
%84 = add i16 %62, %58
br label %134
85: ; preds = %73
%86 = sub i16 %58, %62
br label %134
87: ; preds = %73
%88 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0), i8* %5)
%89 = load i8, i8* %5
%90 = sext i8 %89 to i16
br label %134
91: ; preds = %73
br i1 %19, label %92, label %94
92: ; preds = %91
%93 = call i32 @putchar(i32 10)
br label %94
94: ; preds = %92, %91
%95 = zext i16 %58 to i32
%96 = shl i32 %95, 24
%97 = ashr exact i32 %96, 24
%98 = call i32 @putchar(i32 %97)
br label %134
99: ; preds = %73
%100 = call i32 @exit(i32 0)
unreachable
101: ; preds = %73
%102 = lshr i16 %61, 10
%103 = and i16 %102, 3
%104 = icmp eq i16 %103, 0
%105 = icmp slt i16 %58, 0
%106 = select i1 %104, i1 %105, i1 false
br i1 %106, label %107, label %109
107: ; preds = %101
%108 = add i16 %57, 2
br label %134
109: ; preds = %101
%110 = icmp eq i16 %103, 1
%111 = icmp eq i16 %58, 0
%112 = select i1 %110, i1 %111, i1 false
br i1 %112, label %113, label %115
113: ; preds = %109
%114 = add i16 %57, 2
br label %134
115: ; preds = %109
%116 = icmp eq i16 %103, 2
%117 = icmp sgt i16 %58, 0
%118 = select i1 %116, i1 %117, i1 false
%119 = add i16 %57, 2
%120 = select i1 %118, i16 %119, i16 %74
br label %134
121: ; preds = %73
br label %134
122: ; preds = %73
br label %134
123: ; preds = %73
%124 = zext i16 %62 to i64
%125 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %124
%126 = load i16, i16* %125
%127 = add i16 %126, %58
br label %134
128: ; preds = %73
%129 = zext i16 %62 to i64
%130 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %129
%131 = load i16, i16* %130
br label %134
132: ; preds = %73
%133 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.21, i64 0, i64 0), i32 %75)
br label %134
134: ; preds = %115, %73, %132, %128, %123, %122, %121, %113, %107, %94, %87, %85, %83, %80, %76
%135 = phi i16 [ %74, %132 ], [ %131, %128 ], [ %74, %123 ], [ %74, %122 ], [ %62, %121 ], [ %108, %107 ], [ %114, %113 ], [ %74, %94 ], [ %74, %87 ], [ %74, %85 ], [ %74, %83 ], [ %74, %80 ], [ %79, %76 ], [ %74, %73 ], [ %120, %115 ]
%136 = phi i16 [ %58, %132 ], [ %58, %128 ], [ %127, %123 ], [ 0, %122 ], [ %58, %121 ], [ %58, %107 ], [ 0, %113 ], [ %58, %94 ], [ %90, %87 ], [ %86, %85 ], [ %84, %83 ], [ %58, %80 ], [ %58, %76 ], [ %62, %73 ], [ %58, %115 ]
br label %56
}