#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 simulate(char *p) {
  printf("\n");
  for (int i = 0; i < 3; ++i) {
    if (i > 0) {
      for (int k = 0; k < 3; ++k) {
        if (k > 0) {
          printf("+");
        }
        for (int l = 0; l < 3 + 2; ++l) {
          printf("-");
        }
      }
      printf("\n");
    }
    for (int j = 0; j < 3; ++j) {
      if (j > 0) {
        printf("|");
      }
      printf("  %c  ", *(p++));
    }
    printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<simulate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    122f <simulate+0x11f>
cmpl   $0x0,-0xc(%rbp)
jle    11bc <simulate+0xac>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    11ae <simulate+0x9e>
cmpl   $0x0,-0x10(%rbp)
jle    116e <simulate+0x5e>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    119b <simulate+0x8b>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <simulate+0x65>
jmp    11a0 <simulate+0x90>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114c <simulate+0x3c>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    1213 <simulate+0x103>
cmpl   $0x0,-0x18(%rbp)
jle    11e5 <simulate+0xd5>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%esi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c3 <simulate+0xb3>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1131 <simulate+0x21>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simulate>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    $0xa,%edi
call   1030 <putchar@plt>
movsbl (%r15),%esi
lea    0xec3(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x7c,%edi
call   1030 <putchar@plt>
movsbl 0x1(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x7c,%edi
call   1030 <putchar@plt>
movsbl 0x2(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2b,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2b,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsbl 0x3(%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x7c,%edi
call   1030 <putchar@plt>
movsbl 0x4(%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x7c,%edi
call   1030 <putchar@plt>
movsbl 0x5(%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x3,%rbx
cmp    $0x6,%ebx
jne    1190 <simulate+0x70>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str.4 = [7 x i8] c" %c \00"
define void @simulate(i8* nocapture %0) {
%2 = tail call i32 @putchar(i32 10)
%3 = load i8, i8* %0
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = sext i8 %3 to i32
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %5)
%7 = tail call i32 @putchar(i32 124)
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%12 = tail call i32 @putchar(i32 124)
%13 = load i8, i8* %8
%14 = sext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = tail call i32 @putchar(i32 10)
br label %19
17: ; preds = %19
%18 = tail call i32 @putchar(i32 10)
ret void
19: ; preds = %1, %19
%20 = phi i32 [ 1, %1 ], [ %55, %19 ]
%21 = phi i8* [ %0, %1 ], [ %22, %19 ]
%22 = getelementptr inbounds i8, i8* %21, i64 3
%23 = tail call i32 @putchar(i32 45)
%24 = tail call i32 @putchar(i32 45)
%25 = tail call i32 @putchar(i32 45)
%26 = tail call i32 @putchar(i32 45)
%27 = tail call i32 @putchar(i32 45)
%28 = tail call i32 @putchar(i32 43)
%29 = tail call i32 @putchar(i32 45)
%30 = tail call i32 @putchar(i32 45)
%31 = tail call i32 @putchar(i32 45)
%32 = tail call i32 @putchar(i32 45)
%33 = tail call i32 @putchar(i32 45)
%34 = tail call i32 @putchar(i32 43)
%35 = tail call i32 @putchar(i32 45)
%36 = tail call i32 @putchar(i32 45)
%37 = tail call i32 @putchar(i32 45)
%38 = tail call i32 @putchar(i32 45)
%39 = tail call i32 @putchar(i32 45)
%40 = tail call i32 @putchar(i32 10)
%41 = load i8, i8* %22
%42 = getelementptr inbounds i8, i8* %21, i64 4
%43 = sext i8 %41 to i32
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%45 = tail call i32 @putchar(i32 124)
%46 = getelementptr inbounds i8, i8* %21, i64 5
%47 = load i8, i8* %42
%48 = sext i8 %47 to i32
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = tail call i32 @putchar(i32 124)
%51 = load i8, i8* %46
%52 = sext i8 %51 to i32
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %52)
%54 = tail call i32 @putchar(i32 10)
%55 = add nuw nsw i32 %20, 1
%56 = icmp eq i32 %55, 3
br i1 %56, label %17, label %19
}