#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void hexdump(const char *desc, const void *addr, size_t len, FILE *fp) {
  unsigned int i;
  unsigned char buf[17];
  const unsigned char *pc = (const unsigned char *)addr;
  if (desc != NULL)
    fprintf(fp, "%s:\n", desc);
  for (i = 0; i < (unsigned int)len; i++) {
    if ((i % 16) == 0) {
      if (i != 0)
        fprintf(fp, "  |%s|\n", buf);
      fprintf(fp, "%08x ", i);
    } else if ((i % 8) == 0) {
      fprintf(fp, " ");
    }
    fprintf(fp, " %02x", pc[i]);
    if ((pc[i] < 0x20) || (pc[i] > 0x7e)) {
      buf[i % 16] = '.';
    } else {
      buf[i % 16] = pc[i];
    }
    buf[(i % 16) + 1] = '\0';
  }
  if (i % 16 <= 8 && i % 16 != 0)
    fprintf(fp, " ");
  while ((i % 16) != 0) {
    fprintf(fp, "   ");
    i++;
  }
  fprintf(fp, "  |%s|\n", buf);
}


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    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1151 <hexdump+0x41>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xeb6(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
jae    1261 <hexdump+0x151>
mov    -0x24(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11b0 <hexdump+0xa0>
cmpl   $0x0,-0x24(%rbp)
je     1196 <hexdump+0x86>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11d6 <hexdump+0xc6>
mov    -0x24(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    11d1 <hexdump+0xc1>
mov    -0x20(%rbp),%rdi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11d6 <hexdump+0xc6>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    -0x24(%rbp),%ecx
movzbl (%rax,%rcx,1),%edx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x48(%rbp),%rax
mov    -0x24(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     121b <hexdump+0x10b>
mov    -0x48(%rbp),%rax
mov    -0x24(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    122d <hexdump+0x11d>
mov    -0x24(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
movb   $0x2e,-0x40(%rbp,%rax,1)
jmp    1243 <hexdump+0x133>
mov    -0x48(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x24(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
and    $0xf,%eax
add    $0x1,%eax
mov    %eax,%eax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1158 <hexdump+0x48>
mov    -0x24(%rbp),%eax
and    $0xf,%eax
cmp    $0x8,%eax
ja     1291 <hexdump+0x181>
mov    -0x24(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     1291 <hexdump+0x181>
mov    -0x20(%rbp),%rdi
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1296 <hexdump+0x186>
mov    -0x24(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     12c5 <hexdump+0x1b5>
mov    -0x20(%rbp),%rdi
lea    0xd69(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1296 <hexdump+0x186>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@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    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
test   %rdi,%rdi
je     1160 <hexdump+0x30>
mov    %rdi,%rdx
lea    0xeaa(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r12d,%r12d
je     12b1 <hexdump+0x181>
mov    %r12d,%r13d
lea    0xe9a(%rip),%rsi
mov    %r14,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r15),%edx
lea    0xe89(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r15),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
mov    %al,(%rsp)
movb   $0x0,0x1(%rsp)
mov    $0x1,%ebx
cmp    $0x1,%r13
je     1265 <hexdump+0x135>
mov    $0x1,%ebx
jmp    1231 <hexdump+0x101>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
lea    0xe2b(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
lea    0xe1f(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r15,%rbx,1),%edx
mov    %r14,%rdi
lea    0xe0d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r15,%rbx,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
mov    %al,(%rsp,%rbp,1)
movb   $0x0,0x1(%rsp,%rbp,1)
add    $0x1,%rbx
cmp    %rbx,%r13
je     124e <hexdump+0x11e>
mov    %rbx,%rbp
and    $0xf,%rbp
je     11d0 <hexdump+0xa0>
test   $0x7,%bl
jne    11f7 <hexdump+0xc7>
mov    $0x20,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    11f7 <hexdump+0xc7>
mov    %r12d,%eax
and    $0xf,%eax
lea    -0x9(%rax),%ecx
cmp    $0xfffffff8,%ecx
jae    1262 <hexdump+0x132>
test   %eax,%eax
jne    1275 <hexdump+0x145>
jmp    12b1 <hexdump+0x181>
mov    %r12d,%ebx
mov    $0x20,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %ebx,%r12d
add    $0x1,%r12d
lea    0xd99(%rip),%rbx
mov    %r12d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rdi
mov    %r14,%rcx
call   1050 <fwrite@plt>
add    $0x1,%ebp
test   $0xf,%r12b
mov    %ebp,%r12d
jne    1290 <hexdump+0x160>
lea    0xd4d(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fprintf@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 = [8 x i8] c" |%s|\0A\00"
@.str.2 = [6 x i8] c"%08x \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [6 x i8] c" %02x\00"
@.str.5 = [4 x i8] c" \00"
define void @hexdump(i8* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [17 x i8]
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%12 = load i8*, i8** %6
store i8* %12, i8** %11
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %4
%16 = load i32*, i32** %8
%17 = load i8*, i8** %5
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15, %4
store i32 0, i32* %9
br label %20
20: ; preds = %93, %19
%21 = load i32, i32* %9
%22 = load i64, i64* %7
%23 = trunc i64 %22 to i32
%24 = icmp ult i32 %21, %23
br i1 %24, label %25, label %96
25: ; preds = %20
%26 = load i32, i32* %9
%27 = urem i32 %26, 16
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %25
%30 = load i32, i32* %9
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32*, i32** %8
%34 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %32, %29
%37 = load i32*, i32** %8
%38 = load i32, i32* %9
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %48
40: ; preds = %25
%41 = load i32, i32* %9
%42 = urem i32 %41, 8
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i32*, i32** %8
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %44, %40
br label %48
48: ; preds = %47, %36
%49 = load i32*, i32** %8
%50 = load i8*, i8** %11
%51 = load i32, i32* %9
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %55)
%57 = load i8*, i8** %11
%58 = load i32, i32* %9
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp slt i32 %62, 32
br i1 %63, label %72, label %64
64: ; preds = %48
%65 = load i8*, i8** %11
%66 = load i32, i32* %9
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = icmp sgt i32 %70, 126
br i1 %71, label %72, label %77
72: ; preds = %64, %48
%73 = load i32, i32* %9
%74 = urem i32 %73, 16
%75 = zext i32 %74 to i64
%76 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 %75
store i8 46, i8* %76
br label %87
77: ; preds = %64
%78 = load i8*, i8** %11
%79 = load i32, i32* %9
%80 = zext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = load i8, i8* %81
%83 = load i32, i32* %9
%84 = urem i32 %83, 16
%85 = zext i32 %84 to i64
%86 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 %85
store i8 %82, i8* %86
br label %87
87: ; preds = %77, %72
%88 = load i32, i32* %9
%89 = urem i32 %88, 16
%90 = add i32 %89, 1
%91 = zext i32 %90 to i64
%92 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 %91
store i8 0, i8* %92
br label %93
93: ; preds = %87
%94 = load i32, i32* %9
%95 = add i32 %94, 1
store i32 %95, i32* %9
br label %20
96: ; preds = %20
%97 = load i32, i32* %9
%98 = urem i32 %97, 16
%99 = icmp ule i32 %98, 8
br i1 %99, label %100, label %107
100: ; preds = %96
%101 = load i32, i32* %9
%102 = urem i32 %101, 16
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %107
104: ; preds = %100
%105 = load i32*, i32** %8
%106 = call i32 (i32*, i8*, ...) @fprintf(i32* %105, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %107
107: ; preds = %104, %100, %96
br label %108
108: ; preds = %112, %107
%109 = load i32, i32* %9
%110 = urem i32 %109, 16
%111 = icmp ne i32 %110, 0
br i1 %111, label %112, label %117
112: ; preds = %108
%113 = load i32*, i32** %8
%114 = call i32 (i32*, i8*, ...) @fprintf(i32* %113, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%115 = load i32, i32* %9
%116 = add i32 %115, 1
store i32 %116, i32* %9
br label %108
117: ; preds = %108
%118 = load i32*, i32** %8
%119 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%120 = call i32 (i32*, i8*, ...) @fprintf(i32* %118, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %119)
ret void
}

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