#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*/ printf(char *, ...);
void print_state(unsigned char *ip, unsigned char *ir, unsigned char **reg,
                 unsigned char **mem) {
  int i;
  printf("Registers\n\tr0:%.2X\n\tr1:%.2X\n", (*reg)[0], (*reg)[1]);
  printf("Instruction\n\tCurrent:%X\n\tPointer:%X\n", *ir, *ip);
  printf("Memory\n\t");
  for (i = 0; i < 16; i++) {
    if (i == 8)
      printf("\n\t");
    printf("%.2X ", (*mem)[i]);
  }
  printf("\n");
  return;
}


x86 assembly (clang, -O0):
<print_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movzbl (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movzbl 0x1(%rax),%edx
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
mov    -0x8(%rbp),%rax
movzbl (%rax),%edx
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    11c9 <print_state+0xb9>
cmpl   $0x8,-0x24(%rbp)
jne    119e <print_state+0x8e>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117c <print_state+0x6c>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_state>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdx),%rax
movzbl (%rax),%esi
movzbl 0x1(%rax),%edx
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r14),%esi
movzbl (%r15),%edx
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed4(%rip),%r14
lea    0xed0(%rip),%r15
xor    %ebx,%ebx
jmp    119c <print_state+0x7c>
nop
mov    (%r12),%rax
movzbl (%rax,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x10,%rbx
je     11ae <print_state+0x8e>
cmp    $0x8,%rbx
jne    1180 <print_state+0x60>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <print_state+0x60>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Registers\0A\09r0:%.2X\0A\09r1:%.2X\0A\00"
@.str.1 = [37 x i8] c"Instruction\0A\09Current:%X\0A\09Pointer:%X\0A\00"
@.str.2 = [9 x i8] c"Memory\0A\09\00"
@.str.3 = [3 x i8] c"\0A\09\00"
@.str.4 = [6 x i8] c"%.2X \00"
@.str.5 = [2 x i8] c"\0A\00"
define void @print_state(i8* %0, i8* %1, i8** %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i8** %3, i8*** %8
%10 = load i8**, i8*** %7
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = load i8**, i8*** %7
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %19)
%21 = load i8*, i8** %6
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
br label %29
29: ; preds = %46, %4
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 16
br i1 %31, label %32, label %49
32: ; preds = %29
%33 = load i32, i32* %9
%34 = icmp eq i32 %33, 8
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = load i8**, i8*** %8
%39 = load i8*, i8** %38
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %37
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %29
49: ; preds = %29
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Registers\0A\09r0:%.2X\0A\09r1:%.2X\0A\00"
@.str.1 = [37 x i8] c"Instruction\0A\09Current:%X\0A\09Pointer:%X\0A\00"
@.str.2 = [9 x i8] c"Memory\0A\09\00"
@.str.3 = [3 x i8] c"\0A\09\00"
@.str.4 = [6 x i8] c"%.2X \00"
define void @print_state(i8* nocapture %0, i8* nocapture %1, i8** nocapture %2, i8** nocapture %3) {
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = zext i8 %6 to i32
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10)
%12 = load i8, i8* %1
%13 = zext i8 %12 to i32
%14 = load i8, i8* %0
%15 = zext i8 %14 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %4, %23
%19 = phi i64 [ 0, %4 ], [ %29, %23 ]
%20 = icmp eq i64 %19, 8
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 %19
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %19, 1
%30 = icmp eq i64 %29, 16
br i1 %30, label %31, label %18
31: ; preds = %23
%32 = tail call i32 @putchar(i32 10)
ret void
}