#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(void *addr, int len) {
  int i;
  unsigned char buff[17];
  unsigned char *pc = (unsigned char *)addr;
  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    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1218 <hex_dump+0x108>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117b <hex_dump+0x6b>
cmpl   $0x0,-0x10(%rbp)
je     116a <hex_dump+0x5a>
lea    -0x30(%rbp),%rsi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     11bf <hex_dump+0xaf>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    11d7 <hex_dump+0xc7>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    11f4 <hex_dump+0xe4>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <hex_dump+0x1e>
jmp    121d <hex_dump+0x10d>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     124d <hex_dump+0x13d>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    121d <hex_dump+0x10d>
lea    -0x30(%rbp),%rsi
lea    0xda8(%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    $0x28,%rsp
test   %esi,%esi
jle    1226 <hex_dump+0x116>
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xed4(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%rbx),%esi
lea    0xec9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%rbx),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%r12d
cmovb  %r12d,%eax
mov    %al,0x10(%rsp)
movb   $0x0,0x11(%rsp)
mov    $0x1,%r15d
cmp    $0x1,%ebp
je     11f5 <hex_dump+0xe5>
mov    %ebp,0xc(%rsp)
mov    %ebp,%r15d
mov    $0x1,%ebp
lea    0xe84(%rip),%r14
jmp    11c0 <hex_dump+0xb0>
nopl   0x0(%rax)
movzbl (%rbx,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%rbx,%rbp,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
cmovb  %r12d,%eax
mov    %al,0x10(%rsp,%r13,1)
movb   $0x0,0x11(%rsp,%r13,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     11ee <hex_dump+0xde>
mov    %rbp,%r13
and    $0xf,%r13
jne    1190 <hex_dump+0x80>
lea    0xe30(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe23(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1190 <hex_dump+0x80>
testb  $0xf,0xc(%rsp)
je     1226 <hex_dump+0x116>
add    $0x1,%r15d
lea    0xe14(%rip),%rbx
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
test   $0xf,%r15b
mov    %ebp,%r15d
jne    1210 <hex_dump+0x100>
lea    0xdd3(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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