#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*/ memset(unsigned char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
void hexdump(const char *prefix, void *buffer, int size) {
  unsigned char *c = buffer;
  unsigned char ascii[17] = {
      0,
  };
  int i;
  if (!prefix)
    prefix = "";
  for (i = 0; i < size; i++) {
    if ((i % 16) == 0) {
      if (i > 0)
        printf(" %s\n", ascii);
      memset(ascii, ' ', 16);
      printf("%s%08x  ", prefix, i);
    }
    printf("%02x ", c[i]);
    ascii[i % 16] = (c[i] >= 32 && c[i] <= 127) ? c[i] : '.';
  }
  while ((i++ % 16) != 0)
    printf("   ");
  printf(" %s\n", ascii);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x8(%rbp)
jne    1161 <hexdump+0x41>
lea    0xea7(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1256 <hexdump+0x136>
mov    -0x44(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11cc <hexdump+0xac>
cmpl   $0x0,-0x44(%rbp)
jle    11a4 <hexdump+0x84>
lea    -0x40(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1224 <hexdump+0x104>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jg     1224 <hexdump+0x104>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x48(%rbp)
jmp    1231 <hexdump+0x111>
mov    $0x2e,%eax
mov    %eax,-0x48(%rbp)
jmp    1231 <hexdump+0x111>
mov    -0x48(%rbp),%eax
mov    %al,%cl
mov    -0x44(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1168 <hexdump+0x48>
jmp    125b <hexdump+0x13b>
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x44(%rbp)
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     128a <hexdump+0x16a>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125b <hexdump+0x13b>
lea    -0x40(%rbp),%rsi
lea    0xd6b(%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    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
test   %rdi,%rdi
lea    0xebf(%rip),%rbp
cmovne %rdi,%rbp
test   %edx,%edx
jle    1286 <hexdump+0x166>
mov    %edx,%r15d
mov    %rsi,%r12
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    0xe93(%rip),%rdi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r12),%esi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r12),%eax
cmp    $0x20,%al
mov    $0x2e,%r13d
cmovl  %r13d,%eax
mov    %al,0x10(%rsp)
mov    $0x1,%r14d
cmp    $0x1,%r15d
je     125d <hexdump+0x13d>
mov    %rbp,0x30(%rsp)
mov    %r15d,0xc(%rsp)
mov    %r15d,%r14d
mov    $0x1,%ebp
lea    0xe3f(%rip),%rbx
jmp    1208 <hexdump+0xe8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbp,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r12,%rbp,1),%eax
cmp    $0x20,%al
cmovl  %r13d,%eax
mov    %al,0x10(%rsp,%r15,1)
add    $0x1,%rbp
cmp    %rbp,%r14
je     1256 <hexdump+0x136>
mov    %rbp,%r15
and    $0xf,%r15
jne    11e0 <hexdump+0xc0>
lea    0xde8(%rip),%rdi
lea    0x10(%rsp),%r13
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r13,%rdi
mov    $0x2e,%r13d
mov    $0x20,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    0xdbf(%rip),%rdi
mov    0x30(%rsp),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11e0 <hexdump+0xc0>
testb  $0xf,0xc(%rsp)
je     1286 <hexdump+0x166>
add    $0x1,%r14d
lea    0xdac(%rip),%rbx
mov    %r14d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
test   $0xf,%r14b
mov    %ebp,%r14d
jne    1270 <hexdump+0x150>
lea    0xd73(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c" %s\0A\00"
@.str.2 = [9 x i8] c"%s%08x \00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [4 x i8] c" \00"
define void @hexdump(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [17 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %7
%11 = bitcast [17 x i8]* %8 to i8*
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
br label %15
15: ; preds = %14, %3
store i32 0, i32* %9
br label %16
16: ; preds = %74, %15
%17 = load i32, i32* %9
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %77
20: ; preds = %16
%21 = load i32, i32* %9
%22 = srem i32 %21, 16
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i32, i32* %9
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %24
%31 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%32 = call i32 @memset(i8* %31, i8 signext 32, i32 16)
%33 = load i8*, i8** %4
%34 = load i32, i32* %9
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %34)
br label %36
36: ; preds = %30, %20
%37 = load i8*, i8** %7
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = load i8*, i8** %7
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = icmp sge i32 %49, 32
br i1 %50, label %51, label %66
51: ; preds = %36
%52 = load i8*, i8** %7
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp sle i32 %57, 127
br i1 %58, label %59, label %66
59: ; preds = %51
%60 = load i8*, i8** %7
%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 %67
66: ; preds = %51, %36
br label %67
67: ; preds = %66, %59
%68 = phi i32 [ %65, %59 ], [ 46, %66 ]
%69 = trunc i32 %68 to i8
%70 = load i32, i32* %9
%71 = srem i32 %70, 16
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %72
store i8 %69, i8* %73
br label %74
74: ; preds = %67
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
br label %16
77: ; preds = %16
br label %78
78: ; preds = %83, %77
%79 = load i32, i32* %9
%80 = add nsw i32 %79, 1
store i32 %80, i32* %9
%81 = srem i32 %79, 16
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %78
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %78
85: ; preds = %78
%86 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %86)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c" %s\0A\00"
@.str.2 = [9 x i8] c"%s%08x \00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [4 x i8] c" \00"
define void @hexdump(i8* %0, i8* nocapture %1, i32 %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
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %52
9: ; preds = %3
%10 = zext i32 %2 to i64
%11 = call i32 @memset(i8* %5, i8 signext 32, i32 16)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %7, 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 = icmp sgt i8 %16, 31
%18 = select i1 %17, i8 %16, i8 46
store i8 %18, i8* %5
%19 = icmp eq i32 %2, 1
br i1 %19, label %23, label %25
20: ; preds = %34
%21 = and i32 %2, 15
%22 = icmp eq i32 %21, 0
br i1 %22, label %52, label %23
23: ; preds = %9, %20
%24 = phi i32 [ 1, %9 ], [ %2, %20 ]
br label %46
25: ; preds = %9, %34
%26 = phi i64 [ %44, %34 ], [ 1, %9 ]
%27 = trunc i64 %26 to i32
%28 = and i32 %27, 15
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%32 = call i32 @memset(i8* %5, i8 signext 32, i32 16)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %7, i32 %27)
br label %34
34: ; preds = %30, %25
%35 = getelementptr inbounds i8, i8* %1, i64 %26
%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 = icmp sgt i8 %39, 31
%41 = select i1 %40, i8 %39, i8 46
%42 = zext i32 %28 to i64
%43 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %42
store i8 %41, i8* %43
%44 = add nuw nsw i64 %26, 1
%45 = icmp eq i64 %44, %10
br i1 %45, label %20, label %25
46: ; preds = %23, %46
%47 = phi i32 [ %48, %46 ], [ %24, %23 ]
%48 = add nuw nsw i32 %47, 1
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%50 = and i32 %48, 15
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %46
52: ; preds = %46, %3, %20
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %5)
ret void
}