#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void dump_hex(unsigned char *data, int len) {
  while (len > 0) {
    int i;
    int chunk = len < 16 ? len : 16;
    for (i = 0; i < chunk; i++)
      fprintf(stderr, "%.2x ", data[i]);
    fprintf(stderr, "| ");
    for (i = 0; i < chunk; i++)
      fprintf(stderr, "%c", data[i] < 127 && data[i] > 30 ? data[i] : '.');
    fprintf(stderr, "\n");
    len -= chunk;
    data += 16;
  }
}


x86 assembly (clang, -O0):
<dump_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    126b <dump_hex+0x15b>
cmpl   $0x10,-0xc(%rbp)
jge    113e <dump_hex+0x2e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    114b <dump_hex+0x3b>
mov    $0x10,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <dump_hex+0x3b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1195 <dump_hex+0x85>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1158 <dump_hex+0x48>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1238 <dump_hex+0x128>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jge    1209 <dump_hex+0xf9>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x1e,%eax
jle    1209 <dump_hex+0xf9>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
jmp    1216 <dump_hex+0x106>
mov    $0x2e,%eax
mov    %eax,-0x20(%rbp)
jmp    1216 <dump_hex+0x106>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%edx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b3 <dump_hex+0xa3>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
jmp    111f <dump_hex+0xf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11f4 <dump_hex+0xe4>
mov    %rdi,%r13
mov    0x2eb3(%rip),%r15
lea    0xecc(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x10,%esi
mov    $0x10,%r14d
mov    %esi,0x4(%rsp)
cmovb  %esi,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%edi
movzbl 0x0(%r13,%rbp,1),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1160 <dump_hex+0x50>
mov    (%r15),%edi
lea    0xe80(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %r12d,%r12d
mov    $0x2e,%ebx
mov    %r15,%rbp
lea    0xe6a(%rip),%r15
nop
mov    0x0(%rbp),%edi
movzbl 0x0(%r13,%r12,1),%eax
lea    -0x1f(%rax),%ecx
cmp    $0x60,%cl
cmovae %ebx,%eax
movzbl %al,%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    11a0 <dump_hex+0x90>
mov    0x0(%rbp),%edi
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x10,%r13
mov    0x4(%rsp),%esi
sub    %r14d,%esi
lea    0xe15(%rip),%rbx
mov    %rbp,%r15
jg     1140 <dump_hex+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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