#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 mem_dump(void *str, size_t size, int len) {
  unsigned char *strPtr = str;
  int i;
  for (i = 0; i < size; i++) {
    if (i == 0) {
      printf("%p    ", &(*(strPtr + i)));
    } else if (i % len == 0) {
      printf("\n%p    ", &(*(strPtr + i)));
    }
    printf("%02x ", *strPtr);
    strPtr++;
  }
}


x86 assembly (clang, -O0):
<mem_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11c5 <mem_dump+0xb5>
cmpl   $0x0,-0x24(%rbp)
jne    1168 <mem_dump+0x58>
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1196 <mem_dump+0x86>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    1191 <mem_dump+0x81>
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1196 <mem_dump+0x86>
mov    -0x20(%rbp),%rax
movzbl (%rax),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <mem_dump+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1153 <mem_dump+0x43>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xed1(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r12),%esi
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x1,%r15
jne    1162 <mem_dump+0x52>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x2(%r12),%rbx
mov    $0x1,%ebp
lea    0xe95(%rip),%r13
jmp    119c <mem_dump+0x8c>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r12,%rbp,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbp
add    $0x2,%rbx
cmp    %rbp,%r15
je     1153 <mem_dump+0x43>
mov    %ebp,%eax
cltd
idiv   %r14d
test   %edx,%edx
jne    1180 <mem_dump+0x70>
lea    0xe53(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1180 <mem_dump+0x70>

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

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