#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 uint8_t;

/* Variables and functions */
scalar_t__ isprint(int);
int /*<<< orphan*/ printf(char *, ...);
void dump_hex(const void *buf, int len) {
  const uint8_t *data = buf;
  int i;
  char ascii_buf[17];
  ascii_buf[16] = '\0';
  for (i = 0; i < len; i++) {
    int val = data[i];
    int off = i % 16;
    if (off == 0)
      printf("%08x  ", i);
    printf("%02x ", val);
    ascii_buf[off] = isprint(val) ? val : '.';
    if (off == 15)
      printf(" %-16s\n", ascii_buf);
  }
  i %= 16;
  if (i) {
    ascii_buf[i] = '\0';
    while (i++ < 16)
      printf("   ");
    printf(" %-16s\n", ascii_buf);
  }
}


x86 assembly (clang, -O0):
<dump_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fc <dump_hex+0xdc>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    1185 <dump_hex+0x65>
mov    -0x1c(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     11b3 <dump_hex+0x93>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    11c0 <dump_hex+0xa0>
mov    $0x2e,%eax
mov    %eax,-0x3c(%rbp)
jmp    11c0 <dump_hex+0xa0>
mov    -0x3c(%rbp),%eax
mov    %al,%cl
movslq -0x38(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
cmpl   $0xf,-0x38(%rbp)
jne    11e9 <dump_hex+0xc9>
lea    -0x30(%rbp),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ee <dump_hex+0xce>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1142 <dump_hex+0x22>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1256 <dump_hex+0x136>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x10,%eax
jge    1244 <dump_hex+0x124>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121d <dump_hex+0xfd>
lea    -0x30(%rbp),%rsi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movb   $0x0,0x10(%rsp)
test   %esi,%esi
jle    11ff <dump_hex+0xdf>
mov    %rdi,%rbx
mov    %rsi,0x20(%rsp)
mov    %esi,%r13d
mov    $0x2e,%ebp
xor    %r14d,%r14d
jmp    1159 <dump_hex+0x39>
add    $0x1,%r14
cmp    %r14,%r13
je     11b7 <dump_hex+0x97>
mov    (%rbx,%r14,4),%r15d
mov    %r14d,%r12d
and    $0xf,%r12d
test   %r12,%r12
jne    117a <dump_hex+0x5a>
lea    0xe90(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe86(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15d,%edi
call   1040 <isprint@plt>
test   %rax,%rax
cmove  %ebp,%r15d
mov    %r15b,(%rsp,%r12,1)
cmp    $0xf,%r12d
jne    1150 <dump_hex+0x30>
lea    0xe62(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1150 <dump_hex+0x30>
mov    0x20(%rsp),%rax
and    $0xf,%eax
test   %rax,%rax
je     11ff <dump_hex+0xdf>
movb   $0x0,(%rsp,%rax,1)
lea    -0x10(%rax),%ebp
lea    0xe43(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
inc    %ebp
jne    11e0 <dump_hex+0xc0>
lea    0xe18(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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