#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 hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen) {
  unsigned char *pt;
  int x;
  pt = pSrcBufVA;
  printf("%s: %p, len = %d\n\r", str, pSrcBufVA, SrcBufLen);
  for (x = 0; x < SrcBufLen; x++) {
    if (x % 16 == 0) {
      printf("0x%04x : ", x);
    }
    printf("%02x ", ((unsigned char)pt[x]));
    if (x % 16 == 15) {
      printf("\n\r");
    }
  }
  printf("\n\r");
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11cb <hex_dump+0xbb>
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117c <hex_dump+0x6c>
mov    -0x24(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    11b8 <hex_dump+0xa8>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bd <hex_dump+0xad>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114b <hex_dump+0x3b>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r13
mov    %rdi,%rsi
lea    0xed6(%rip),%rdi
mov    %r13,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebx,%ebx
je     11a4 <hex_dump+0x94>
mov    %ebx,%ebp
lea    0xed0(%rip),%r14
lea    0xed3(%rip),%r15
xor    %ebx,%ebx
jmp    1175 <hex_dump+0x65>
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x0(%r13,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11a4 <hex_dump+0x94>
mov    %ebx,%r12d
and    $0xf,%r12d
je     1150 <hex_dump+0x40>
movzbl 0x0(%r13,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0xf,%r12d
jne    116c <hex_dump+0x5c>
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    116c <hex_dump+0x5c>
lea    0xe65(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

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

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