#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 char *uint64_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ to_print(int /*<<< orphan*/);
void dump_buffer(unsigned char *buffer, uint64_t addr, size_t sz) {
  char printable[20];
  size_t index = 0;
  unsigned char *ptr = buffer;
  unsigned char *end = buffer + sz;
  while (ptr < end) {
    size_t len = (end - ptr);
    if (len > 16)
      len = 16;
    printf("%08zx  ", addr + (ptr - buffer));
    char *trans = printable;
    *trans++ = '|';
    for (size_t i = 0; i < 16; i++) {
      if (i == 8)
        printf(" ");
      if (i < len) {
        printf("%02x ", *ptr);
        *trans++ = to_print(*ptr++);
      } else {
        printf("   ");
      }
    }
    *trans++ = '|';
    *trans = '\0';
    printf(" %s\n", printable);
  }
}


x86 assembly (clang, -O0):
<dump_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    128c <dump_buffer+0x16c>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x10,-0x50(%rbp)
jbe    1180 <dump_buffer+0x60>
movq   $0x10,-0x50(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    %rax,%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x58(%rbp)
movb   $0x7c,(%rax)
movq   $0x0,-0x60(%rbp)
cmpq   $0x10,-0x60(%rbp)
jae    125c <dump_buffer+0x13c>
cmpq   $0x8,-0x60(%rbp)
jne    11e6 <dump_buffer+0xc6>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x60(%rbp),%rax
cmp    -0x50(%rbp),%rax
jae    1238 <dump_buffer+0x118>
mov    -0x40(%rbp),%rax
movzbl (%rax),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
movzbl (%rax),%edi
call   1040 <to_print@plt>
mov    %al,%cl
mov    -0x58(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x58(%rbp)
mov    %cl,(%rax)
jmp    1246 <dump_buffer+0x126>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124b <dump_buffer+0x12b>
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    11c2 <dump_buffer+0xa2>
mov    -0x58(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x58(%rbp)
movb   $0x7c,(%rax)
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x30(%rbp),%rsi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1150 <dump_buffer+0x30>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,0x18(%rsp)
mov    %rdi,0x8(%rsp)
test   %rdx,%rdx
jle    1242 <dump_buffer+0x112>
mov    %rdx,%r13
mov    0x8(%rsp),%r15
add    %r15,%r13
lea    0xea5(%rip),%rbx
lea    0xea4(%rip),%rbp
mov    %r13,0x10(%rsp)
jmp    11a8 <dump_buffer+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movw   $0x7c,(%r12)
lea    0xe84(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%r13
cmp    %r13,%r15
jae    1242 <dump_buffer+0x112>
sub    %r15,%r13
cmp    $0x10,%r13
mov    $0x10,%eax
cmovae %rax,%r13
mov    %r15,%rsi
sub    0x8(%rsp),%rsi
add    0x18(%rsp),%rsi
lea    0xe34(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0x7c,0x20(%rsp)
xor    %r14d,%r14d
lea    0x21(%rsp),%r12
jmp    1208 <dump_buffer+0xd8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14
cmp    $0x10,%r14
je     1180 <dump_buffer+0x50>
cmp    $0x8,%r14
jne    1218 <dump_buffer+0xe8>
mov    $0x20,%edi
call   1030 <putchar@plt>
cmp    %r13,%r14
jae    11f0 <dump_buffer+0xc0>
movzbl (%r15),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r15),%edi
add    $0x1,%r15
call   1050 <to_print@plt>
mov    %al,(%r12)
add    $0x1,%r12
jmp    11fa <dump_buffer+0xca>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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