#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void hex_dump(FILE *outfp, char *p, int len) {
  int i;
  if (NULL == p)
    fprintf(outfp, "NULL");
  for (i = 0; i < len; i++) {
    if (i % 16 == 0)
      fprintf(outfp, "\n%08X: ", (int)&p[i]);
    fprintf(outfp, "%02X ", p[i]);
  }
  fprintf(outfp, "\n");
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1141 <hex_dump+0x31>
mov    -0x8(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b3 <hex_dump+0xa3>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1187 <hex_dump+0x77>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %eax,%edx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1148 <hex_dump+0x38>
mov    -0x8(%rbp),%rdi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%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,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     114e <hex_dump+0x1e>
test   %ebp,%ebp
jg     116b <hex_dump+0x3b>
jmp    11b2 <hex_dump+0x82>
lea    0xeab(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
test   %ebp,%ebp
jle    11b2 <hex_dump+0x82>
mov    %ebp,%r13d
lea    0xe90(%rip),%r15
lea    0xe91(%rip),%r12
xor    %ebp,%ebp
jmp    119a <hex_dump+0x6a>
movsbl (%rbx,%rbp,1),%edx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     11b2 <hex_dump+0x82>
test   $0xf,%bpl
jne    1180 <hex_dump+0x50>
lea    (%rbx,%rbp,1),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1180 <hex_dump+0x50>
mov    $0xa,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"NULL\00"
@.str.1 = [8 x i8] c"\0A%08X: \00"
@.str.2 = [6 x i8] c"%02X \00"
define void @hex_dump(i32* nocapture %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %7
7: ; preds = %5, %3
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %27
9: ; preds = %7
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %20
%12 = phi i64 [ 0, %9 ], [ %25, %20 ]
%13 = and i64 %12, 15
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = getelementptr inbounds i8, i8* %1, i64 %12
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %15, %11
%21 = getelementptr inbounds i8, i8* %1, i64 %12
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %12, 1
%26 = icmp eq i64 %25, %10
br i1 %26, label %27, label %11
27: ; preds = %20, %7
%28 = tail call i32 @fputc(i32 10, i32* %0)
ret void
}