void prettyprint(const unsigned char *data, unsigned int size) {
  unsigned int i;
  const unsigned char *dataptr = data;
  unsigned char asciigraph[17];
  memset(asciigraph, '\x00', 17);
  size = (size > 256) ? 256 : size;
  for (i = 0; i < size; i++, dataptr++) {
    printf("%02x ", *dataptr);
    asciigraph[i % 16] =
        (isgraph(*dataptr) || (*dataptr == ' ')) ? *dataptr : '.';
    if (i % 16 == 15) {
      printf("%s\n", asciigraph);
      memset(asciigraph, '\x00', 17);
    }
  }
  if (i % 16) {
    printf("%*s", (16 - (i % 16)) * 3, " ");
    printf("%s\n", asciigraph);
  }
}


x86 assembly (clang, -O0):
<prettyprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
cmpl   $0x100,-0xc(%rbp)
jbe    1171 <prettyprint+0x41>
mov    $0x100,%eax
mov    %eax,-0x34(%rbp)
jmp    1177 <prettyprint+0x47>
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1247 <prettyprint+0x117>
mov    -0x18(%rbp),%rax
movzbl (%rax),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1050 <isgraph@plt>
cmp    $0x0,%eax
jne    11ca <prettyprint+0x9a>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jne    11d9 <prettyprint+0xa9>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x38(%rbp)
jmp    11e6 <prettyprint+0xb6>
mov    $0x2e,%eax
mov    %eax,-0x38(%rbp)
jmp    11e6 <prettyprint+0xb6>
mov    -0x38(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
jne    1228 <prettyprint+0xf8>
lea    -0x30(%rbp),%rsi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
jmp    122d <prettyprint+0xfd>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1184 <prettyprint+0x54>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     128d <prettyprint+0x15d>
mov    -0x10(%rbp),%ecx
and    $0xf,%ecx
mov    $0x10,%eax
sub    %ecx,%eax
imul   $0x3,%eax,%esi
lea    0xd9d(%rip),%rdi
lea    0xd90(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prettyprint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
cmp    $0x100,%esi
mov    $0x100,%eax
cmovb  %esi,%eax
test   %eax,%eax
je     120c <prettyprint+0xdc>
mov    %rdi,%rbx
mov    %eax,0xc(%rsp)
mov    %eax,%r13d
lea    0xe9e(%rip),%r14
lea    0x10(%rsp),%r15
xor    %r12d,%r12d
jmp    1189 <prettyprint+0x59>
nopl   0x0(%rax)
add    $0x1,%r12
cmp    %r12d,%r13d
je     11da <prettyprint+0xaa>
movzbl (%rbx,%r12,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx,%r12,1),%ebp
mov    %ebp,%edi
call   1050 <isgraph@plt>
cmp    $0x20,%ebp
mov    $0x2e,%ecx
cmove  %ebp,%ecx
test   %eax,%eax
cmovne %ebp,%ecx
mov    %r12d,%eax
and    $0xf,%eax
mov    %cl,0x10(%rsp,%rax,1)
cmp    $0xf,%eax
jne    1180 <prettyprint+0x50>
mov    %r15,%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
jmp    1180 <prettyprint+0x50>
mov    0xc(%rsp),%ecx
and    $0xf,%ecx
je     120c <prettyprint+0xdc>
mov    $0x10,%eax
sub    %ecx,%eax
lea    (%rax,%rax,2),%esi
lea    0xe22(%rip),%rdi
lea    0xe19(%rip),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%02x \00"
@.str.2 = [4 x i8] c"%*s\00"
@.str.3 = [2 x i8] c" \00"
define void @prettyprint(i8* nocapture %0, i32 %1) {
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%5 = icmp ult i32 %1, 256
%6 = select i1 %5, i32 %1, i32 256
%7 = icmp eq i32 %6, 0
br i1 %7, label %39, label %8
8: ; preds = %2, %27
%9 = phi i8* [ %29, %27 ], [ %0, %2 ]
%10 = phi i32 [ %28, %27 ], [ 0, %2 ]
%11 = load i8, i8* %9
%12 = zext i8 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8, i8* %9
%15 = zext i8 %14 to i32
%16 = tail call i32 @isgraph(i32 %15)
%17 = icmp ne i32 %16, 0
%18 = icmp eq i8 %14, 32
%19 = select i1 %17, i1 true, i1 %18
%20 = select i1 %19, i8 %14, i8 46
%21 = and i32 %10, 15
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %22
store i8 %20, i8* %23
%24 = icmp eq i32 %21, 15
br i1 %24, label %25, label %27
25: ; preds = %8
%26 = call i32 @puts(i8* %4)
br label %27
27: ; preds = %8, %25
%28 = add nuw nsw i32 %10, 1
%29 = getelementptr inbounds i8, i8* %9, i64 1
%30 = icmp eq i32 %28, %6
br i1 %30, label %31, label %8
31: ; preds = %27
%32 = and i32 %6, 15
%33 = icmp eq i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %31
%35 = sub nuw nsw i32 16, %32
%36 = mul nuw nsw i32 %35, 3
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @puts(i8* %4)
br label %39
39: ; preds = %2, %34, %31
ret void
}