#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(char *start, char *mem, char *memend) {
  char *cp;
  int i;
  for (cp = mem; cp < memend; cp += 16) {
    printf("%04lx: ", cp - start);
    for (i = 0; i < 16 && cp + i < memend; i++) {
      printf("%02x ", cp[i] & 0xff);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<dump_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11db <dump_mem+0xcb>
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rax
sub    %rax,%rsi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0x24(%rbp)
mov    %al,-0x25(%rbp)
jge    117e <dump_mem+0x6e>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
cmp    -0x18(%rbp),%rax
setb   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    118e <dump_mem+0x7e>
jmp    11bc <dump_mem+0xac>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115a <dump_mem+0x4a>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <dump_mem+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %rdx,%rsi
jae    11a7 <dump_mem+0x87>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xec0(%rip),%r12
lea    0xec1(%rip),%r13
jmp    1163 <dump_mem+0x43>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rbx
cmp    %r14,%rbx
jae    11a7 <dump_mem+0x87>
mov    %rbx,%rsi
sub    %r15,%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx,%rbp,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xe,%rbp
ja     1150 <dump_mem+0x30>
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    %r14,%rax
jb     1180 <dump_mem+0x60>
jmp    1150 <dump_mem+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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