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


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1141 <hexdump+0x31>
mov    -0x8(%rbp),%rsi
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    123a <hexdump+0x12a>
mov    -0x3c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119f <hexdump+0x8f>
cmpl   $0x0,-0x3c(%rbp)
je     118e <hexdump+0x7e>
lea    -0x30(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     11e3 <hexdump+0xd3>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    11f0 <hexdump+0xe0>
mov    $0x2e,%eax
mov    %eax,-0x40(%rbp)
jmp    11ff <hexdump+0xef>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %al,%cl
mov    -0x3c(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x3c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1150 <hexdump+0x40>
jmp    123f <hexdump+0x12f>
mov    -0x3c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     126f <hexdump+0x15f>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    123f <hexdump+0x12f>
lea    -0x30(%rbp),%rsi
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%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     1224 <hexdump+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 <hexdump+0xf4>
mov    $0x1,%ebx
lea    0xe7b(%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     11fb <hexdump+0xeb>
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    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a0 <hexdump+0x90>
mov    %r14d,%ebx
test   $0xf,%r14b
je     1224 <hexdump+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 <hexdump+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 @hexdump(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [17 x i8]
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %3
%16 = load i8*, i8** %5
store i8* %16, i8** %8
store i32 0, i32* %9
br label %17
17: ; preds = %78, %15
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = load i64, i64* %6
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %81
22: ; preds = %17
%23 = load i32, i32* %9
%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* %9
%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]* %7, 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* %9
%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** %8
%37 = load i32, i32* %9
%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** %8
%44 = load i32, i32* %9
%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** %8
%52 = load i32, i32* %9
%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 %59
58: ; preds = %50, %35
br label %66
59: ; preds = %50
%60 = load i8*, i8** %8
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
br label %66
66: ; preds = %59, %58
%67 = phi i32 [ 46, %58 ], [ %65, %59 ]
%68 = trunc i32 %67 to i8
%69 = load i32, i32* %9
%70 = srem i32 %69, 16
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %71
store i8 %68, i8* %72
%73 = load i32, i32* %9
%74 = srem i32 %73, 16
%75 = add nsw i32 %74, 1
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %76
store i8 0, i8* %77
br label %78
78: ; preds = %66
%79 = load i32, i32* %9
%80 = add nsw i32 %79, 1
store i32 %80, i32* %9
br label %17
81: ; preds = %17
br label %82
82: ; preds = %88, %81
%83 = load i32, i32* %9
%84 = srem i32 %83, 16
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %82
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %88
88: ; preds = %86
%89 = load i32, i32* %9
%90 = add nsw i32 %89, 1
store i32 %90, i32* %9
br label %82
91: ; preds = %82
%92 = getelementptr inbounds [17 x i8], [17 x i8]* %7, 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 @hexdump(i8* %0, i8* nocapture %1, i64 %2) {
%4 = alloca [17 x i8]
%5 = icmp eq i8* %0, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = 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 %8
8: ; preds = %6, %3
%9 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%10 = icmp eq i64 %2, 0
br i1 %10, label %58, label %11
11: ; preds = %8
%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* %9
%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* %9)
%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 = select i1 %43, i8 46, i8 %41
%45 = zext i32 %31 to i64
%46 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %45
store i8 %44, i8* %46
%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, %8, %22
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9)
ret void
}