#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 *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printk(char *, unsigned int, unsigned char *,
                          unsigned char *);
int /*<<< orphan*/ sprintk(char *, char *, unsigned char);
void hexdump(void *data, int len) {
  int i = 0;
  int index = 0;
  unsigned int base = 0;
  unsigned char *p = data;
  unsigned char hex[16 * 3 + 1] = {
      0,
  };
  unsigned char text[16 + 1] = {
      0,
  };
  unsigned char c;
  for (i = 0; i < len; i++) {
    index = i & 0xf;
    if (i && index == 0) {
      printk("%08x  %-48s  |%-16s|\n", base, hex, text);
      base += 0x10;
      memset(hex, 0, sizeof hex);
      memset(text, 0, sizeof text);
    }
    c = *p++;
    sprintk((char *)&hex[index * 3], "%02x ", c);
    if (c < 0x20 || c > 0x7f)
      text[index] = '.';
    else
      text[index] = c;
  }
  printk("%08x  %-48s  |%-16s|\n", base, hex, text);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x31,%edx
call   1040 <memset@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1275 <hexdump+0x145>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11ef <hexdump+0xbf>
cmpl   $0x0,-0x14(%rbp)
jne    11ef <hexdump+0xbf>
mov    -0x18(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    0xe3f(%rip),%rdi
call   1030 <printk@plt>
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x31,%edx
call   1040 <memset@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0x81(%rbp)
imul   $0x3,-0x14(%rbp),%eax
cltq
lea    -0x60(%rbp),%rdi
add    %rax,%rdi
lea    0xdfc(%rip),%rsi
movzbl -0x81(%rbp),%edx
call   1050 <sprintk@plt>
movzbl -0x81(%rbp),%eax
cmp    $0x20,%eax
jl     1246 <hexdump+0x116>
movzbl -0x81(%rbp),%eax
cmp    $0x7f,%eax
jle    1254 <hexdump+0x124>
movslq -0x14(%rbp),%rax
movb   $0x2e,-0x80(%rbp,%rax,1)
jmp    1262 <hexdump+0x132>
mov    -0x81(%rbp),%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
jmp    1267 <hexdump+0x137>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <hexdump+0x56>
mov    -0x18(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    0xd79(%rip),%rdi
call   1030 <printk@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,0x38(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movb   $0x0,0x70(%rsp)
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
test   %esi,%esi
jle    1239 <hexdump+0x109>
mov    %esi,%ebp
xor    %r12d,%r12d
lea    0xe9e(%rip),%r15
mov    $0x2e,%ebx
movl   $0x0,0xc(%rsp)
mov    %rbp,0x30(%rsp)
jmp    11c8 <hexdump+0x98>
nopl   0x0(%rax)
mov    0x38(%rsp),%rax
movzbl (%rax,%r12,1),%r14d
lea    0x0(%r13,%r13,2),%eax
lea    (%rsp,%rax,1),%rdi
add    $0x40,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <sprintk@plt>
cmp    $0x20,%r14b
cmovl  %ebx,%r14d
mov    %r14b,0x10(%rsp,%r13,1)
add    $0x1,%r12
cmp    %r12d,%ebp
je     1241 <hexdump+0x111>
mov    %r12d,%r13d
and    $0xf,%r13d
test   %r12d,%r12d
je     1190 <hexdump+0x60>
test   %r13d,%r13d
jne    1190 <hexdump+0x60>
lea    0xe20(%rip),%rdi
mov    0xc(%rsp),%r14d
mov    %r14d,%esi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdx
mov    %r15,%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rcx
call   1030 <printk@plt>
add    $0x10,%r14d
mov    %r14d,0xc(%rsp)
mov    %rbp,%rdi
mov    0x30(%rsp),%rbp
xor    %esi,%esi
mov    $0x31,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%r15
mov    $0x2e,%ebx
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
jmp    1190 <hexdump+0x60>
movl   $0x0,0xc(%rsp)
lea    0xdb8(%rip),%rdi
lea    0x40(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    0xc(%rsp),%esi
call   1030 <printk@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [22 x i8] c"%08x %-48s |%-16s|\0A\00"
@.str.1 = [6 x i8] c"%02x \00"
define void @hexdump(i8* nocapture %0, i32 %1) {
%3 = alloca [49 x i8]
%4 = alloca [17 x i8]
%5 = getelementptr inbounds [49 x i8], [49 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %35
8: ; preds = %2, %21
%9 = phi i32 [ %33, %21 ], [ 0, %2 ]
%10 = phi i8* [ %23, %21 ], [ %0, %2 ]
%11 = phi i32 [ %22, %21 ], [ 0, %2 ]
%12 = and i32 %9, 15
%13 = icmp ne i32 %9, 0
%14 = icmp eq i32 %12, 0
%15 = and i1 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %8
%17 = call i32 @printk(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %5, i8* %6)
%18 = add i32 %11, 16
%19 = call i32 @memset(i8* %5, i32 0, i32 49)
%20 = call i32 @memset(i8* %6, i32 0, i32 17)
br label %21
21: ; preds = %16, %8
%22 = phi i32 [ %18, %16 ], [ %11, %8 ]
%23 = getelementptr inbounds i8, i8* %10, i64 1
%24 = load i8, i8* %10
%25 = mul nuw nsw i32 %12, 3
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [49 x i8], [49 x i8]* %3, i64 0, i64 %26
%28 = call i32 @sprintk(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %24)
%29 = icmp slt i8 %24, 32
%30 = zext i32 %12 to i64
%31 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %30
%32 = select i1 %29, i8 46, i8 %24
store i8 %32, i8* %31
%33 = add nuw nsw i32 %9, 1
%34 = icmp eq i32 %33, %1
br i1 %34, label %35, label %8
35: ; preds = %21, %2
%36 = phi i32 [ 0, %2 ], [ %22, %21 ]
%37 = call i32 @printk(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %36, i8* %5, i8* %6)
ret void
}