#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void hexdump(void *ptr, void *end_ptr) {
  int total = 0;
  while (ptr < end_ptr) {
    fprintf(stderr, "%02x", (int)*(unsigned char *)ptr);
    ptr++;
    total++;
    if (total == 16) {
      fprintf(stderr, "\n");
      total = 0;
    }
  }
  if (total) {
    fprintf(stderr, "\n");
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1195 <hexdump+0x85>
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movzbl (%rax),%edx
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jne    1190 <hexdump+0x80>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
jmp    1127 <hexdump+0x17>
cmpl   $0x0,-0x14(%rbp)
je     11b6 <hexdump+0xa6>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %rsi,%rdi
jae    11b2 <hexdump+0xa2>
mov    %rsi,%rbx
mov    %rdi,%r14
sub    %rdi,%rbx
mov    0x2eac(%rip),%r13
lea    0xec5(%rip),%r15
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    1159 <hexdump+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     118d <hexdump+0x7d>
mov    0x0(%r13),%edi
movzbl (%r14,%rbp,1),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r12d
cmp    $0x10,%r12d
jne    1150 <hexdump+0x40>
mov    0x0(%r13),%edi
xor    %r12d,%r12d
lea    0xe81(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1150 <hexdump+0x40>
test   %r12d,%r12d
je     11b2 <hexdump+0xa2>
mov    0x0(%r13),%edi
lea    0xe68(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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