#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*/ DUMP_REGISTERS();
int PinGetPIN_A();
int PinGetPIN_D();
int PinGetPIN_SYNC();
scalar_t__ PinGetPIN__WR();
int /*<<< orphan*/ PinSetO1(int);
int /*<<< orphan*/ PinSetO2(int);
int /*<<< orphan*/ PinSetPIN_D(int);
int /*<<< orphan*/ PinSetPIN_READY(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
void EXECUTE_CYCLES(unsigned char instruction, int cnt, char *named) {
  int a;
  int readInstruction = 0;
  static unsigned char SYNC_LATCH;
  for (a = 0; a < cnt; a++) {
    PinSetO1(1);
    PinSetO1(0);
    PinSetO2(1);
    PinSetO2(0);
    if (a == 0 && (PinGetPIN_SYNC() != 1 || PinGetPIN_D() != (0xA2))) {
      printf("Previous instruction took wrong number of cycles!\n");
      exit(1);
    }
    if (PinGetPIN_SYNC()) {
      SYNC_LATCH = PinGetPIN_D();
    }
    if (PinGetPIN_SYNC()) {
      if (SYNC_LATCH == (0xA2)) {
        if (readInstruction) {
          printf("current instruction took wrong number of cycles!\n");
          exit(1);
        }
        readInstruction = 1;
        printf("Reading next instruction - Address %04X <- %02X (%s)\n",
               PinGetPIN_A(), instruction, named);
        PinSetPIN_D(instruction);
        PinSetPIN_READY(1);
      } else {
        if (SYNC_LATCH == (0x86)) {
          printf("Reading memory(stack) - Address %04X <- $55\n",
                 PinGetPIN_A());
          PinSetPIN_D(0x55);
          PinSetPIN_READY(1);
        } else {
          if (SYNC_LATCH == (0x04)) {
            PinSetPIN_READY(1);
          } else {
            if (SYNC_LATCH == (0x82)) {
              printf("Reading memory - Address %04X <- 0\n", PinGetPIN_A());
              PinSetPIN_D(0x0);
              PinSetPIN_READY(1);
            } else {
              if (SYNC_LATCH == (0x00)) {
                PinSetPIN_READY(1);
              } else {
                if (SYNC_LATCH == (0x42)) {
                  printf("Reading port %04X <- $AA\n", PinGetPIN_A());
                  PinSetPIN_D(0xAA);
                  PinSetPIN_READY(1);
                } else {
                  if (SYNC_LATCH == (0x10)) {
                    PinSetPIN_READY(1);
                  } else {
                    printf("PIN_D = %02X\n", PinGetPIN_D());
                    exit(2);
                  }
                }
              }
            }
          }
        }
      }
    }
    if (PinGetPIN__WR() == 0) {
      if (SYNC_LATCH == (0x04)) {
        printf("Writing memory(stack) - Address %04X <- %02X\n", PinGetPIN_A(),
               PinGetPIN_D());
      } else {
        if (SYNC_LATCH == (0x00)) {
          printf("Writing memory - Address %04X <- %02X\n", PinGetPIN_A(),
                 PinGetPIN_D());
        } else {
          if (SYNC_LATCH == (0x10)) {
            printf("Writing port %04X <- %02X\n", PinGetPIN_A(), PinGetPIN_D());
          }
        }
      }
    }
  }
  DUMP_REGISTERS();
}


x86 assembly (clang, -O0):
<EXECUTE_CYCLES>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    151f <EXECUTE_CYCLES+0x36f>
mov    $0x1,%edi
call   10a0 <PinSetO1@plt>
xor    %edi,%edi
call   10a0 <PinSetO1@plt>
mov    $0x1,%edi
call   1040 <PinSetO2@plt>
xor    %edi,%edi
call   1040 <PinSetO2@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1245 <EXECUTE_CYCLES+0x95>
mov    $0x0,%al
call   10b0 <PinGetPIN_SYNC@plt>
cmp    $0x1,%eax
jne    122d <EXECUTE_CYCLES+0x7d>
mov    $0x0,%al
call   10d0 <PinGetPIN_D@plt>
cmp    $0xa2,%eax
je     1245 <EXECUTE_CYCLES+0x95>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   10b0 <PinGetPIN_SYNC@plt>
cmp    $0x0,%eax
je     1262 <EXECUTE_CYCLES+0xb2>
mov    $0x0,%al
call   10d0 <PinGetPIN_D@plt>
mov    %al,0x2e17(%rip)
mov    $0x0,%al
call   10b0 <PinGetPIN_SYNC@plt>
cmp    $0x0,%eax
je     1446 <EXECUTE_CYCLES+0x296>
movzbl 0x2e00(%rip),%eax
cmp    $0xa2,%eax
jne    12e4 <EXECUTE_CYCLES+0x134>
cmpl   $0x0,-0x18(%rbp)
je     12a6 <EXECUTE_CYCLES+0xf6>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x1,-0x18(%rbp)
mov    $0x0,%al
call   1070 <PinGetPIN_A@plt>
mov    %eax,%esi
movzbl -0x1(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movzbl -0x1(%rbp),%edi
call   1080 <PinSetPIN_D@plt>
mov    $0x1,%edi
call   1030 <PinSetPIN_READY@plt>
jmp    1441 <EXECUTE_CYCLES+0x291>
movzbl 0x2d8e(%rip),%eax
cmp    $0x86,%eax
jne    1326 <EXECUTE_CYCLES+0x176>
mov    $0x0,%al
call   1070 <PinGetPIN_A@plt>
mov    %eax,%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x55,%edi
call   1080 <PinSetPIN_D@plt>
mov    $0x1,%edi
call   1030 <PinSetPIN_READY@plt>
jmp    143c <EXECUTE_CYCLES+0x28c>
movzbl 0x2d4c(%rip),%eax
cmp    $0x4,%eax
jne    1345 <EXECUTE_CYCLES+0x195>
mov    $0x1,%edi
call   1030 <PinSetPIN_READY@plt>
jmp    1437 <EXECUTE_CYCLES+0x287>
movzbl 0x2d2d(%rip),%eax
cmp    $0x82,%eax
jne    1384 <EXECUTE_CYCLES+0x1d4>
mov    $0x0,%al
call   1070 <PinGetPIN_A@plt>
mov    %eax,%esi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1080 <PinSetPIN_D@plt>
mov    $0x1,%edi
call   1030 <PinSetPIN_READY@plt>
jmp    1432 <EXECUTE_CYCLES+0x282>
movzbl 0x2cee(%rip),%eax
cmp    $0x0,%eax
jne    13a3 <EXECUTE_CYCLES+0x1f3>
mov    $0x1,%edi
call   1030 <PinSetPIN_READY@plt>
jmp    142d <EXECUTE_CYCLES+0x27d>
movzbl 0x2ccf(%rip),%eax
cmp    $0x42,%eax
jne    13e3 <EXECUTE_CYCLES+0x233>
mov    $0x0,%al
call   1070 <PinGetPIN_A@plt>
mov    %eax,%esi
lea    0xd29(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xaa,%edi
call   1080 <PinSetPIN_D@plt>
mov    $0x1,%edi
call   1030 <PinSetPIN_READY@plt>
jmp    1428 <EXECUTE_CYCLES+0x278>
movzbl 0x2c8f(%rip),%eax
cmp    $0x10,%eax
jne    1402 <EXECUTE_CYCLES+0x252>
mov    $0x1,%edi
call   1030 <PinSetPIN_READY@plt>
jmp    1423 <EXECUTE_CYCLES+0x273>
mov    $0x0,%al
call   10d0 <PinGetPIN_D@plt>
mov    %eax,%esi
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
jmp    1428 <EXECUTE_CYCLES+0x278>
jmp    142d <EXECUTE_CYCLES+0x27d>
jmp    1432 <EXECUTE_CYCLES+0x282>
jmp    1437 <EXECUTE_CYCLES+0x287>
jmp    143c <EXECUTE_CYCLES+0x28c>
jmp    1441 <EXECUTE_CYCLES+0x291>
jmp    1446 <EXECUTE_CYCLES+0x296>
mov    $0x0,%al
call   1050 <PinGetPIN__WR@plt>
cmp    $0x0,%rax
jne    150c <EXECUTE_CYCLES+0x35c>
movzbl 0x2c1b(%rip),%eax
cmp    $0x4,%eax
jne    1490 <EXECUTE_CYCLES+0x2e0>
mov    $0x0,%al
call   1070 <PinGetPIN_A@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   10d0 <PinGetPIN_D@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xc90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1507 <EXECUTE_CYCLES+0x357>
movzbl 0x2be2(%rip),%eax
cmp    $0x0,%eax
jne    14c9 <EXECUTE_CYCLES+0x319>
mov    $0x0,%al
call   1070 <PinGetPIN_A@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   10d0 <PinGetPIN_D@plt>
mov    -0x20(%rbp),%esi
mov    %eax,%edx
lea    0xc85(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1502 <EXECUTE_CYCLES+0x352>
movzbl 0x2ba9(%rip),%eax
cmp    $0x10,%eax
jne    14fd <EXECUTE_CYCLES+0x34d>
mov    $0x0,%al
call   1070 <PinGetPIN_A@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   10d0 <PinGetPIN_D@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xc73(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1502 <EXECUTE_CYCLES+0x352>
jmp    1507 <EXECUTE_CYCLES+0x357>
jmp    150c <EXECUTE_CYCLES+0x35c>
jmp    1511 <EXECUTE_CYCLES+0x361>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d3 <EXECUTE_CYCLES+0x23>
mov    $0x0,%al
call   1090 <DUMP_REGISTERS@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EXECUTE_CYCLES>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
test   %esi,%esi
jle    138b <EXECUTE_CYCLES+0x1cb>
mov    %esi,%r14d
mov    %edi,%ebx
mov    $0x1,%edi
call   10b0 <PinSetO1@plt>
xor    %edi,%edi
call   10b0 <PinSetO1@plt>
mov    $0x1,%edi
call   1040 <PinSetO2@plt>
xor    %edi,%edi
call   1040 <PinSetO2@plt>
xor    %eax,%eax
call   10c0 <PinGetPIN_SYNC@plt>
cmp    $0x1,%eax
jne    1556 <EXECUTE_CYCLES+0x396>
xor    %eax,%eax
call   10e0 <PinGetPIN_D@plt>
cmp    $0xa2,%eax
jne    1556 <EXECUTE_CYCLES+0x396>
xor    %r13d,%r13d
xor    %eax,%eax
call   10c0 <PinGetPIN_SYNC@plt>
test   %eax,%eax
je     123f <EXECUTE_CYCLES+0x7f>
xor    %eax,%eax
call   10e0 <PinGetPIN_D@plt>
mov    %al,0x2e42(%rip)
movzbl %bl,%eax
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   10c0 <PinGetPIN_SYNC@plt>
test   %eax,%eax
je     1330 <EXECUTE_CYCLES+0x170>
mov    0x2e26(%rip),%al
test   %al,%al
js     127b <EXECUTE_CYCLES+0xbb>
xor    %r13d,%r13d
cmp    $0xf,%al
jg     12b5 <EXECUTE_CYCLES+0xf5>
test   %al,%al
je     1326 <EXECUTE_CYCLES+0x166>
cmp    $0x4,%al
je     1326 <EXECUTE_CYCLES+0x166>
jmp    156c <EXECUTE_CYCLES+0x3ac>
cmp    $0x82,%al
je     12e2 <EXECUTE_CYCLES+0x122>
cmp    $0x86,%al
je     1300 <EXECUTE_CYCLES+0x140>
cmp    $0xa2,%al
jne    156c <EXECUTE_CYCLES+0x3ac>
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
lea    0xd67(%rip),%rdi
mov    %eax,%esi
mov    0xc(%rsp),%ebx
mov    %ebx,%edx
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%r13d
jmp    131f <EXECUTE_CYCLES+0x15f>
cmp    $0x10,%al
je     1326 <EXECUTE_CYCLES+0x166>
cmp    $0x42,%al
jne    156c <EXECUTE_CYCLES+0x3ac>
xor    %r13d,%r13d
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
lea    0xdb5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xaa,%ebx
jmp    131f <EXECUTE_CYCLES+0x15f>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
lea    0xd71(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %r13d,%r13d
jmp    131f <EXECUTE_CYCLES+0x15f>
xor    %r13d,%r13d
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
lea    0xd25(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x55,%ebx
mov    %ebx,%edi
call   1090 <PinSetPIN_D@plt>
mov    $0x1,%edi
call   1030 <PinSetPIN_READY@plt>
xor    %eax,%eax
call   1060 <PinGetPIN__WR@plt>
test   %rax,%rax
jne    1385 <EXECUTE_CYCLES+0x1c5>
mov    0x2d3f(%rip),%al
test   %al,%al
je     1357 <EXECUTE_CYCLES+0x197>
cmp    $0x4,%al
je     1360 <EXECUTE_CYCLES+0x1a0>
cmp    $0x10,%al
jne    1385 <EXECUTE_CYCLES+0x1c5>
lea    0xdaf(%rip),%r15
jmp    1367 <EXECUTE_CYCLES+0x1a7>
lea    0xd7f(%rip),%r15
jmp    1367 <EXECUTE_CYCLES+0x1a7>
lea    0xd48(%rip),%r15
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10e0 <PinGetPIN_D@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x1,%r14d
jne    13a0 <EXECUTE_CYCLES+0x1e0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <DUMP_REGISTERS@plt>
add    $0xffffffff,%r14d
lea    0xd04(%rip),%r15
jmp    13d8 <EXECUTE_CYCLES+0x218>
lea    0xd50(%rip),%rbx
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10e0 <PinGetPIN_D@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
add    $0xffffffff,%r14d
je     138b <EXECUTE_CYCLES+0x1cb>
mov    $0x1,%edi
call   10b0 <PinSetO1@plt>
xor    %edi,%edi
call   10b0 <PinSetO1@plt>
mov    $0x1,%edi
call   1040 <PinSetO2@plt>
xor    %edi,%edi
call   1040 <PinSetO2@plt>
xor    %eax,%eax
call   10c0 <PinGetPIN_SYNC@plt>
test   %eax,%eax
je     1412 <EXECUTE_CYCLES+0x252>
xor    %eax,%eax
call   10e0 <PinGetPIN_D@plt>
mov    %al,0x2c6f(%rip)
xor    %eax,%eax
call   10c0 <PinGetPIN_SYNC@plt>
test   %eax,%eax
je     150f <EXECUTE_CYCLES+0x34f>
movzbl 0x2c59(%rip),%eax
test   %al,%al
js     1450 <EXECUTE_CYCLES+0x290>
cmp    $0xf,%al
jg     1499 <EXECUTE_CYCLES+0x2d9>
test   %al,%al
je     1505 <EXECUTE_CYCLES+0x345>
cmp    $0x4,%al
je     1505 <EXECUTE_CYCLES+0x345>
jmp    156c <EXECUTE_CYCLES+0x3ac>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x82,%al
je     14c4 <EXECUTE_CYCLES+0x304>
cmp    $0x86,%al
je     14e0 <EXECUTE_CYCLES+0x320>
cmp    $0xa2,%al
jne    156c <EXECUTE_CYCLES+0x3ac>
test   %r13d,%r13d
jne    154d <EXECUTE_CYCLES+0x38d>
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
lea    0xb85(%rip),%rdi
mov    %eax,%esi
mov    0xc(%rsp),%r12d
mov    %r12d,%edx
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%r13d
jmp    14fd <EXECUTE_CYCLES+0x33d>
cmp    $0x10,%al
je     1505 <EXECUTE_CYCLES+0x345>
cmp    $0x42,%al
jne    156c <EXECUTE_CYCLES+0x3ac>
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
lea    0xbd4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xaa,%r12d
jmp    14fd <EXECUTE_CYCLES+0x33d>
xor    %r12d,%r12d
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
lea    0xb8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    14fd <EXECUTE_CYCLES+0x33d>
xor    %eax,%eax
call   1080 <PinGetPIN_A@plt>
lea    0xb48(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x55,%r12d
mov    %r12d,%edi
call   1090 <PinSetPIN_D@plt>
mov    $0x1,%edi
call   1030 <PinSetPIN_READY@plt>
xor    %eax,%eax
call   1060 <PinGetPIN__WR@plt>
test   %rax,%rax
jne    13d2 <EXECUTE_CYCLES+0x212>
movzbl 0x2b5b(%rip),%eax
cmp    $0x10,%al
je     13ad <EXECUTE_CYCLES+0x1ed>
mov    %r15,%rbx
cmp    $0x4,%al
je     13b4 <EXECUTE_CYCLES+0x1f4>
test   %al,%al
jne    13d2 <EXECUTE_CYCLES+0x212>
lea    0xb95(%rip),%rbx
jmp    13b4 <EXECUTE_CYCLES+0x1f4>
lea    0xbcb(%rip),%rdi
jmp    155d <EXECUTE_CYCLES+0x39d>
lea    0xbf3(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
call   10e0 <PinGetPIN_D@plt>
lea    0xb27(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@EXECUTE_CYCLES.SYNC_LATCH = internal global i8 0
@.str = [51 x i8] c"Previous instruction took wrong number of cycles!\0A\00"
@.str.1 = [50 x i8] c"current instruction took wrong number of cycles!\0A\00"
@.str.2 = [54 x i8] c"Reading next instruction - Address %04X <- %02X (%s)\0A\00"
@.str.3 = [45 x i8] c"Reading memory(stack) - Address %04X <- $55\0A\00"
@.str.4 = [36 x i8] c"Reading memory - Address %04X <- 0\0A\00"
@.str.5 = [26 x i8] c"Reading port %04X <- $AA\0A\00"
@.str.6 = [14 x i8] c"PIN_D = %02X\0A\00"
@.str.7 = [46 x i8] c"Writing memory(stack) - Address %04X <- %02X\0A\00"
@.str.8 = [39 x i8] c"Writing memory - Address %04X <- %02X\0A\00"
@.str.9 = [27 x i8] c"Writing port %04X <- %02X\0A\00"
define void @EXECUTE_CYCLES(i8 zeroext %0, i32 %1, i8* %2) {
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8 %0, i8* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %9
9: ; preds = %145, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %148
13: ; preds = %9
%14 = call i32 @PinSetO1(i32 1)
%15 = call i32 @PinSetO1(i32 0)
%16 = call i32 @PinSetO2(i32 1)
%17 = call i32 @PinSetO2(i32 0)
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %13
%21 = call i32 (...) @PinGetPIN_SYNC()
%22 = icmp ne i32 %21, 1
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = call i32 (...) @PinGetPIN_D()
%25 = icmp ne i32 %24, 162
br i1 %25, label %26, label %29
26: ; preds = %23, %20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %23, %13
%30 = call i32 (...) @PinGetPIN_SYNC()
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 (...) @PinGetPIN_D()
%34 = trunc i32 %33 to i8
store i8 %34, i8* @EXECUTE_CYCLES.SYNC_LATCH
br label %35
35: ; preds = %32, %29
%36 = call i32 (...) @PinGetPIN_SYNC()
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %114
38: ; preds = %35
%39 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%40 = zext i8 %39 to i32
%41 = icmp eq i32 %40, 162
br i1 %41, label %42, label %58
42: ; preds = %38
%43 = load i32, i32* %8
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %42
store i32 1, i32* %8
%49 = call i32 (...) @PinGetPIN_A()
%50 = load i8, i8* %4
%51 = zext i8 %50 to i32
%52 = load i8*, i8** %6
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32 %51, i8* %52)
%54 = load i8, i8* %4
%55 = zext i8 %54 to i32
%56 = call i32 @PinSetPIN_D(i32 %55)
%57 = call i32 @PinSetPIN_READY(i32 1)
br label %113
58: ; preds = %38
%59 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%60 = zext i8 %59 to i32
%61 = icmp eq i32 %60, 134
br i1 %61, label %62, label %67
62: ; preds = %58
%63 = call i32 (...) @PinGetPIN_A()
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %63)
%65 = call i32 @PinSetPIN_D(i32 85)
%66 = call i32 @PinSetPIN_READY(i32 1)
br label %112
67: ; preds = %58
%68 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%69 = zext i8 %68 to i32
%70 = icmp eq i32 %69, 4
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @PinSetPIN_READY(i32 1)
br label %111
73: ; preds = %67
%74 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%75 = zext i8 %74 to i32
%76 = icmp eq i32 %75, 130
br i1 %76, label %77, label %82
77: ; preds = %73
%78 = call i32 (...) @PinGetPIN_A()
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %78)
%80 = call i32 @PinSetPIN_D(i32 0)
%81 = call i32 @PinSetPIN_READY(i32 1)
br label %110
82: ; preds = %73
%83 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%84 = zext i8 %83 to i32
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %82
%87 = call i32 @PinSetPIN_READY(i32 1)
br label %109
88: ; preds = %82
%89 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%90 = zext i8 %89 to i32
%91 = icmp eq i32 %90, 66
br i1 %91, label %92, label %97
92: ; preds = %88
%93 = call i32 (...) @PinGetPIN_A()
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %93)
%95 = call i32 @PinSetPIN_D(i32 170)
%96 = call i32 @PinSetPIN_READY(i32 1)
br label %108
97: ; preds = %88
%98 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%99 = zext i8 %98 to i32
%100 = icmp eq i32 %99, 16
br i1 %100, label %101, label %103
101: ; preds = %97
%102 = call i32 @PinSetPIN_READY(i32 1)
br label %107
103: ; preds = %97
%104 = call i32 (...) @PinGetPIN_D()
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %104)
%106 = call i32 @exit(i32 2)
unreachable
107: ; preds = %101
br label %108
108: ; preds = %107, %92
br label %109
109: ; preds = %108, %86
br label %110
110: ; preds = %109, %77
br label %111
111: ; preds = %110, %71
br label %112
112: ; preds = %111, %62
br label %113
113: ; preds = %112, %48
br label %114
114: ; preds = %113, %35
%115 = call i64 (...) @PinGetPIN__WR()
%116 = icmp eq i64 %115, 0
br i1 %116, label %117, label %144
117: ; preds = %114
%118 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%119 = zext i8 %118 to i32
%120 = icmp eq i32 %119, 4
br i1 %120, label %121, label %125
121: ; preds = %117
%122 = call i32 (...) @PinGetPIN_A()
%123 = call i32 (...) @PinGetPIN_D()
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %122, i32 %123)
br label %143
125: ; preds = %117
%126 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%127 = zext i8 %126 to i32
%128 = icmp eq i32 %127, 0
br i1 %128, label %129, label %133
129: ; preds = %125
%130 = call i32 (...) @PinGetPIN_A()
%131 = call i32 (...) @PinGetPIN_D()
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32 %130, i32 %131)
br label %142
133: ; preds = %125
%134 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
%135 = zext i8 %134 to i32
%136 = icmp eq i32 %135, 16
br i1 %136, label %137, label %141
137: ; preds = %133
%138 = call i32 (...) @PinGetPIN_A()
%139 = call i32 (...) @PinGetPIN_D()
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %138, i32 %139)
br label %141
141: ; preds = %137, %133
br label %142
142: ; preds = %141, %129
br label %143
143: ; preds = %142, %121
br label %144
144: ; preds = %143, %114
br label %145
145: ; preds = %144
%146 = load i32, i32* %7
%147 = add nsw i32 %146, 1
store i32 %147, i32* %7
br label %9
148: ; preds = %9
%149 = call i32 (...) @DUMP_REGISTERS()
ret void
}

LLVM IR (-O2):
@EXECUTE_CYCLES.SYNC_LATCH = internal unnamed_addr global i8 0
@.str.2 = [54 x i8] c"Reading next instruction - Address %04X <- %02X (%s)\0A\00"
@.str.3 = [45 x i8] c"Reading memory(stack) - Address %04X <- $55\0A\00"
@.str.4 = [36 x i8] c"Reading memory - Address %04X <- 0\0A\00"
@.str.5 = [26 x i8] c"Reading port %04X <- $AA\0A\00"
@.str.6 = [14 x i8] c"PIN_D = %02X\0A\00"
@.str.7 = [46 x i8] c"Writing memory(stack) - Address %04X <- %02X\0A\00"
@.str.8 = [39 x i8] c"Writing memory - Address %04X <- %02X\0A\00"
@.str.9 = [27 x i8] c"Writing port %04X <- %02X\0A\00"
@str = [49 x i8] c"current instruction took wrong number of cycles!\00"
@str.10 = [50 x i8] c"Previous instruction took wrong number of cycles!\00"
define void @EXECUTE_CYCLES(i8 zeroext %0, i32 %1, i8* %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %125
5: ; preds = %3
%6 = zext i8 %0 to i32
%7 = tail call i32 @PinSetO1(i32 1)
%8 = tail call i32 @PinSetO1(i32 0)
%9 = tail call i32 @PinSetO2(i32 1)
%10 = tail call i32 @PinSetO2(i32 0)
%11 = tail call i32 (...) @PinGetPIN_SYNC()
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %70
13: ; preds = %5
%14 = tail call i32 (...) @PinGetPIN_D()
%15 = icmp eq i32 %14, 162
br i1 %15, label %16, label %70
16: ; preds = %13
%17 = tail call i32 (...) @PinGetPIN_SYNC()
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = tail call i32 (...) @PinGetPIN_D()
%21 = trunc i32 %20 to i8
store i8 %21, i8* @EXECUTE_CYCLES.SYNC_LATCH
br label %22
22: ; preds = %19, %16
%23 = tail call i32 (...) @PinGetPIN_SYNC()
%24 = icmp eq i32 %23, 0
br i1 %24, label %46, label %25
25: ; preds = %22
%26 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
switch i8 %26, label %98 [
i8 -94, label %36
i8 -122, label %33
i8 4, label %43
i8 -126, label %30
i8 0, label %43
i8 66, label %27
i8 16, label %43
]
27: ; preds = %25
%28 = tail call i32 (...) @PinGetPIN_A()
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %39
30: ; preds = %25
%31 = tail call i32 (...) @PinGetPIN_A()
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %39
33: ; preds = %25
%34 = tail call i32 (...) @PinGetPIN_A()
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %39
36: ; preds = %25
%37 = tail call i32 (...) @PinGetPIN_A()
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %37, i32 %6, i8* %2)
br label %39
39: ; preds = %36, %33, %30, %27
%40 = phi i32 [ 85, %33 ], [ 0, %30 ], [ 170, %27 ], [ %6, %36 ]
%41 = phi i32 [ 0, %33 ], [ 0, %30 ], [ 0, %27 ], [ 1, %36 ]
%42 = tail call i32 @PinSetPIN_D(i32 %40)
br label %43
43: ; preds = %39, %25, %25, %25
%44 = phi i32 [ 0, %25 ], [ 0, %25 ], [ 0, %25 ], [ %41, %39 ]
%45 = tail call i32 @PinSetPIN_READY(i32 1)
br label %46
46: ; preds = %43, %22
%47 = phi i32 [ 0, %22 ], [ %44, %43 ]
%48 = tail call i64 (...) @PinGetPIN__WR()
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %59
50: ; preds = %46
%51 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
switch i8 %51, label %59 [
i8 4, label %54
i8 0, label %53
i8 16, label %52
]
52: ; preds = %50
br label %54
53: ; preds = %50
br label %54
54: ; preds = %53, %52, %50
%55 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), %53 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), %52 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), %50 ]
%56 = tail call i32 (...) @PinGetPIN_A()
%57 = tail call i32 (...) @PinGetPIN_D()
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %55, i32 %56, i32 %57)
br label %59
59: ; preds = %54, %50, %46
%60 = icmp eq i32 %1, 1
br i1 %60, label %125, label %61
61: ; preds = %59, %122
%62 = phi i32 [ %110, %122 ], [ %47, %59 ]
%63 = phi i32 [ %123, %122 ], [ 1, %59 ]
%64 = tail call i32 @PinSetO1(i32 1)
%65 = tail call i32 @PinSetO1(i32 0)
%66 = tail call i32 @PinSetO2(i32 1)
%67 = tail call i32 @PinSetO2(i32 0)
%68 = tail call i32 (...) @PinGetPIN_SYNC()
%69 = icmp eq i32 %68, 0
br i1 %69, label %76, label %73
70: ; preds = %13, %5
%71 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.10, i64 0, i64 0))
%72 = tail call i32 @exit(i32 1)
unreachable
73: ; preds = %61
%74 = tail call i32 (...) @PinGetPIN_D()
%75 = trunc i32 %74 to i8
store i8 %75, i8* @EXECUTE_CYCLES.SYNC_LATCH
br label %76
76: ; preds = %73, %61
%77 = tail call i32 (...) @PinGetPIN_SYNC()
%78 = icmp eq i32 %77, 0
br i1 %78, label %109, label %79
79: ; preds = %76
%80 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
switch i8 %80, label %98 [
i8 -94, label %81
i8 -122, label %89
i8 4, label %106
i8 -126, label %92
i8 0, label %106
i8 66, label %95
i8 16, label %106
]
81: ; preds = %79
%82 = icmp eq i32 %62, 0
br i1 %82, label %86, label %83
83: ; preds = %81
%84 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%85 = tail call i32 @exit(i32 1)
unreachable
86: ; preds = %81
%87 = tail call i32 (...) @PinGetPIN_A()
%88 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %87, i32 %6, i8* %2)
br label %102
89: ; preds = %79
%90 = tail call i32 (...) @PinGetPIN_A()
%91 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %90)
br label %102
92: ; preds = %79
%93 = tail call i32 (...) @PinGetPIN_A()
%94 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %93)
br label %102
95: ; preds = %79
%96 = tail call i32 (...) @PinGetPIN_A()
%97 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %96)
br label %102
98: ; preds = %79, %25
%99 = tail call i32 (...) @PinGetPIN_D()
%100 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %99)
%101 = tail call i32 @exit(i32 2)
unreachable
102: ; preds = %86, %95, %92, %89
%103 = phi i32 [ 85, %89 ], [ 0, %92 ], [ 170, %95 ], [ %6, %86 ]
%104 = phi i32 [ %62, %89 ], [ %62, %92 ], [ %62, %95 ], [ 1, %86 ]
%105 = tail call i32 @PinSetPIN_D(i32 %103)
br label %106
106: ; preds = %102, %79, %79, %79
%107 = phi i32 [ %62, %79 ], [ %62, %79 ], [ %62, %79 ], [ %104, %102 ]
%108 = tail call i32 @PinSetPIN_READY(i32 1)
br label %109
109: ; preds = %106, %76
%110 = phi i32 [ %62, %76 ], [ %107, %106 ]
%111 = tail call i64 (...) @PinGetPIN__WR()
%112 = icmp eq i64 %111, 0
br i1 %112, label %113, label %122
113: ; preds = %109
%114 = load i8, i8* @EXECUTE_CYCLES.SYNC_LATCH
switch i8 %114, label %122 [
i8 4, label %117
i8 0, label %115
i8 16, label %116
]
115: ; preds = %113
br label %117
116: ; preds = %113
br label %117
117: ; preds = %113, %116, %115
%118 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), %115 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), %116 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), %113 ]
%119 = tail call i32 (...) @PinGetPIN_A()
%120 = tail call i32 (...) @PinGetPIN_D()
%121 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %118, i32 %119, i32 %120)
br label %122
122: ; preds = %117, %113, %109
%123 = add nuw nsw i32 %63, 1
%124 = icmp eq i32 %123, %1
br i1 %124, label %125, label %61
125: ; preds = %59, %122, %3
%126 = tail call i32 (...) @DUMP_REGISTERS()
ret void
}