#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;
  unsigned char *bptr = (unsigned char *)ptr;
  while (bptr < (unsigned char *)end_ptr) {
    fprintf(stderr, "%02x", (int)*bptr);
    bptr++;
    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
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    119d <hexdump+0x8d>
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
movzbl (%rax),%edx
lea    0xeac(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jne    1198 <hexdump+0x88>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
jmp    112f <hexdump+0x1f>
cmpl   $0x0,-0x14(%rbp)
je     11be <hexdump+0xae>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%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
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
store i8* %7, i8** %6
br label %8
8: ; preds = %27, %2
%9 = load i8*, i8** %6
%10 = load i8*, i8** %4
%11 = icmp ult i8* %9, %10
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %6
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 16
br i1 %23, label %24, label %27
24: ; preds = %12
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %27
27: ; preds = %24, %12
br label %8
28: ; preds = %8
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31, %28
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 i8* [ %16, %22 ], [ %0, %4 ]
%11 = phi i32 [ %23, %22 ], [ 0, %4 ]
%12 = load i32, i32* @stderr
%13 = load i8, i8* %10
%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* %10, i64 1
%17 = add nsw i32 %11, 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
}