#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 *, ...);
int /*<<< orphan*/ puts(char *);
void memory_display(char *address, int length) {
  int i = 0;
  char *line = (char *)address;
  unsigned char ch;
  printf("%08X | ", (int)address);
  while (length-- > 0) {
    printf("%02X ", (unsigned char)*address++);
    if (!(++i % 16) || (length == 0 && i % 16)) {
      if (length == 0) {
        while (i++ % 16) {
          printf("__ ");
        }
      }
      printf("| ");
      while (line < address) {
        ch = *line++;
        printf("%c", (ch < 33 || ch == 255) ? 0x2E : ch);
      }
      if (length > 0) {
        printf("\n%08X | ", (int)address);
      }
    }
  }
  puts("");
}


x86 assembly (clang, -O0):
<memory_display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    129f <memory_display+0x17f>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11be <memory_display+0x9e>
cmpl   $0x0,-0xc(%rbp)
jne    129a <memory_display+0x17a>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     129a <memory_display+0x17a>
cmpl   $0x0,-0xc(%rbp)
jne    1201 <memory_display+0xe1>
jmp    11cd <memory_display+0xad>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11fc <memory_display+0xdc>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cd <memory_display+0xad>
jmp    1201 <memory_display+0xe1>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1277 <memory_display+0x157>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x21,%eax
jl     124d <memory_display+0x12d>
movzbl -0x19(%rbp),%eax
cmp    $0xff,%eax
jne    125a <memory_display+0x13a>
mov    $0x2e,%eax
mov    %eax,-0x20(%rbp)
jmp    1261 <memory_display+0x141>
movzbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120f <memory_display+0xef>
cmpl   $0x0,-0xc(%rbp)
jle    1295 <memory_display+0x175>
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129a <memory_display+0x17a>
jmp    1152 <memory_display+0x32>
lea    0xd5f(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_display>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xed0(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    129d <memory_display+0x17d>
mov    %rbx,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%ebp
mov    %r15d,%r15d
lea    -0x1(%r15),%r14
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
mov    %rax,%r12
movzbl (%rbx,%rax,1),%esi
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r12,%rbp,1),%eax
add    $0x1,%eax
test   $0xf,%al
je     11d0 <memory_display+0xb0>
lea    0x1(%r12),%rax
cmp    %eax,%r15d
jne    1170 <memory_display+0x50>
mov    %rbx,%r14
add    %eax,%ebp
add    $0x1,%ebp
lea    0xe5d(%rip),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    %ebp,%eax
and    $0xf,%al
cmp    $0x1,%al
jne    11b0 <memory_display+0x90>
jmp    11e6 <memory_display+0xc6>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rcx
mov    %rbx,%r14
xor    %eax,%eax
cmp    %r12d,%ecx
sete   %al
add    %r12d,%ebp
add    %eax,%ebp
add    $0x1,%ebp
lea    0xe23(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r14,%r12,1),%rax
add    $0x1,%rax
mov    %r15,0x18(%rsp)
sub    %r12,%r15
mov    %r15,0x10(%rsp)
mov    %rax,0x8(%rsp)
cmp    %rax,%r13
mov    %r14,0x20(%rsp)
jae    1260 <memory_display+0x140>
lea    (%r14,%r12,1),%r15
mov    $0x2e,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%r13),%r14
movzbl 0x0(%r13),%eax
lea    0x1(%rax),%ecx
cmp    $0x22,%cl
cmovb  %ebx,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
cmp    %r15,%r13
mov    %r14,%r13
jb     1230 <memory_display+0x110>
jmp    1263 <memory_display+0x143>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%r14
cmpl   $0x2,0x10(%rsp)
mov    0x20(%rsp),%rax
mov    0x18(%rsp),%r15
jl     129d <memory_display+0x17d>
add    $0xffffffff,%r15d
sub    %r12,%r15
lea    (%rax,%r12,1),%esi
add    $0x1,%esi
lea    0xd81(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rbx
mov    %r14,%r13
jmp    1160 <memory_display+0x40>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%08X | \00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [4 x i8] c"__ \00"
@.str.3 = [3 x i8] c"| \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [9 x i8] c"\0A%08X | \00"
@.str.6 = [1 x i8] zeroinitializer
define void @memory_display(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i8*, i8** %3
store i8* %8, i8** %6
%9 = load i8*, i8** %3
%10 = ptrtoint i8* %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %77, %2
%13 = load i32, i32* %4
%14 = add nsw i32 %13, -1
store i32 %14, i32* %4
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %78
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
%19 = load i8, i8* %17
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = srem i32 %23, 16
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %16
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %77
29: ; preds = %26
%30 = load i32, i32* %5
%31 = srem i32 %30, 16
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %77
33: ; preds = %29, %16
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %33
br label %37
37: ; preds = %42, %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
%40 = srem i32 %38, 16
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %37
44: ; preds = %37
br label %45
45: ; preds = %44, %33
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %66, %45
%48 = load i8*, i8** %6
%49 = load i8*, i8** %3
%50 = icmp ult i8* %48, %49
br i1 %50, label %51, label %69
51: ; preds = %47
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %6
%54 = load i8, i8* %52
store i8 %54, i8* %7
%55 = load i8, i8* %7
%56 = zext i8 %55 to i32
%57 = icmp slt i32 %56, 33
br i1 %57, label %62, label %58
58: ; preds = %51
%59 = load i8, i8* %7
%60 = zext i8 %59 to i32
%61 = icmp eq i32 %60, 255
br i1 %61, label %62, label %63
62: ; preds = %58, %51
br label %66
63: ; preds = %58
%64 = load i8, i8* %7
%65 = zext i8 %64 to i32
br label %66
66: ; preds = %63, %62
%67 = phi i32 [ 46, %62 ], [ %65, %63 ]
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %67)
br label %47
69: ; preds = %47
%70 = load i32, i32* %4
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = load i8*, i8** %3
%74 = ptrtoint i8* %73 to i32
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %72, %69
br label %77
77: ; preds = %76, %29, %26
br label %12
78: ; preds = %12
%79 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
ret void
}

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