#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*/ printf(char *, ...);
void hex_dump(const void *src, size_t length, size_t line_size, char *prefix) {
  int i = 0;
  const unsigned char *address = src;
  const unsigned char *line = address;
  unsigned char c;
  printf("%s | ", prefix);
  while (length-- > 0) {
    printf("%02X ", *address++);
    if (!(++i % line_size) || (length == 0 && i % line_size)) {
      if (length == 0) {
        while (i++ % line_size)
          printf("__ ");
      }
      printf(" | ");
      while (line < address) {
        c = *line++;
        printf("%c", (c < 33 || c == 255) ? 0x2E : c);
      }
      printf("\n");
      if (length > 0)
        printf("%s | ", prefix);
    }
  }
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
jbe    12ba <hex_dump+0x1aa>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movzbl (%rax),%esi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cltq
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
je     11c8 <hex_dump+0xb8>
cmpq   $0x0,-0x10(%rbp)
jne    12b5 <hex_dump+0x1a5>
movslq -0x24(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
je     12b5 <hex_dump+0x1a5>
cmpq   $0x0,-0x10(%rbp)
jne    120f <hex_dump+0xff>
jmp    11d8 <hex_dump+0xc8>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
cltq
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
je     120a <hex_dump+0xfa>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d8 <hex_dump+0xc8>
jmp    120f <hex_dump+0xff>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1285 <hex_dump+0x175>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
mov    (%rax),%al
mov    %al,-0x39(%rbp)
movzbl -0x39(%rbp),%eax
cmp    $0x21,%eax
jl     125b <hex_dump+0x14b>
movzbl -0x39(%rbp),%eax
cmp    $0xff,%eax
jne    1268 <hex_dump+0x158>
mov    $0x2e,%eax
mov    %eax,-0x40(%rbp)
jmp    126f <hex_dump+0x15f>
movzbl -0x39(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%esi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121d <hex_dump+0x10d>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
jbe    12b0 <hex_dump+0x1a0>
mov    -0x20(%rbp),%rsi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b5 <hex_dump+0x1a5>
jmp    1151 <hex_dump+0x41>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xec2(%rip),%rdi
mov    %rcx,0x18(%rsp)
mov    %rcx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14,%r14
je     12df <hex_dump+0x1bf>
mov    %r14,%rax
mov    %rbp,%rcx
xor    %r14d,%r14d
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,0x10(%rsp)
lea    -0x1(%r15),%rax
mov    %rax,0x8(%rsp)
mov    %r14d,%r15d
add    $0x2,%r14d
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
mov    %rax,%r12
mov    %rcx,%r13
movzbl (%rcx,%rax,1),%esi
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r15,%r12,1),%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    %rcx,%rdx
or     %rbx,%rdx
shr    $0x20,%rdx
je     11d0 <hex_dump+0xb0>
mov    %rcx,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
jne    11d9 <hex_dump+0xb9>
jmp    1230 <hex_dump+0x110>
nopl   (%rax)
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
je     1230 <hex_dump+0x110>
lea    0x1(%r12),%rax
add    $0x1,%r14d
cmp    %rax,0x10(%rsp)
mov    %r13,%rcx
jne    1190 <hex_dump+0x70>
add    %r15d,%eax
add    $0x1,%eax
movslq %eax,%r14
lea    0xe10(%rip),%r15
jmp    1211 <hex_dump+0xf1>
xchg   %ax,%ax
mov    %r14,%rax
xor    %edx,%edx
div    %rbx
add    $0x1,%r14
test   %rdx,%rdx
je     1245 <hex_dump+0x125>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1200 <hex_dump+0xe0>
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
jmp    1208 <hex_dump+0xe8>
xor    %eax,%eax
cmp    %r12,0x8(%rsp)
sete   %al
add    %r12d,%r15d
lea    (%rax,%r15,1),%r14d
add    $0x1,%r14d
lea    0xdb6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r12,%r13,1),%rax
add    $0x1,%rax
cmp    %rax,%rbp
mov    %rax,0x20(%rsp)
jae    12a0 <hex_dump+0x180>
mov    %r13,%r15
add    %r12,%r15
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbp),%r13
movzbl 0x0(%rbp),%eax
lea    0x1(%rax),%ecx
cmp    $0x22,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
cmp    %r15,%rbp
mov    %r13,%rbp
jb     1270 <hex_dump+0x150>
jmp    12a3 <hex_dump+0x183>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%r13
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    %r12,0x8(%rsp)
je     12df <hex_dump+0x1bf>
not    %r12
mov    0x10(%rsp),%r15
add    %r12,%r15
lea    0xd3a(%rip),%rdi
mov    0x18(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rbp
mov    0x20(%rsp),%rcx
jmp    1170 <hex_dump+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%s | \00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [4 x i8] c"__ \00"
@.str.3 = [4 x i8] c" | \00"
define void @hex_dump(i8* %0, i64 %1, i64 %2, i8* %3) {
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = icmp eq i64 %1, 0
br i1 %6, label %61, label %7
7: ; preds = %4, %59
%8 = phi i64 [ %16, %59 ], [ %1, %4 ]
%9 = phi i8* [ %56, %59 ], [ %0, %4 ]
%10 = phi i8* [ %17, %59 ], [ %0, %4 ]
%11 = phi i32 [ %42, %59 ], [ 0, %4 ]
br label %12
12: ; preds = %7, %26
%13 = phi i64 [ %16, %26 ], [ %8, %7 ]
%14 = phi i8* [ %17, %26 ], [ %10, %7 ]
%15 = phi i32 [ %21, %26 ], [ %11, %7 ]
%16 = add i64 %13, -1
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = load i8, i8* %14
%19 = zext i8 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = add nsw i32 %15, 1
%22 = sext i32 %21 to i64
%23 = urem i64 %22, %2
%24 = icmp eq i64 %23, 0
%25 = icmp eq i64 %16, 0
br i1 %24, label %27, label %26
26: ; preds = %12
br i1 %25, label %30, label %12
27: ; preds = %12
%28 = add i32 %15, 2
%29 = select i1 %25, i32 %28, i32 %21
br label %41
30: ; preds = %26
%31 = add i32 %15, 2
%32 = sext i32 %31 to i64
br label %33
33: ; preds = %30, %33
%34 = phi i64 [ %32, %30 ], [ %36, %33 ]
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%36 = add i64 %34, 1
%37 = urem i64 %34, %2
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %33
39: ; preds = %33
%40 = trunc i64 %36 to i32
br label %41
41: ; preds = %27, %39
%42 = phi i32 [ %40, %39 ], [ %29, %27 ]
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp ult i8* %9, %17
br i1 %44, label %45, label %55
45: ; preds = %41, %45
%46 = phi i8* [ %47, %45 ], [ %9, %41 ]
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8, i8* %46
%49 = add i8 %48, 1
%50 = icmp ult i8 %49, 34
%51 = select i1 %50, i8 46, i8 %48
%52 = zext i8 %51 to i32
%53 = tail call i32 @putchar(i32 %52)
%54 = icmp ult i8* %46, %14
br i1 %54, label %45, label %55
55: ; preds = %45, %41
%56 = phi i8* [ %9, %41 ], [ %47, %45 ]
%57 = tail call i32 @putchar(i32 10)
%58 = icmp eq i64 %16, 0
br i1 %58, label %61, label %59
59: ; preds = %55
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %7
61: ; preds = %55, %4
ret void
}