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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void hex_dump(const char *msg, const char *data, size_t len, FILE *log) {
  u_int i = 0;
  assert(data && (len > (size_t)0) && log);
  if (msg)
    (void)fprintf(log, "%s: ", msg);
  for (i = 0; i < len; ++i)
    (void)fprintf(log, "%02x ", data[i] & 0xFF);
  (void)fputs("\n", log);
  return;
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x29(%rbp)
je     117b <hex_dump+0x4b>
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x29(%rbp)
jbe    117b <hex_dump+0x4b>
cmpq   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
je     11a9 <hex_dump+0x79>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11f4 <hex_dump+0xc4>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11b1 <hex_dump+0x81>
mov    -0x20(%rbp),%rsi
lea    0xe0c(%rip),%rdi
call   1030 <fputs@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
test   %rsi,%rsi
setne  %al
test   %rdx,%rdx
setne  %cl
and    %al,%cl
test   %r14,%r14
setne  %al
and    %cl,%al
movzbl %al,%edi
call   1040 <assert@plt>
test   %r12,%r12
je     117c <hex_dump+0x4c>
lea    0xe91(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r13,%r13
je     11ab <hex_dump+0x7b>
lea    0xe7d(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1190 <hex_dump+0x60>
mov    $0xa,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <fputc@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s: \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @hex_dump(i8* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
store i64 0, i64* %9
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %4
%13 = load i64, i64* %7
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32*, i32** %8
%17 = icmp ne i32* %16, null
br label %18
18: ; preds = %15, %12, %4
%19 = phi i1 [ false, %12 ], [ false, %4 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32*, i32** %8
%26 = load i8*, i8** %5
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %24, %18
store i64 0, i64* %9
br label %29
29: ; preds = %42, %28
%30 = load i64, i64* %9
%31 = load i64, i64* %7
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i32*, i32** %8
%35 = load i8*, i8** %6
%36 = load i64, i64* %9
%37 = getelementptr inbounds i8, i8* %35, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = and i32 %39, 255
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, 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 i64, i64* %9
%44 = add i64 %43, 1
store i64 %44, i64* %9
br label %29
45: ; preds = %29
%46 = load i32*, i32** %8
%47 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32* %46)
ret void
}

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