#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void print_current_state(char *prog_array, char *ptr, int arr_size) {
  int ptr_index = ptr - prog_array;
  int start_i = ptr_index - 8 < 0 ? 0 : ptr_index - 8;
  int end_i = ptr_index + 8 < arr_size ? ptr_index + 8 : arr_size - 1;
  int i;
  fprintf(stderr, "Indices:");
  for (i = start_i; i < end_i; i++) {
    fprintf(stderr, " %5d ", i);
  }
  fprintf(stderr, "\n");
  fprintf(stderr, "Array  :");
  for (i = start_i; i < end_i; i++) {
    fprintf(stderr, " %5d ", prog_array[i]);
  }
  fprintf(stderr, "\n");
  fprintf(stderr, "Pointer:");
  char ptr_symbol = '^';
  for (i = start_i; i < end_i; i++) {
    if (i == ptr_index) {
      fprintf(stderr, " %5c ", ptr_symbol);
    } else {
      fprintf(stderr, "       ");
    }
  }
  fprintf(stderr, "\n");
}


x86 assembly (clang, -O0):
<print_current_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x8,%eax
cmp    $0x0,%eax
jge    114a <print_current_state+0x3a>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    1153 <print_current_state+0x43>
mov    -0x18(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x8,%eax
cmp    -0x14(%rbp),%eax
jge    1176 <print_current_state+0x66>
mov    -0x18(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x30(%rbp)
jmp    117f <print_current_state+0x6f>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d6 <print_current_state+0xc6>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a2 <print_current_state+0x92>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1247 <print_current_state+0x137>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120a <print_current_state+0xfa>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movb   $0x5e,-0x25(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12e1 <print_current_state+0x1d1>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    12b7 <print_current_state+0x1a7>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
movsbl -0x25(%rbp),%edx
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12ce <print_current_state+0x1be>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12d3 <print_current_state+0x1c3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127f <print_current_state+0x16f>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd1e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_current_state>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %rdi,%rbx
sub    %ebx,%r12d
cmp    $0x9,%r12d
mov    $0x8,%ebp
cmovge %r12d,%ebp
lea    -0x8(%rbp),%r15d
lea    0x8(%r12),%eax
lea    -0x1(%rdx),%r14d
cmp    %edx,%eax
cmovl  %eax,%r14d
mov    0x2e92(%rip),%r13
mov    0x0(%r13),%edi
lea    0xea7(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    %r14d,%r15d
jge    1201 <print_current_state+0xf1>
mov    %rbp,0x8(%rsp)
mov    %rbx,0x10(%rsp)
lea    0xe8f(%rip),%rbx
mov    %r15d,%ebp
nopl   (%rax)
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1180 <print_current_state+0x70>
mov    0x0(%r13),%edi
lea    0xe6c(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe5c(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    %r14d,%r15d
jge    129d <print_current_state+0x18d>
mov    %r12,(%rsp)
mov    0x8(%rsp),%ebp
add    $0xfffffffffffffff8,%rbp
mov    %r14d,%r12d
mov    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    0x0(%r13),%edi
movsbl (%rbx,%rbp,1),%edx
lea    0xe1a(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %ebp,%r12d
jne    11e0 <print_current_state+0xd0>
jmp    1229 <print_current_state+0x119>
mov    %r12,(%rsp)
mov    0x0(%r13),%edi
lea    0xdff(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xdef(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xddb(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xdd4(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    %r14d,%r15d
mov    (%rsp),%rbp
jge    12c1 <print_current_state+0x1b1>
lea    0xdc6(%rip),%r12
lea    0xdc5(%rip),%rbx
jmp    1283 <print_current_state+0x173>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r15d
cmp    %r15d,%r14d
je     12c1 <print_current_state+0x1b1>
mov    0x0(%r13),%edi
cmp    %r15d,%ebp
jne    1270 <print_current_state+0x160>
mov    %r12,%rsi
mov    $0x5e,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    127a <print_current_state+0x16a>
mov    0x0(%r13),%edi
lea    0xd67(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xd60(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xd43(%rip),%rsi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"Indices:\00"
@.str.1 = [6 x i8] c" %5d \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [9 x i8] c"Array :\00"
@.str.4 = [9 x i8] c"Pointer:\00"
@.str.5 = [6 x i8] c" %5c \00"
@.str.6 = [8 x i8] c" \00"
define void @print_current_state(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
%13 = load i8*, i8** %4
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 8
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %3
br label %25
22: ; preds = %3
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 8
br label %25
25: ; preds = %22, %21
%26 = phi i32 [ 0, %21 ], [ %24, %22 ]
store i32 %26, i32* %8
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 8
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 8
br label %37
34: ; preds = %25
%35 = load i32, i32* %6
%36 = sub nsw i32 %35, 1
br label %37
37: ; preds = %34, %31
%38 = phi i32 [ %33, %31 ], [ %36, %34 ]
store i32 %38, i32* %9
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%41 = load i32, i32* %8
store i32 %41, i32* %10
br label %42
42: ; preds = %50, %37
%43 = load i32, i32* %10
%44 = load i32, i32* %9
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = load i32, i32* %10
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %46
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %42
53: ; preds = %42
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* %8
store i32 %58, i32* %10
br label %59
59: ; preds = %72, %53
%60 = load i32, i32* %10
%61 = load i32, i32* %9
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %75
63: ; preds = %59
%64 = load i32, i32* @stderr
%65 = load i8*, i8** %4
%66 = load i32, i32* %10
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %63
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
store i32 %74, i32* %10
br label %59
75: ; preds = %59
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i8 94, i8* %11
%80 = load i32, i32* %8
store i32 %80, i32* %10
br label %81
81: ; preds = %98, %75
%82 = load i32, i32* %10
%83 = load i32, i32* %9
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %101
85: ; preds = %81
%86 = load i32, i32* %10
%87 = load i32, i32* %7
%88 = icmp eq i32 %86, %87
br i1 %88, label %89, label %94
89: ; preds = %85
%90 = load i32, i32* @stderr
%91 = load i8, i8* %11
%92 = sext i8 %91 to i32
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %92)
br label %97
94: ; preds = %85
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %97
97: ; preds = %94, %89
br label %98
98: ; preds = %97
%99 = load i32, i32* %10
%100 = add nsw i32 %99, 1
store i32 %100, i32* %10
br label %81
101: ; preds = %81
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [9 x i8] c"Indices:\00"
@.str.1 = [6 x i8] c" %5d \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [9 x i8] c"Array :\00"
@.str.4 = [9 x i8] c"Pointer:\00"
@.str.5 = [6 x i8] c" %5c \00"
@.str.6 = [8 x i8] c" \00"
define void @print_current_state(i8* %0, i8* %1, i32 %2) {
%4 = ptrtoint i8* %1 to i64
%5 = ptrtoint i8* %0 to i64
%6 = sub i64 %4, %5
%7 = trunc i64 %6 to i32
%8 = icmp sgt i32 %7, 8
%9 = select i1 %8, i32 %7, i32 8
%10 = add nsw i32 %9, -8
%11 = add nsw i32 %7, 8
%12 = icmp slt i32 %11, %2
%13 = add nsw i32 %2, -1
%14 = select i1 %12, i32 %11, i32 %13
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%17 = icmp slt i32 %10, %14
br i1 %17, label %18, label %42
18: ; preds = %3, %18
%19 = phi i32 [ %22, %18 ], [ %10, %3 ]
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%22 = add i32 %19, 1
%23 = icmp eq i32 %22, %14
br i1 %23, label %24, label %18
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br i1 %17, label %29, label %63
29: ; preds = %24
%30 = zext i32 %9 to i64
%31 = add nsw i64 %30, -8
br label %32
32: ; preds = %29, %32
%33 = phi i64 [ %31, %29 ], [ %39, %32 ]
%34 = load i32, i32* @stderr
%35 = getelementptr inbounds i8, i8* %0, i64 %33
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = add nsw i64 %33, 1
%40 = trunc i64 %39 to i32
%41 = icmp eq i32 %14, %40
br i1 %41, label %47, label %32
42: ; preds = %3
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %32, %42
%48 = load i32, i32* @stderr
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br i1 %17, label %52, label %68
52: ; preds = %47, %60
%53 = phi i32 [ %61, %60 ], [ %10, %47 ]
%54 = icmp eq i32 %53, %7
%55 = load i32, i32* @stderr
br i1 %54, label %56, label %58
56: ; preds = %52
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 94)
br label %60
58: ; preds = %52
%59 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %60
60: ; preds = %56, %58
%61 = add i32 %53, 1
%62 = icmp eq i32 %61, %14
br i1 %62, label %68, label %52
63: ; preds = %24
%64 = load i32, i32* @stderr
%65 = tail call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%66 = load i32, i32* @stderr
%67 = tail call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %68
68: ; preds = %60, %63, %47
%69 = load i32, i32* @stderr
%70 = tail call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}