#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(char *desc, void *addr, size_t len, FILE *fp) {
  unsigned int i;
  unsigned char buff[17];
  unsigned char *pc = (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", buff);
      fprintf(fp, "  %04x ", i);
    } else if ((i % 8) == 0) {
      fprintf(fp, " ");
    }
    fprintf(fp, " %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) {
    fprintf(fp, "   ");
    i++;
  }
  fprintf(fp, "  %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    %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    0xe67(%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>
jmp    1266 <hexdump+0x156>
mov    -0x24(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     1295 <hexdump+0x185>
mov    -0x20(%rbp),%rdi
lea    0xd99(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1266 <hexdump+0x156>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xd61(%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    $0x28,%rsp
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rsi,%r15
test   %rdi,%rdi
je     1160 <hexdump+0x30>
mov    %rdi,%rdx
lea    0xeaa(%rip),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebp,%ebp
je     128f <hexdump+0x15f>
mov    %ebp,%r13d
lea    0xe99(%rip),%rsi
mov    %r12,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r15),%edx
lea    0xe8a(%rip),%rsi
mov    %r12,%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     1257 <hexdump+0x127>
mov    %rbp,0x20(%rsp)
mov    $0x1,%ebx
lea    0xe46(%rip),%rbp
jmp    122f <hexdump+0xff>
nop
mov    %r12,%rdi
lea    0xe2b(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12,%rdi
lea    0xe1d(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r15,%rbx,1),%edx
mov    %r12,%rdi
mov    %rbp,%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,%r14,1)
movb   $0x0,0x1(%rsp,%r14,1)
add    $0x1,%rbx
cmp    %rbx,%r13
je     124c <hexdump+0x11c>
mov    %rbx,%r14
and    $0xf,%r14
je     11d0 <hexdump+0xa0>
test   $0x7,%bl
jne    11f7 <hexdump+0xc7>
mov    $0x20,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
jmp    11f7 <hexdump+0xc7>
mov    0x20(%rsp),%rax
mov    %eax,%ebx
test   $0xf,%al
je     128f <hexdump+0x15f>
add    $0x1,%ebx
lea    0xdb8(%rip),%r14
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %r12,%rcx
call   1050 <fwrite@plt>
add    $0x1,%ebp
test   $0xf,%bl
mov    %ebp,%ebx
jne    1270 <hexdump+0x140>
lea    0xd6f(%rip),%rsi
mov    %rsp,%rdx
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x28,%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 = [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 ([6 x i8], [6 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 ([8 x i8], [8 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
br label %97
97: ; preds = %101, %96
%98 = load i32, i32* %9
%99 = urem i32 %98, 16
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %106
101: ; preds = %97
%102 = load i32*, i32** %8
%103 = call i32 (i32*, i8*, ...) @fprintf(i32* %102, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%104 = load i32, i32* %9
%105 = add i32 %104, 1
store i32 %105, i32* %9
br label %97
106: ; preds = %97
%107 = load i32*, i32** %8
%108 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%109 = call i32 (i32*, i8*, ...) @fprintf(i32* %107, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %108)
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.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 %66, label %13
13: ; preds = %10
%14 = and i64 %2, 4294967295
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 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 %29, label %31
25: ; preds = %44
%26 = trunc i64 %2 to i32
%27 = and i32 %26, 15
%28 = icmp eq i32 %27, 0
br i1 %28, label %66, label %29
29: ; preds = %13, %25
%30 = phi i32 [ 1, %13 ], [ %26, %25 ]
br label %60
31: ; preds = %13, %44
%32 = phi i64 [ %58, %44 ], [ 1, %13 ]
%33 = trunc i64 %32 to i32
%34 = and i32 %33, 15
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %44
39: ; preds = %31
%40 = and i32 %33, 7
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @fputc(i32 32, i32* %3)
br label %44
44: ; preds = %39, %42, %36
%45 = getelementptr inbounds i8, i8* %1, i64 %32
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = load i8, i8* %45
%50 = add i8 %49, -127
%51 = icmp ult i8 %50, -95
%52 = zext i32 %34 to i64
%53 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %52
%54 = select i1 %51, i8 46, i8 %49
store i8 %54, i8* %53
%55 = add nuw nsw i32 %34, 1
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %56
store i8 0, i8* %57
%58 = add nuw nsw i64 %32, 1
%59 = icmp eq i64 %58, %14
br i1 %59, label %25, label %31
60: ; preds = %29, %60
%61 = phi i32 [ %63, %60 ], [ %30, %29 ]
%62 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64 3, i64 1, i32* %3)
%63 = add i32 %61, 1
%64 = and i32 %63, 15
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %60
66: ; preds = %60, %10, %25
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %6)
ret void
}