#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 ceil(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ log10(short);
int /*<<< orphan*/ stderr;
void print(short instruction, int accumulator, int *memory, short mem_length) {
  fprintf(stderr, "Instruction Pointer: %hd\n", instruction);
  fprintf(stderr, "Instruction Register: %d\n", memory[instruction]);
  fprintf(stderr, "Accumulator: %d\n", accumulator);
  int number_width = ceil(log10(mem_length));
  int mem_width = 2 + number_width;
  fprintf(stderr, "Memory:\n");
  for (int i = 0; i < mem_length;) {
    fprintf(stderr, "%*d |", number_width, i);
    for (int ii = 0; ii < 10; ii++, i++)
      fprintf(stderr, " %*d", mem_width, memory[i]);
    fprintf(stderr, "\n");
  }
}


x86 assembly (clang, -O0):
<print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cx,%ax
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
movswl -0x2(%rbp),%edx
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movswq -0x2(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movswl -0x12(%rbp),%edi
call   1050 <log10@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
movswl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jge    1274 <print+0x144>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jge    1258 <print+0x128>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1212 <print+0xe2>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11df <print+0xaf>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%ebp
mov    0x2e93(%rip),%r14
mov    (%r14),%edi
lea    0xea9(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
movslq %ebp,%rax
mov    (%rbx,%rax,4),%edx
lea    0xeaa(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xeb3(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12d,%edi
call   1050 <log10@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,0x4(%rsp)
mov    (%r14),%edi
lea    0xe9d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12d,%r15d
test   %r15w,%r15w
jle    12cd <print+0x19d>
mov    0x4(%rsp),%ebp
add    $0x2,%ebp
lea    0xe8a(%rip),%r13
xor    %r12d,%r12d
nopl   (%rax)
mov    (%r14),%edi
lea    0xe74(%rip),%rsi
mov    0x4(%rsp),%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    (%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x4(%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x8(%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0xc(%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x10(%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x14(%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x18(%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x1c(%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x20(%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x24(%rbx,%r12,4),%ecx
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xd93(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xa,%r12
cmp    %r15d,%r12d
jl     11d0 <print+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Instruction Pointer: %hd\0A\00"
@.str.1 = [26 x i8] c"Instruction Register: %d\0A\00"
@.str.2 = [17 x i8] c"Accumulator: %d\0A\00"
@.str.3 = [9 x i8] c"Memory:\0A\00"
@.str.4 = [6 x i8] c"%*d |\00"
@.str.5 = [5 x i8] c" %*d\00"
@.str.6 = [2 x i8] c"\0A\00"
define void @print(i16 signext %0, i32 %1, i32* %2, i16 signext %3) {
%5 = alloca i16
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i16
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i16 %0, i16* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i16 %3, i16* %8
%13 = load i32, i32* @stderr
%14 = load i16, i16* %5
%15 = sext i16 %14 to i32
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @stderr
%18 = load i32*, i32** %7
%19 = load i16, i16* %5
%20 = sext i16 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @stderr
%25 = load i32, i32* %6
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i16, i16* %8
%28 = call i32 @log10(i16 signext %27)
%29 = call i32 @ceil(i32 %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = add nsw i32 2, %30
store i32 %31, i32* %10
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %11
br label %34
34: ; preds = %61, %4
%35 = load i32, i32* %11
%36 = load i16, i16* %8
%37 = sext i16 %36 to i32
%38 = icmp slt i32 %35, %37
br i1 %38, label %39, label %64
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i32, i32* %9
%42 = load i32, i32* %11
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %41, i32 %42)
store i32 0, i32* %12
br label %44
44: ; preds = %56, %39
%45 = load i32, i32* %12
%46 = icmp slt i32 %45, 10
br i1 %46, label %47, label %61
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = load i32, i32* %10
%50 = load i32*, i32** %7
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 %54)
br label %56
56: ; preds = %47
%57 = load i32, i32* %12
%58 = add nsw i32 %57, 1
store i32 %58, i32* %12
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
store i32 %60, i32* %11
br label %44
61: ; preds = %44
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %34
64: ; preds = %34
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Instruction Pointer: %hd\0A\00"
@.str.1 = [26 x i8] c"Instruction Register: %d\0A\00"
@.str.2 = [17 x i8] c"Accumulator: %d\0A\00"
@.str.3 = [9 x i8] c"Memory:\0A\00"
@.str.4 = [6 x i8] c"%*d |\00"
@.str.5 = [5 x i8] c" %*d\00"
@.str.6 = [2 x i8] c"\0A\00"
define void @print(i16 signext %0, i32 %1, i32* nocapture %2, i16 signext %3) {
%5 = load i32, i32* @stderr
%6 = sext i16 %0 to i32
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @stderr
%9 = sext i16 %0 to i64
%10 = getelementptr inbounds i32, i32* %2, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%15 = tail call i32 @log10(i16 signext %3)
%16 = tail call i32 @ceil(i32 %15)
%17 = add nsw i32 %16, 2
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%20 = sext i16 %3 to i32
%21 = icmp sgt i16 %3, 0
br i1 %21, label %23, label %22
22: ; preds = %23, %4
ret void
23: ; preds = %4, %23
%24 = phi i32 [ %77, %23 ], [ 0, %4 ]
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %16, i32 %24)
%27 = sext i32 %24 to i64
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds i32, i32* %2, i64 %27
%30 = load i32, i32* %29
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %30)
%32 = or i64 %27, 1
%33 = load i32, i32* @stderr
%34 = getelementptr inbounds i32, i32* %2, i64 %32
%35 = load i32, i32* %34
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %35)
%37 = add nsw i64 %27, 2
%38 = load i32, i32* @stderr
%39 = getelementptr inbounds i32, i32* %2, i64 %37
%40 = load i32, i32* %39
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %40)
%42 = add nsw i64 %27, 3
%43 = load i32, i32* @stderr
%44 = getelementptr inbounds i32, i32* %2, i64 %42
%45 = load i32, i32* %44
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %45)
%47 = add nsw i64 %27, 4
%48 = load i32, i32* @stderr
%49 = getelementptr inbounds i32, i32* %2, i64 %47
%50 = load i32, i32* %49
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %50)
%52 = add nsw i64 %27, 5
%53 = load i32, i32* @stderr
%54 = getelementptr inbounds i32, i32* %2, i64 %52
%55 = load i32, i32* %54
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %55)
%57 = add nsw i64 %27, 6
%58 = load i32, i32* @stderr
%59 = getelementptr inbounds i32, i32* %2, i64 %57
%60 = load i32, i32* %59
%61 = tail call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %60)
%62 = add nsw i64 %27, 7
%63 = load i32, i32* @stderr
%64 = getelementptr inbounds i32, i32* %2, i64 %62
%65 = load i32, i32* %64
%66 = tail call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %65)
%67 = add nsw i64 %27, 8
%68 = load i32, i32* @stderr
%69 = getelementptr inbounds i32, i32* %2, i64 %67
%70 = load i32, i32* %69
%71 = tail call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %70)
%72 = add nsw i64 %27, 9
%73 = load i32, i32* @stderr
%74 = getelementptr inbounds i32, i32* %2, i64 %72
%75 = load i32, i32* %74
%76 = tail call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %75)
%77 = add i32 %24, 10
%78 = load i32, i32* @stderr
%79 = tail call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%80 = icmp slt i32 %77, %20
br i1 %80, label %23, label %22
}