#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
void dump_hex(char *str, int len) {
  char d[17];
  d[16] = 0;
  unsigned int i, bytes, index = 0;
  int left_len = len;
  while (left_len > 0) {
    if (left_len / 16 >= 1) {
      memcpy(d, str + index, 16);
      bytes = 16;
    } else {
      memcpy(d, str + index, left_len);
      bytes = left_len;
    }
    printf("%08X\t", index);
    index += 16;
    for (i = 0; i < bytes; i++) {
      printf("%02X", (unsigned char)(d[i]));
      if ((i + 1) % 4 == 0)
        printf(" ");
      if (d[i] == 127 || d[i] < -127 || (d[i] >= 0 && d[i] <= 31))
        d[i] = '.';
    }
    if (bytes < 16) {
      for (i = bytes; i < 16; i++) {
        printf("   ");
        if ((i + 1) % 4 == 0)
          printf(" ");
      }
      d[bytes] = '\0';
    }
    printf("%s\n", d);
    left_len -= 16;
  }
}


x86 assembly (clang, -O0):
<dump_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    12e3 <dump_hex+0x1c3>
mov    -0x30(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x1,%eax
jl     1182 <dump_hex+0x62>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    %rax,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movl   $0x10,-0x28(%rbp)
jmp    119e <dump_hex+0x7e>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    %rax,%rsi
mov    -0x30(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    1260 <dump_hex+0x140>
mov    -0x24(%rbp),%eax
movzbl -0x20(%rbp,%rax,1),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    1201 <dump_hex+0xe1>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x7f,%eax
je     1245 <dump_hex+0x125>
mov    -0x24(%rbp),%eax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0xffffff81,%eax
jl     1245 <dump_hex+0x125>
mov    -0x24(%rbp),%eax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x0,%eax
jl     124d <dump_hex+0x12d>
mov    -0x24(%rbp),%eax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x1f,%eax
jg     124d <dump_hex+0x12d>
mov    -0x24(%rbp),%eax
movb   $0x2e,-0x20(%rbp,%rax,1)
jmp    1252 <dump_hex+0x132>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11bf <dump_hex+0x9f>
cmpl   $0x10,-0x28(%rbp)
jae    12c3 <dump_hex+0x1a3>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jae    12bb <dump_hex+0x19b>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    12a8 <dump_hex+0x188>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ad <dump_hex+0x18d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1270 <dump_hex+0x150>
mov    -0x28(%rbp),%eax
movb   $0x0,-0x20(%rbp,%rax,1)
lea    -0x20(%rbp),%rsi
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
sub    $0x10,%eax
mov    %eax,-0x30(%rbp)
jmp    1140 <dump_hex+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,0x28(%rsp)
movb   $0x0,0x20(%rsp)
test   %esi,%esi
jle    128a <dump_hex+0x14a>
lea    0x10(%rsp),%r15
lea    0xe9a(%rip),%rbx
lea    0xe98(%rip),%r13
xor    %r14d,%r14d
jmp    11a6 <dump_hex+0x66>
nopl   0x0(%rax,%rax,1)
mov    0x30(%rsp),%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    0x8(%rsp),%ebp
add    $0x10,%r14
mov    %r15,%rdi
call   1040 <puts@plt>
cmp    $0x10,%ebp
mov    0xc(%rsp),%esi
jle    128a <dump_hex+0x14a>
mov    %esi,%ebp
cmp    $0x10,%esi
mov    $0x10,%edx
mov    %esi,0x8(%rsp)
cmovb  %esi,%edx
lea    0x1(%rdx),%r12d
mov    %rdx,%rbp
neg    %rbp
mov    0x28(%rsp),%rax
lea    (%rax,%r14,1),%rsi
mov    %r15,%rdi
mov    %rdx,0x30(%rsp)
call   1060 <memcpy@plt>
lea    0xe22(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r15d
jmp    1208 <dump_hex+0xc8>
movb   $0x2e,0xf(%rsp,%r15,1)
lea    (%r15,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%r15
cmp    $0x1,%rax
je     1240 <dump_hex+0x100>
movzbl 0xf(%rsp,%r15,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x3,%r15b
jne    1228 <dump_hex+0xe8>
mov    $0x20,%edi
call   1030 <putchar@plt>
movzbl 0xf(%rsp,%r15,1),%eax
cmp    $0x20,%al
jb     11f0 <dump_hex+0xb0>
add    $0x81,%al
cmp    $0x1,%al
ja     11f6 <dump_hex+0xb6>
jmp    11f0 <dump_hex+0xb0>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%ebp
mov    %ebp,%eax
sub    $0x10,%eax
mov    %eax,0xc(%rsp)
lea    0x10(%rsp),%r15
jb     126e <dump_hex+0x12e>
jmp    118d <dump_hex+0x4d>
nopl   0x0(%rax)
add    $0x1,%r12d
cmp    $0x11,%r12d
je     1180 <dump_hex+0x40>
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x3,%r12b
jne    1260 <dump_hex+0x120>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1260 <dump_hex+0x120>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%08X\09\00"
@.str.1 = [5 x i8] c"%02X\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [4 x i8] c"%s\0A\00"
define void @dump_hex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [17 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 16
store i8 0, i8* %10
store i32 0, i32* %8
%11 = load i32, i32* %4
store i32 %11, i32* %9
br label %12
12: ; preds = %117, %2
%13 = load i32, i32* %9
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %122
15: ; preds = %12
%16 = load i32, i32* %9
%17 = sdiv i32 %16, 16
%18 = icmp sge i32 %17, 1
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = load i32, i32* %8
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = call i32 @memcpy(i8* %20, i8* %24, i32 16)
store i32 16, i32* %7
br label %35
26: ; preds = %15
%27 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%28 = load i8*, i8** %3
%29 = load i32, i32* %8
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i32, i32* %9
%33 = call i32 @memcpy(i8* %27, i8* %31, i32 %32)
%34 = load i32, i32* %9
store i32 %34, i32* %7
br label %35
35: ; preds = %26, %19
%36 = load i32, i32* %8
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %8
%39 = add i32 %38, 16
store i32 %39, i32* %8
store i32 0, i32* %6
br label %40
40: ; preds = %90, %35
%41 = load i32, i32* %6
%42 = load i32, i32* %7
%43 = icmp ult i32 %41, %42
br i1 %43, label %44, label %93
44: ; preds = %40
%45 = load i32, i32* %6
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %6
%52 = add i32 %51, 1
%53 = urem i32 %52, 4
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %44
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %55, %44
%58 = load i32, i32* %6
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 127
br i1 %63, label %85, label %64
64: ; preds = %57
%65 = load i32, i32* %6
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %66
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp slt i32 %69, -127
br i1 %70, label %85, label %71
71: ; preds = %64
%72 = load i32, i32* %6
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp sge i32 %76, 0
br i1 %77, label %78, label %89
78: ; preds = %71
%79 = load i32, i32* %6
%80 = zext i32 %79 to i64
%81 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %80
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp sle i32 %83, 31
br i1 %84, label %85, label %89
85: ; preds = %78, %64, %57
%86 = load i32, i32* %6
%87 = zext i32 %86 to i64
%88 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %87
store i8 46, i8* %88
br label %89
89: ; preds = %85, %78, %71
br label %90
90: ; preds = %89
%91 = load i32, i32* %6
%92 = add i32 %91, 1
store i32 %92, i32* %6
br label %40
93: ; preds = %40
%94 = load i32, i32* %7
%95 = icmp ult i32 %94, 16
br i1 %95, label %96, label %117
96: ; preds = %93
%97 = load i32, i32* %7
store i32 %97, i32* %6
br label %98
98: ; preds = %110, %96
%99 = load i32, i32* %6
%100 = icmp ult i32 %99, 16
br i1 %100, label %101, label %113
101: ; preds = %98
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%103 = load i32, i32* %6
%104 = add i32 %103, 1
%105 = urem i32 %104, 4
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %101
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %109
109: ; preds = %107, %101
br label %110
110: ; preds = %109
%111 = load i32, i32* %6
%112 = add i32 %111, 1
store i32 %112, i32* %6
br label %98
113: ; preds = %98
%114 = load i32, i32* %7
%115 = zext i32 %114 to i64
%116 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %115
store i8 0, i8* %116
br label %117
117: ; preds = %113, %93
%118 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %118)
%120 = load i32, i32* %9
%121 = sub nsw i32 %120, 16
store i32 %121, i32* %9
br label %12
122: ; preds = %12
ret void
}

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