#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*/ print_byte(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char);
void mem_dump(const char *addr, const size_t size) {
  const char *const end_addr = addr + size;
  size_t printed = 0;
  while (addr < end_addr) {
    print_byte(*addr++);
    printf("%c", (++printed % 24 ? ' ' : '\n'));
  }
}


x86 assembly (clang, -O0):
<mem_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a4 <mem_dump+0x84>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <print_byte@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    $0x18,%ecx
xor    %edx,%edx
div    %rcx
mov    $0xa,%eax
mov    $0x20,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
lea    0xe69(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
jmp    1144 <mem_dump+0x24>
add    $0x20,%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
jle    119d <mem_dump+0x7d>
mov    %rsi,%r14
mov    %rdi,%rbx
add    %rdi,%r14
mov    $0xffffffffffffffff,%r13
mov    $0x1,%r15d
lea    0xeb3(%rip),%r12
nopl   (%rax)
mov    %r15,%rax
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mul    %rcx
shr    $0x4,%rdx
lea    (%rdx,%rdx,2),%rbp
shl    $0x3,%rbp
movsbl (%rbx),%edi
add    $0x1,%rbx
call   1030 <print_byte@plt>
add    %r13,%rbp
mov    $0x20,%esi
mov    $0xa,%eax
cmove  %eax,%esi
mov    %r12,%rdi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%r13
add    $0x1,%r15
cmp    %r14,%rbx
jb     1150 <mem_dump+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @mem_dump(i8* %0, i64 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 %1
%4 = icmp sgt i64 %1, 0
br i1 %4, label %5, label %18
5: ; preds = %2, %5
%6 = phi i64 [ %12, %5 ], [ 0, %2 ]
%7 = phi i8* [ %8, %5 ], [ %0, %2 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
%11 = tail call i32 @print_byte(i32 %10)
%12 = add i64 %6, 1
%13 = urem i64 %12, 24
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8 10, i8 32
%16 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %15)
%17 = icmp ult i8* %8, %3
br i1 %17, label %5, label %18
18: ; preds = %5, %2
ret void
}