#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(const char *desc, const void *addr, const size_t len) {
  int i;
  unsigned char buff[17];
  unsigned char *pc = (unsigned char *)addr;
  if (desc != NULL)
    printf("%s:\n", desc);
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0) {
      if (i != 0)
        printf("  %s\n", buff);
      printf("  %04x ", i);
    }
    printf(" %02x", pc[i]);
    if ((pc[i] < 0x20) || (pc[i] > 0x7e))
      buff[i % 16] = '.';
    else
      buff[i % 16] = pc[i];
    buff[(i % 16) + 1] = '\0';
  }
  while ((i % 16) != 0) {
    printf("   ");
    i++;
  }
  printf("  %s\n", buff);
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1149 <hex_dump+0x39>
mov    -0x8(%rbp),%rsi
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    123c <hex_dump+0x12c>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119f <hex_dump+0x8f>
cmpl   $0x0,-0x1c(%rbp)
je     118e <hex_dump+0x7e>
lea    -0x30(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     11e3 <hex_dump+0xd3>
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    11fb <hex_dump+0xeb>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    1218 <hex_dump+0x108>
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x1c(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1150 <hex_dump+0x40>
jmp    1241 <hex_dump+0x131>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1271 <hex_dump+0x161>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1241 <hex_dump+0x131>
lea    -0x30(%rbp),%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
test   %rdi,%rdi
je     113a <hex_dump+0x2a>
mov    %rdi,%rsi
lea    0xecd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r14,%r14
je     1224 <hex_dump+0x114>
lea    0xec1(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r15),%esi
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r15),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%r13d
cmovb  %r13d,%eax
mov    %al,(%rsp)
movb   $0x0,0x1(%rsp)
mov    $0x1,%ebx
cmp    $0x1,%r14
je     1204 <hex_dump+0xf4>
mov    $0x1,%ebx
lea    0xe7b(%rip),%r12
jmp    11cf <hex_dump+0xbf>
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r15,%rbx,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
cmovb  %r13d,%eax
mov    %al,(%rsp,%rbp,1)
movb   $0x0,0x1(%rsp,%rbp,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     11fb <hex_dump+0xeb>
mov    %rbx,%rbp
and    $0xf,%rbp
jne    11a0 <hex_dump+0x90>
lea    0xe26(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe1b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a0 <hex_dump+0x90>
mov    %r14d,%ebx
test   $0xf,%r14b
je     1224 <hex_dump+0x114>
add    $0x1,%ebx
lea    0xe0b(%rip),%r14
mov    %ebx,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
test   $0xf,%bl
mov    %ebp,%ebx
jne    1210 <hex_dump+0x100>
lea    0xdda(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s:\0A\00"
@.str.1 = [6 x i8] c" %s\0A\00"
@.str.2 = [8 x i8] c" %04x \00"
@.str.3 = [6 x i8] c" %02x\00"
@.str.4 = [4 x i8] c" \00"
define void @hex_dump(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca [17 x i8]
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %9
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %3
store i32 0, i32* %7
br label %17
17: ; preds = %79, %16
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = load i64, i64* %6
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %82
22: ; preds = %17
%23 = load i32, i32* %7
%24 = srem i32 %23, 16
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %26
%33 = load i32, i32* %7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %22
%36 = load i8*, i8** %9
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i8*, i8** %9
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp slt i32 %48, 32
br i1 %49, label %58, label %50
50: ; preds = %35
%51 = load i8*, i8** %9
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = icmp sgt i32 %56, 126
br i1 %57, label %58, label %63
58: ; preds = %50, %35
%59 = load i32, i32* %7
%60 = srem i32 %59, 16
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %61
store i8 46, i8* %62
br label %73
63: ; preds = %50
%64 = load i8*, i8** %9
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = load i32, i32* %7
%70 = srem i32 %69, 16
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %71
store i8 %68, i8* %72
br label %73
73: ; preds = %63, %58
%74 = load i32, i32* %7
%75 = srem i32 %74, 16
%76 = add nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %77
store i8 0, i8* %78
br label %79
79: ; preds = %73
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
br label %17
82: ; preds = %17
br label %83
83: ; preds = %87, %82
%84 = load i32, i32* %7
%85 = srem i32 %84, 16
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %91
87: ; preds = %83
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%89 = load i32, i32* %7
%90 = add nsw i32 %89, 1
store i32 %90, i32* %7
br label %83
91: ; preds = %83
%92 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %92)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s:\0A\00"
@.str.1 = [6 x i8] c" %s\0A\00"
@.str.2 = [8 x i8] c" %04x \00"
@.str.3 = [6 x i8] c" %02x\00"
@.str.4 = [4 x i8] c" \00"
define void @hex_dump(i8* %0, i8* nocapture %1, i64 %2) {
%4 = alloca [17 x i8]
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %3
%10 = icmp eq i64 %2, 0
br i1 %10, label %58, label %11
11: ; preds = %9
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 0)
%13 = load i8, i8* %1
%14 = zext i8 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i8, i8* %1
%17 = add i8 %16, -127
%18 = icmp ult i8 %17, -95
%19 = select i1 %18, i8 46, i8 %16
store i8 %19, i8* %5
%20 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 1
store i8 0, i8* %20
%21 = icmp eq i64 %2, 1
br i1 %21, label %26, label %28
22: ; preds = %36
%23 = trunc i64 %2 to i32
%24 = and i32 %23, 15
%25 = icmp eq i32 %24, 0
br i1 %25, label %58, label %26
26: ; preds = %11, %22
%27 = phi i32 [ 1, %11 ], [ %23, %22 ]
br label %52
28: ; preds = %11, %36
%29 = phi i64 [ %50, %36 ], [ 1, %11 ]
%30 = trunc i64 %29 to i32
%31 = and i32 %30, 15
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %36
36: ; preds = %33, %28
%37 = getelementptr inbounds i8, i8* %1, i64 %29
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i8, i8* %37
%42 = add i8 %41, -127
%43 = icmp ult i8 %42, -95
%44 = zext i32 %31 to i64
%45 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %44
%46 = select i1 %43, i8 46, i8 %41
store i8 %46, i8* %45
%47 = add nuw nsw i32 %31, 1
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %48
store i8 0, i8* %49
%50 = add nuw i64 %29, 1
%51 = icmp eq i64 %50, %2
br i1 %51, label %22, label %28
52: ; preds = %26, %52
%53 = phi i32 [ %55, %52 ], [ %27, %26 ]
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%55 = add nuw nsw i32 %53, 1
%56 = and i32 %55, 15
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %52
58: ; preds = %52, %9, %22
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5)
ret void
}