#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void p_mem(uint8_t *buff, uint32_t length) {
  uint32_t row, col, i = 0;
  printf("      00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
  for (row = 0; (i + 1) < length; row++) {
    printf("%04x: ", row * 16);
    for (col = 0; col < 16; col++) {
      i = row * 16 + col;
      if (i < length)
        printf("%02x", buff[i]);
      else
        printf("  ");
      printf(" ");
    }
    printf("| ");
    for (col = 0; col < 16; col++) {
      i = row * 16 + col;
      if (i < length) {
        if (buff[i] > 0x20 && buff[i] < 0x7F)
          printf("%c", buff[i]);
        else
          printf(".");
      } else
        break;
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<p_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cmp    -0xc(%rbp),%eax
jge    128f <p_mem+0x17f>
mov    -0x10(%rbp),%esi
shl    $0x4,%esi
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    11cf <p_mem+0xbf>
mov    -0x10(%rbp),%eax
shl    $0x4,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a5 <p_mem+0x95>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b3 <p_mem+0xa3>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <p_mem+0x55>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    1273 <p_mem+0x163>
mov    -0x10(%rbp),%eax
shl    $0x4,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    125b <p_mem+0x14b>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x20,(%rax,%rcx,4)
jle    1248 <p_mem+0x138>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x7f,(%rax,%rcx,4)
jge    1248 <p_mem+0x138>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1256 <p_mem+0x146>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1260 <p_mem+0x150>
jmp    1273 <p_mem+0x163>
jmp    1265 <p_mem+0x155>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e4 <p_mem+0xd4>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113b <p_mem+0x2b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xec8(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,(%rsp)
cmp    $0x2,%ebp
jl     1275 <p_mem+0x145>
mov    (%rsp),%r14d
mov    $0xfffffff0,%eax
lea    0xe9c(%rip),%r15
lea    0xe9a(%rip),%r13
xor    %r12d,%r12d
xor    %ecx,%ecx
jmp    11b4 <p_mem+0x84>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp),%rcx
add    $0x1,%rcx
sub    0x8(%rsp),%r15d
add    $0x40,%rbx
add    $0x10,%r12
mov    0x4(%rsp),%eax
add    $0xfffffff0,%eax
cmp    (%rsp),%r15d
mov    %rbp,%r15
jge    1275 <p_mem+0x145>
mov    %eax,0x4(%rsp)
mov    %eax,%eax
add    $0xf,%rax
mov    %rax,0x8(%rsp)
mov    %rcx,0x10(%rsp)
mov    %ecx,%esi
shl    $0x4,%esi
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
jmp    11fe <p_mem+0xce>
nop
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     1220 <p_mem+0xf0>
lea    (%r12,%rbp,1),%rax
cmp    %r14,%rax
jge    11e0 <p_mem+0xb0>
mov    (%rbx,%rbp,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ea <p_mem+0xba>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rbp
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%r15
add    %r12,%rax
cmp    %r14,%rax
jge    1180 <p_mem+0x50>
mov    (%rbx,%r15,4),%edi
lea    -0x21(%rdi),%eax
cmp    $0x5e,%eax
mov    $0x2e,%eax
cmovae %eax,%edi
call   1030 <putchar@plt>
lea    0x1(%r15),%rax
cmp    $0x10,%rax
jne    1240 <p_mem+0x110>
jmp    1180 <p_mem+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c" 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\0A\00"
@.str.1 = [7 x i8] c"%04x: \00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [3 x i8] c" \00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [3 x i8] c"| \00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [2 x i8] c".\00"
@.str.8 = [2 x i8] c"\0A\00"
define void @p_mem(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %9
9: ; preds = %87, %2
%10 = load i32, i32* %7
%11 = add nsw i32 %10, 1
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %90
14: ; preds = %9
%15 = load i32, i32* %5
%16 = mul nsw i32 %15, 16
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 0, i32* %6
br label %18
18: ; preds = %40, %14
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 16
br i1 %20, label %21, label %43
21: ; preds = %18
%22 = load i32, i32* %5
%23 = mul nsw i32 %22, 16
%24 = load i32, i32* %6
%25 = add nsw i32 %23, %24
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %36
29: ; preds = %21
%30 = load i32*, i32** %3
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %38
36: ; preds = %21
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %29
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %18
43: ; preds = %18
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %6
br label %45
45: ; preds = %82, %43
%46 = load i32, i32* %6
%47 = icmp slt i32 %46, 16
br i1 %47, label %48, label %85
48: ; preds = %45
%49 = load i32, i32* %5
%50 = mul nsw i32 %49, 16
%51 = load i32, i32* %6
%52 = add nsw i32 %50, %51
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = load i32, i32* %4
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %80
56: ; preds = %48
%57 = load i32*, i32** %3
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = icmp sgt i32 %61, 32
br i1 %62, label %63, label %77
63: ; preds = %56
%64 = load i32*, i32** %3
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = icmp slt i32 %68, 127
br i1 %69, label %70, label %77
70: ; preds = %63
%71 = load i32*, i32** %3
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
%75 = load i32, i32* %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %75)
br label %79
77: ; preds = %63, %56
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %79
79: ; preds = %77, %70
br label %81
80: ; preds = %48
br label %85
81: ; preds = %79
br label %82
82: ; preds = %81
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %45
85: ; preds = %80, %45
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %87
87: ; preds = %85
%88 = load i32, i32* %5
%89 = add nsw i32 %88, 1
store i32 %89, i32* %5
br label %9
90: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%04x: \00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [3 x i8] c" \00"
@.str.5 = [3 x i8] c"| \00"
@str = [54 x i8] c" 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\00"
define void @p_mem(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %47
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %41
%8 = phi i64 [ 0, %5 ], [ %44, %41 ]
%9 = shl nsw i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %7, %22
%13 = phi i64 [ 0, %7 ], [ %24, %22 ]
%14 = add nuw nsw i64 %13, %9
%15 = icmp slt i64 %14, %6
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = getelementptr inbounds i32, i32* %0, i64 %14
%18 = load i32, i32* %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %22
20: ; preds = %12
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = tail call i32 @putchar(i32 32)
%24 = add nuw nsw i64 %13, 1
%25 = icmp eq i64 %24, 16
br i1 %25, label %26, label %12
26: ; preds = %22
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %28
28: ; preds = %26, %32
%29 = phi i64 [ 0, %26 ], [ %39, %32 ]
%30 = add nuw nsw i64 %29, %9
%31 = icmp slt i64 %30, %6
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = getelementptr inbounds i32, i32* %0, i64 %30
%34 = load i32, i32* %33
%35 = add i32 %34, -33
%36 = icmp ult i32 %35, 94
%37 = select i1 %36, i32 %34, i32 46
%38 = tail call i32 @putchar(i32 %37)
%39 = add nuw nsw i64 %29, 1
%40 = icmp eq i64 %39, 16
br i1 %40, label %41, label %28
41: ; preds = %28, %32
%42 = trunc i64 %30 to i32
%43 = tail call i32 @putchar(i32 10)
%44 = add nuw i64 %8, 1
%45 = add nuw nsw i32 %42, 1
%46 = icmp slt i32 %45, %1
br i1 %46, label %7, label %47
47: ; preds = %41, %2
ret void
}