#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*/ asciishow(unsigned char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void hexdump(unsigned char *buf, int len, char *prefix) {
  int i, j;
  fprintf(stderr, "\n%s", prefix);
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0) {
      fprintf(stderr, "0x%04x: ", i);
    }
    fprintf(stderr, "%02x ", buf[i]);
    if ((i % 16) == 15) {
      asciishow(buf + i - 15, 16);
      if (i != (len - 1))
        fprintf(stderr, "\n%s", prefix);
    }
  }
  for (j = (i % 16); j < 16; j++)
    fprintf(stderr, "   ");
  asciishow(buf + i - (i % 16), (i % 16));
  fprintf(stderr, "\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xeb9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1223 <hexdump+0x103>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118f <hexdump+0x6f>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    1210 <hexdump+0xf0>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffff1,%rdi
mov    $0x10,%esi
call   1030 <asciishow@plt>
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     120b <hexdump+0xeb>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1210 <hexdump+0xf0>
jmp    1215 <hexdump+0xf5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <hexdump+0x35>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
cmpl   $0x10,-0x20(%rbp)
jge    1260 <hexdump+0x140>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1231 <hexdump+0x111>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
call   1030 <asciishow@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd74(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x20,%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    %esi,%ebx
mov    %rdi,%r13
mov    0x2ea6(%rip),%r12
mov    (%r12),%edi
lea    0xebb(%rip),%rsi
xor    %r15d,%r15d
mov    %rdx,0x10(%rsp)
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebx,%ebx
jle    120a <hexdump+0xea>
lea    -0x1(%rbx),%eax
mov    %rax,0x20(%rsp)
mov    %rbx,0x8(%rsp)
mov    %ebx,%r15d
lea    -0xf(%r13),%rax
mov    %rax,0x18(%rsp)
lea    0xe91(%rip),%rbx
xor    %r14d,%r14d
jmp    1199 <hexdump+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r14,%r15
je     1202 <hexdump+0xe2>
mov    %r14d,%ebp
and    $0xf,%ebp
jne    11b6 <hexdump+0x96>
mov    (%r12),%edi
lea    0xe58(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%edi
movzbl 0x0(%r13,%r14,1),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0xf,%ebp
jne    1190 <hexdump+0x70>
mov    0x18(%rsp),%rax
lea    (%rax,%r14,1),%rdi
mov    $0x10,%esi
call   1030 <asciishow@plt>
cmp    %r14,0x20(%rsp)
je     1190 <hexdump+0x70>
mov    (%r12),%edi
lea    0xe0c(%rip),%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1190 <hexdump+0x70>
mov    0x8(%rsp),%rax
mov    %eax,%r15d
mov    %r15d,%r14d
and    $0xf,%r14d
lea    -0x10(%r14),%ebx
lea    0xdf7(%rip),%rbp
nopl   0x0(%rax)
mov    (%r12),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
inc    %ebx
jne    1220 <hexdump+0x100>
mov    %r15d,%eax
add    %rax,%r13
mov    %r14d,%eax
sub    %rax,%r13
mov    %r13,%rdi
mov    %r14d,%esi
call   1030 <asciishow@plt>
mov    (%r12),%edi
lea    0xdc3(%rip),%rsi
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

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

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