#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 *info, char *str, int len) {
  int i = 0;
  if (str == NULL || len == 0)
    return;
  printf("dump %s, len: %d; data:\n", info, len);
  for (i = 0; i < len; i++) {
    if (((char *)str + i) == NULL)
      break;
    printf("%02x ", *((char *)str + i));
    if ((i + 1) % 16 == 0)
      printf("\n");
  }
  printf("\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)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     113f <hex_dump+0x2f>
cmpl   $0x0,-0x14(%rbp)
jne    1144 <hex_dump+0x34>
jmp    11e6 <hex_dump+0xd6>
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d8 <hex_dump+0xc8>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
cmp    $0x0,%rax
jne    1186 <hex_dump+0x76>
jmp    11d8 <hex_dump+0xc8>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c5 <hex_dump+0xb5>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <hex_dump+0xba>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1160 <hex_dump+0x50>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
test   %rsi,%rsi
je     1193 <hex_dump+0x73>
mov    %edx,%ebp
test   %edx,%edx
je     1193 <hex_dump+0x73>
mov    %rdi,%rsi
lea    0xec1(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    119e <hex_dump+0x7e>
mov    %ebp,%ebp
neg    %rbp
mov    $0x1,%ebx
lea    0xebc(%rip),%r14
jmp    1172 <hex_dump+0x52>
nop
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     119e <hex_dump+0x7e>
movsbl -0x1(%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0xf,%bl
jne    1160 <hex_dump+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <hex_dump+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"dump %s, len: %d; data:\0A\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, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %3
br label %49
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
store i32 0, i32* %7
br label %18
18: ; preds = %44, %14
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %47
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %22
br label %47
29: ; preds = %22
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
%39 = srem i32 %38, 16
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %29
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %29
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %18
47: ; preds = %28, %18
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %49
49: ; preds = %47, %13
ret void
}

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