#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*/ print_indent(int);
int /*<<< orphan*/ stderr;
void dump_hex(unsigned char *data, int len, int indent) {
  while (len > 0) {
    int chunk = len < 16 ? len : 16;
    int i;
    print_indent(indent);
    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    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1286 <dump_hex+0x166>
cmpl   $0x10,-0xc(%rbp)
jge    1151 <dump_hex+0x31>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <dump_hex+0x3e>
mov    $0x10,%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <dump_hex+0x3e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <print_indent@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b0 <dump_hex+0x90>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1173 <dump_hex+0x53>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1253 <dump_hex+0x133>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jge    1224 <dump_hex+0x104>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x1e,%eax
jle    1224 <dump_hex+0x104>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
jmp    1231 <dump_hex+0x111>
mov    $0x2e,%eax
mov    %eax,-0x24(%rbp)
jmp    1231 <dump_hex+0x111>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%edx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ce <dump_hex+0xae>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1040 <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    1132 <dump_hex+0x12>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,(%rsp)
test   %esi,%esi
jle    1202 <dump_hex+0xe2>
mov    %rdi,%rbx
mov    0x2ea0(%rip),%r12
lea    0xeb9(%rip),%r13
lea    0xebb(%rip),%r14
xchg   %ax,%ax
cmp    $0x10,%esi
mov    $0x10,%r15d
mov    %esi,0x4(%rsp)
cmovb  %esi,%r15d
mov    (%rsp),%edi
call   1030 <print_indent@plt>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
movzbl (%rbx,%rbp,1),%edx
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1170 <dump_hex+0x50>
mov    (%r12),%edi
lea    0xe70(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %r13d,%r13d
mov    $0x2e,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%edi
movzbl (%rbx,%r13,1),%eax
lea    -0x1f(%rax),%ecx
cmp    $0x60,%cl
cmovae %ebp,%eax
movzbl %al,%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    11b0 <dump_hex+0x90>
mov    (%r12),%edi
lea    0xe29(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x10,%rbx
mov    0x4(%rsp),%esi
sub    %r15d,%esi
lea    0xe04(%rip),%r13
jg     1150 <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, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
br label %9
9: ; preds = %76, %3
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %84
12: ; preds = %9
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 16
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i32, i32* %5
br label %18
17: ; preds = %12
br label %18
18: ; preds = %17, %15
%19 = phi i32 [ %16, %15 ], [ 16, %17 ]
store i32 %19, i32* %7
%20 = load i32, i32* %6
%21 = call i32 @print_indent(i32 %20)
store i32 0, i32* %8
br label %22
22: ; preds = %35, %18
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %4
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %26
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %22
38: ; preds = %22
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %41
41: ; preds = %73, %38
%42 = load i32, i32* %8
%43 = load i32, i32* %7
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %76
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %4
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = icmp slt i32 %52, 127
br i1 %53, label %54, label %69
54: ; preds = %45
%55 = load i8*, i8** %4
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = icmp sgt i32 %60, 30
br i1 %61, label %62, label %69
62: ; preds = %54
%63 = load i8*, i8** %4
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
br label %70
69: ; preds = %54, %45
br label %70
70: ; preds = %69, %62
%71 = phi i32 [ %68, %62 ], [ 46, %69 ]
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %70
%74 = load i32, i32* %8
%75 = add nsw i32 %74, 1
store i32 %75, i32* %8
br label %41
76: ; preds = %41
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%79 = load i32, i32* %7
%80 = load i32, i32* %5
%81 = sub nsw i32 %80, %79
store i32 %81, i32* %5
%82 = load i8*, i8** %4
%83 = getelementptr inbounds i8, i8* %82, i64 16
store i8* %83, i8** %4
br label %9
84: ; preds = %9
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, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %42
5: ; preds = %3, %36
%6 = phi i8* [ %40, %36 ], [ %0, %3 ]
%7 = phi i32 [ %39, %36 ], [ %1, %3 ]
%8 = icmp ult i32 %7, 16
%9 = select i1 %8, i32 %7, i32 16
%10 = tail call i32 @print_indent(i32 %2)
%11 = zext i32 %9 to i64
br label %12
12: ; preds = %5, %12
%13 = phi i64 [ 0, %5 ], [ %19, %12 ]
%14 = load i32, i32* @stderr
%15 = getelementptr inbounds i8, i8* %6, i64 %13
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %21, label %12
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %24
%25 = phi i64 [ 0, %21 ], [ %34, %24 ]
%26 = load i32, i32* @stderr
%27 = getelementptr inbounds i8, i8* %6, i64 %25
%28 = load i8, i8* %27
%29 = add i8 %28, -31
%30 = icmp ult i8 %29, 96
%31 = select i1 %30, i8 %28, i8 46
%32 = zext i8 %31 to i32
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = add nuw nsw i64 %25, 1
%35 = icmp eq i64 %34, %11
br i1 %35, label %36, label %24
36: ; preds = %24
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%39 = sub nsw i32 %7, %9
%40 = getelementptr inbounds i8, i8* %6, i64 16
%41 = icmp sgt i32 %39, 0
br i1 %41, label %5, label %42
42: ; preds = %36, %3
ret void
}