#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 *, ...);
int /*<<< orphan*/ putchar(char);
void hex_dump(unsigned const char *buffer, int size, const char *comment,
              int print_addr_offset) {
  char ascii[17];
  int i = 0;
  ascii[16] = 0;
  printf("DUMP[%s; %d bytes]:\n", comment, size);
  while (i < size) {
    unsigned char c = buffer[i];
    if (!(i & 15)) {
      if (i) {
        printf("  %s", ascii);
        putchar('\n');
      }
      printf("  %07X  ", i + print_addr_offset);
    }
    printf(" %02X", c);
    ascii[i & 15] = (c >= 32 && c < 127) ? c : '.';
    i++;
  }
  if ((i & 15))
    ascii[i & 15] = 0;
  while ((i++ & 15))
    printf("   ");
  printf("  %s", ascii);
  putchar('\n');
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x34(%rbp)
movb   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121d <hex_dump+0xfd>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x35(%rbp)
mov    -0x34(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11b9 <hex_dump+0x99>
cmpl   $0x0,-0x34(%rbp)
je     11a5 <hex_dump+0x85>
lea    -0x30(%rbp),%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x34(%rbp),%esi
add    -0x1c(%rbp),%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzbl -0x35(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzbl -0x35(%rbp),%eax
cmp    $0x20,%eax
jl     11f1 <hex_dump+0xd1>
movzbl -0x35(%rbp),%eax
cmp    $0x7f,%eax
jge    11f1 <hex_dump+0xd1>
movzbl -0x35(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    11fe <hex_dump+0xde>
mov    $0x2e,%eax
mov    %eax,-0x3c(%rbp)
jmp    11fe <hex_dump+0xde>
mov    -0x3c(%rbp),%eax
mov    %al,%cl
mov    -0x34(%rbp),%eax
and    $0xf,%eax
cltq
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1156 <hex_dump+0x36>
mov    -0x34(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     1239 <hex_dump+0x119>
mov    -0x34(%rbp),%eax
and    $0xf,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
jmp    123e <hex_dump+0x11e>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
and    $0xf,%eax
cmp    $0x0,%eax
je     1268 <hex_dump+0x148>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    123e <hex_dump+0x11e>
lea    -0x30(%rbp),%rsi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
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    $0x38,%rsp
mov    %ecx,%r14d
mov    %esi,%r12d
mov    %rdi,%rbx
movb   $0x0,0x20(%rsp)
lea    0xebd(%rip),%rdi
mov    %rdx,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r12d,%r12d
jle    1276 <hex_dump+0x156>
movzbl (%rbx),%ebp
lea    0xeb7(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x20(%rbp),%eax
cmp    $0x5f,%al
mov    $0x2e,%eax
cmovae %eax,%ebp
mov    %bpl,0x10(%rsp)
mov    $0x1,%eax
mov    $0x1,%r15d
cmp    $0x1,%r12d
je     1247 <hex_dump+0x127>
mov    %r12d,0xc(%rsp)
mov    %r12d,%r15d
mov    %r14d,%eax
mov    %rax,0x30(%rsp)
mov    $0x1,%r13d
lea    0xe62(%rip),%rbp
jmp    11fa <hex_dump+0xda>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x20(%r14),%eax
cmp    $0x5f,%al
mov    $0x2e,%eax
cmovae %eax,%r14d
mov    %r14b,0x10(%rsp,%r12,1)
add    $0x1,%r13
cmp    %r13,%r15
je     123e <hex_dump+0x11e>
movzbl (%rbx,%r13,1),%r14d
mov    %r13,%r12
and    $0xf,%r12
jne    11d0 <hex_dump+0xb0>
lea    0xe06(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x30(%rsp),%rax
lea    (%rax,%r13,1),%esi
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d0 <hex_dump+0xb0>
mov    0xc(%rsp),%eax
and    $0xf,%eax
je     1276 <hex_dump+0x156>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
add    $0x1,%r15d
lea    0xdd0(%rip),%rbx
mov    %r15d,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
test   $0xf,%r15b
mov    %ebp,%r15d
jne    1260 <hex_dump+0x140>
lea    0xd98(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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