#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 < 32 || c > 126) ? '.' : 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    12b8 <hex_dump+0x1a8>
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    12b3 <hex_dump+0x1a3>
movslq -0x24(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
je     12b3 <hex_dump+0x1a3>
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    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1283 <hex_dump+0x173>
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    $0x20,%eax
jl     1259 <hex_dump+0x149>
movzbl -0x39(%rbp),%eax
cmp    $0x7e,%eax
jle    1266 <hex_dump+0x156>
mov    $0x2e,%eax
mov    %eax,-0x40(%rbp)
jmp    126d <hex_dump+0x15d>
movzbl -0x39(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121d <hex_dump+0x10d>
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
jbe    12ae <hex_dump+0x19e>
mov    -0x20(%rbp),%rsi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b3 <hex_dump+0x1a3>
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,%rbp
mov    %rdi,%r13
lea    0xeb2(%rip),%rdi
mov    %rcx,0x20(%rsp)
mov    %rcx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbp,%rbp
je     1301 <hex_dump+0x1d1>
mov    %rbp,%rax
mov    %r13,%rbp
xor    %r14d,%r14d
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,0x18(%rsp)
lea    -0x1(%r15),%rax
mov    %rax,0x10(%rsp)
mov    %r14d,%r15d
add    $0x2,%r14d
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
mov    %rax,%r12
movzbl 0x0(%rbp,%rax,1),%esi
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%r15,%r12,1),%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    %rcx,%rdx
or     %rbx,%rdx
shr    $0x20,%rdx
je     11e0 <hex_dump+0xb0>
mov    %rcx,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
jne    11e9 <hex_dump+0xb9>
jmp    1240 <hex_dump+0x110>
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
je     1240 <hex_dump+0x110>
lea    0x1(%r12),%rax
add    $0x1,%r14d
cmp    %rax,0x18(%rsp)
jne    11a0 <hex_dump+0x70>
mov    %rbp,0x8(%rsp)
add    %r15d,%eax
add    $0x1,%eax
movslq %eax,%r14
lea    0xdfe(%rip),%rbp
jmp    1221 <hex_dump+0xf1>
mov    %r14,%rax
xor    %edx,%edx
div    %rbx
add    $0x1,%r14
test   %rdx,%rdx
je     1260 <hex_dump+0x130>
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1210 <hex_dump+0xe0>
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
jmp    1218 <hex_dump+0xe8>
xor    %eax,%eax
cmp    %r12,0x10(%rsp)
sete   %al
add    %r12d,%r15d
lea    (%rax,%r15,1),%r14d
add    $0x1,%r14d
jmp    1265 <hex_dump+0x135>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rbp
lea    0xda4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%r12,%rbp,1),%rax
add    $0x1,%rax
cmp    %rax,%r13
mov    %rax,0x8(%rsp)
jae    12c0 <hex_dump+0x190>
add    %r12,%rbp
mov    %rbp,%r15
nopl   0x0(%rax,%rax,1)
lea    0x1(%r13),%rbp
movzbl 0x0(%r13),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
cmp    %r15,%r13
mov    %rbp,%r13
jb     1290 <hex_dump+0x160>
jmp    12c3 <hex_dump+0x193>
nopl   0x0(%rax)
mov    %r13,%rbp
lea    0xd47(%rip),%rdi
call   1040 <puts@plt>
cmp    %r12,0x10(%rsp)
je     1301 <hex_dump+0x1d1>
not    %r12
mov    0x18(%rsp),%r15
add    %r12,%r15
lea    0xd18(%rip),%rdi
mov    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%r13
mov    0x8(%rsp),%rbp
jmp    1180 <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 = [3 x i8] c" |\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [3 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 ([3 x i8], [3 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, 32
br i1 %68, label %73, label %69
69: ; preds = %62
%70 = load i8, i8* %12
%71 = zext i8 %70 to i32
%72 = icmp sgt i32 %71, 126
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 ([3 x i8], [3 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 = [3 x i8] c" |\00"
@str = [2 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 ([3 x i8], [3 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, -127
%50 = icmp ult i8 %49, -95
%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 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%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
}