#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 dump_mem(const void *ptr, size_t len) {
  size_t i = 0;
  char *buf = (char *)ptr;
  printf("%p ", ptr);
  for (i = 0; i < len; i++) {
    if (i != 0 && i % 16 == 0)
      printf("\n%p ", &buf[i]);
    printf("%x ", buf[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dump_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b6 <dump_mem+0xa6>
cmpq   $0x0,-0x18(%rbp)
je     118b <dump_mem+0x7b>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    118b <dump_mem+0x7b>
mov    -0x20(%rbp),%rsi
add    -0x18(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114a <dump_mem+0x3a>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_mem>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
lea    0xecb(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14,%r14
je     1198 <dump_mem+0x78>
lea    0xeb4(%rip),%r15
lea    0xeb2(%rip),%r12
xor    %ebx,%ebx
jmp    1179 <dump_mem+0x59>
nopw   0x0(%rax,%rax,1)
movsbl 0x0(%r13,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     1198 <dump_mem+0x78>
test   %rbx,%rbx
je     1160 <dump_mem+0x40>
mov    %ebx,%eax
and    $0xf,%eax
test   %rax,%rax
jne    1160 <dump_mem+0x40>
lea    (%rbx,%r13,1),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <dump_mem+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%p \00"
@.str.1 = [5 x i8] c"\0A%p \00"
@.str.2 = [4 x i8] c"%x \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @dump_mem(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %5
%7 = load i8*, i8** %3
store i8* %7, i8** %6
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
store i64 0, i64* %5
br label %10
10: ; preds = %33, %2
%11 = load i64, i64* %5
%12 = load i64, i64* %4
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load i64, i64* %5
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i64, i64* %5
%19 = urem i64 %18, 16
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = load i64, i64* %5
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %21, %17, %14
%27 = load i8*, i8** %6
%28 = load i64, i64* %5
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %26
%34 = load i64, i64* %5
%35 = add i64 %34, 1
store i64 %35, i64* %5
br label %10
36: ; preds = %10
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%p \00"
@.str.1 = [5 x i8] c"\0A%p \00"
@.str.2 = [4 x i8] c"%x \00"
define void @dump_mem(i8* %0, i64 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = icmp eq i64 %1, 0
br i1 %4, label %21, label %5
5: ; preds = %2, %14
%6 = phi i64 [ %19, %14 ], [ 0, %2 ]
%7 = icmp ne i64 %6, 0
%8 = and i64 %6, 15
%9 = icmp eq i64 %8, 0
%10 = and i1 %7, %9
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %0, i64 %6
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %11, %5
%15 = getelementptr inbounds i8, i8* %0, i64 %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = add nuw i64 %6, 1
%20 = icmp eq i64 %19, %1
br i1 %20, label %21, label %5
21: ; preds = %14, %2
%22 = tail call i32 @putchar(i32 10)
ret void
}