#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 hexdump(const char *desc, const void *addr, size_t len) {
  size_t i;
  unsigned char buff[17];
  const unsigned char *pc = 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("  %04zx ", 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):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1149 <hexdump+0x39>
mov    -0x8(%rbp),%rsi
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    122b <hexdump+0x11b>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11a0 <hexdump+0x90>
cmpq   $0x0,-0x20(%rbp)
je     118e <hexdump+0x7e>
lea    -0x40(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     11e4 <hexdump+0xd4>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    11f6 <hexdump+0xe6>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
movb   $0x2e,-0x40(%rbp,%rax,1)
jmp    120d <hexdump+0xfd>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
and    $0xf,%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
and    $0xf,%rax
movb   $0x0,-0x3f(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1151 <hexdump+0x41>
jmp    1230 <hexdump+0x120>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     1261 <hexdump+0x151>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1230 <hexdump+0x120>
lea    -0x40(%rbp),%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
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 <hexdump+0x2a>
mov    %rdi,%rsi
lea    0xecd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r14,%r14
je     1236 <hexdump+0x126>
lea    0xec1(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r15),%esi
lea    0xeb6(%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     1205 <hexdump+0xf5>
mov    $0x1,%ebx
lea    0xe7c(%rip),%r12
jmp    11cf <hexdump+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     11fc <hexdump+0xec>
mov    %rbx,%rbp
and    $0xf,%rbp
jne    11a0 <hexdump+0x90>
lea    0xe26(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe1b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a0 <hexdump+0x90>
mov    %r14,%rbx
test   $0xf,%r14b
je     1236 <hexdump+0x126>
add    $0x1,%rbx
lea    0xe0a(%rip),%r14
mov    %rbx,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbp
test   $0xf,%bl
mov    %rbp,%rbx
jne    1220 <hexdump+0x110>
lea    0xdc8(%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 = [9 x i8] c" %04zx \00"
@.str.3 = [6 x i8] c" %02x\00"
@.str.4 = [4 x i8] c" \00"
define void @hexdump(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%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 i64 0, i64* %7
br label %17
17: ; preds = %71, %16
%18 = load i64, i64* %7
%19 = load i64, i64* %6
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %74
21: ; preds = %17
%22 = load i64, i64* %7
%23 = urem i64 %22, 16
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = load i64, i64* %7
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %25
%32 = load i64, i64* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64 %32)
br label %34
34: ; preds = %31, %21
%35 = load i8*, i8** %9
%36 = load i64, i64* %7
%37 = getelementptr inbounds i8, i8* %35, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i8*, i8** %9
%42 = load i64, i64* %7
%43 = getelementptr inbounds i8, i8* %41, i64 %42
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp slt i32 %45, 32
br i1 %46, label %54, label %47
47: ; preds = %34
%48 = load i8*, i8** %9
%49 = load i64, i64* %7
%50 = getelementptr inbounds i8, i8* %48, i64 %49
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = icmp sgt i32 %52, 126
br i1 %53, label %54, label %58
54: ; preds = %47, %34
%55 = load i64, i64* %7
%56 = urem i64 %55, 16
%57 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %56
store i8 46, i8* %57
br label %66
58: ; preds = %47
%59 = load i8*, i8** %9
%60 = load i64, i64* %7
%61 = getelementptr inbounds i8, i8* %59, i64 %60
%62 = load i8, i8* %61
%63 = load i64, i64* %7
%64 = urem i64 %63, 16
%65 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %64
store i8 %62, i8* %65
br label %66
66: ; preds = %58, %54
%67 = load i64, i64* %7
%68 = urem i64 %67, 16
%69 = add i64 %68, 1
%70 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %69
store i8 0, i8* %70
br label %71
71: ; preds = %66
%72 = load i64, i64* %7
%73 = add i64 %72, 1
store i64 %73, i64* %7
br label %17
74: ; preds = %17
br label %75
75: ; preds = %79, %74
%76 = load i64, i64* %7
%77 = urem i64 %76, 16
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %75
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%81 = load i64, i64* %7
%82 = add i64 %81, 1
store i64 %82, i64* %7
br label %75
83: ; preds = %75
%84 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %84)
ret void
}

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