#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 prt_hex_2D(unsigned char *blk, int x, int y) {
  int i, j, indx;
  printf("2D print centered on location %d %d\n", x, y);
  for (i = y - 9; i < y + 9; ++i) {
    for (j = x - 9; j < x + 9; ++j) {
      indx = i * 256 + j;
      if (indx < 0 || indx >= 65536)
        printf("** ");
      else if (i == y && j == x)
        printf("%2x<", *(blk + indx));
      else
        printf("%2x ", *(blk + indx));
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<prt_hex_2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
sub    $0x9,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x9,%ecx
cmp    %ecx,%eax
jge    1225 <prt_hex_2D+0x115>
mov    -0xc(%rbp),%eax
sub    $0x9,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x9,%ecx
cmp    %ecx,%eax
jge    1209 <prt_hex_2D+0xf9>
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     118d <prt_hex_2D+0x7d>
cmpl   $0x10000,-0x1c(%rbp)
jl     11a0 <prt_hex_2D+0x90>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <prt_hex_2D+0xe6>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11d7 <prt_hex_2D+0xc7>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11d7 <prt_hex_2D+0xc7>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f1 <prt_hex_2D+0xe1>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <prt_hex_2D+0xe6>
jmp    11fb <prt_hex_2D+0xeb>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1159 <prt_hex_2D+0x49>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <prt_hex_2D+0x2f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prt_hex_2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %esi,%r13d
mov    %rdi,0x10(%rsp)
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x9(%r14),%r12d
lea    0x8(%r13),%ebp
lea    0x8(%r14),%eax
mov    %eax,0xc(%rsp)
mov    %r14,%rbx
mov    %r14d,%eax
shl    $0x8,%eax
mov    %r13d,%r15d
add    $0xfffffff6,%r15d
add    %eax,%r13d
add    $0xfffff6f7,%r13d
jmp    11a0 <prt_hex_2D+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%r12),%eax
add    $0x100,%r13d
cmp    0xc(%rsp),%r12d
mov    %eax,%r12d
jge    1210 <prt_hex_2D+0xf0>
xor    %r14d,%r14d
jmp    11d2 <prt_hex_2D+0xb2>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r15,%r14,1),%eax
add    $0x1,%eax
mov    %r14d,%ecx
add    $0x1,%ecx
mov    %ecx,%r14d
cmp    %ebp,%eax
jge    1180 <prt_hex_2D+0x60>
lea    (%r14,%r13,1),%eax
cmp    $0x10000,%eax
jae    11b0 <prt_hex_2D+0x90>
mov    %eax,%eax
mov    0x10(%rsp),%rcx
movzbl (%rcx,%rax,1),%esi
cmp    %ebx,%r12d
jne    1200 <prt_hex_2D+0xe0>
cmp    $0x9,%r14d
jne    1200 <prt_hex_2D+0xe0>
lea    0xe2f(%rip),%rdi
jmp    1207 <prt_hex_2D+0xe7>
nopl   0x0(%rax)
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11be <prt_hex_2D+0x9e>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"2D print centered on location %d %d\0A\00"
@.str.1 = [4 x i8] c"** \00"
@.str.2 = [5 x i8] c"%2x<\00"
@.str.3 = [5 x i8] c"%2x \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @prt_hex_2D(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
%13 = load i32, i32* %6
%14 = sub nsw i32 %13, 9
store i32 %14, i32* %7
br label %15
15: ; preds = %71, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 9
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %74
20: ; preds = %15
%21 = load i32, i32* %5
%22 = sub nsw i32 %21, 9
store i32 %22, i32* %8
br label %23
23: ; preds = %66, %20
%24 = load i32, i32* %8
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 9
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %69
28: ; preds = %23
%29 = load i32, i32* %7
%30 = mul nsw i32 %29, 256
%31 = load i32, i32* %8
%32 = add nsw i32 %30, %31
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = icmp slt i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %28
%36 = load i32, i32* %9
%37 = icmp sge i32 %36, 65536
br i1 %37, label %38, label %40
38: ; preds = %35, %28
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %65
40: ; preds = %35
%41 = load i32, i32* %7
%42 = load i32, i32* %6
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %56
44: ; preds = %40
%45 = load i32, i32* %8
%46 = load i32, i32* %5
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %56
48: ; preds = %44
%49 = load i8*, i8** %4
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %54)
br label %64
56: ; preds = %44, %40
%57 = load i8*, i8** %4
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %62)
br label %64
64: ; preds = %56, %48
br label %65
65: ; preds = %64, %38
br label %66
66: ; preds = %65
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %23
69: ; preds = %23
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %69
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %15
74: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"2D print centered on location %d %d\0A\00"
@.str.1 = [4 x i8] c"** \00"
@.str.2 = [5 x i8] c"%2x<\00"
@.str.3 = [5 x i8] c"%2x \00"
define void @prt_hex_2D(i8* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%5 = add nsw i32 %2, -9
%6 = add nsw i32 %1, -9
%7 = add nsw i32 %1, 8
%8 = add nsw i32 %2, 8
br label %9
9: ; preds = %3, %33
%10 = phi i32 [ %5, %3 ], [ %35, %33 ]
%11 = shl nsw i32 %10, 8
%12 = icmp eq i32 %10, %2
br label %13
13: ; preds = %9, %30
%14 = phi i32 [ %6, %9 ], [ %31, %30 ]
%15 = add nsw i32 %14, %11
%16 = icmp ugt i32 %15, 65535
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %30
19: ; preds = %13
%20 = icmp eq i32 %14, %1
%21 = select i1 %12, i1 %20, i1 false
%22 = zext i32 %15 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
br i1 %21, label %26, label %28
26: ; preds = %19
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %30
28: ; preds = %19
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %30
30: ; preds = %17, %28, %26
%31 = add nsw i32 %14, 1
%32 = icmp slt i32 %14, %7
br i1 %32, label %13, label %33
33: ; preds = %30
%34 = tail call i32 @putchar(i32 10)
%35 = add nsw i32 %10, 1
%36 = icmp slt i32 %10, %8
br i1 %36, label %9, label %37
37: ; preds = %33
ret void
}