#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 *, ...);
char to_ascii(char const);
void dump_bytes(const char *buf, size_t size) {
  size_t i, ascii_cnt = 0;
  char ascii[17] = {
      0,
  };
  for (i = 0; i < size; i++) {
    if (i % 16 == 0) {
      if (i != 0) {
        printf("  |%s|\n", ascii);
        ascii[0] = 0;
        ascii_cnt = 0;
      }
      printf("%04X:", (unsigned int)i);
    }
    printf(" %02X", buf[i] & 0xFF);
    ascii[ascii_cnt] = to_ascii(buf[i]);
    ascii[ascii_cnt + 1] = 0;
    ascii_cnt++;
  }
  if (ascii[0]) {
    if (size % 16)
      for (i = 0; i < 16 - (size % 16); i++)
        printf("   ");
    printf("  |%s|\n", ascii);
  }
}


x86 assembly (clang, -O0):
<dump_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1050 <memset@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    121e <dump_bytes+0xee>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11bd <dump_bytes+0x8d>
cmpq   $0x0,-0x18(%rbp)
je     11a9 <dump_bytes+0x79>
lea    -0x40(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x40(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <to_ascii@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
movb   $0x0,-0x3f(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1160 <dump_bytes+0x30>
cmpb   $0x0,-0x40(%rbp)
je     1295 <dump_bytes+0x165>
mov    -0x10(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     1283 <dump_bytes+0x153>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rdx
and    $0xf,%rdx
mov    $0x10,%ecx
sub    %rdx,%rcx
cmp    %rcx,%rax
jae    127e <dump_bytes+0x14e>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1242 <dump_bytes+0x112>
jmp    1283 <dump_bytes+0x153>
lea    -0x40(%rbp),%rsi
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
test   %rsi,%rsi
je     1250 <dump_bytes+0x130>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xeb8(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r14),%esi
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl (%r14),%edi
call   1030 <to_ascii@plt>
mov    %al,(%rsp)
movb   $0x0,0x1(%rsp)
cmp    $0x1,%rbx
je     1210 <dump_bytes+0xf0>
mov    $0x1,%r12d
lea    0xe75(%rip),%r13
lea    0xe74(%rip),%rbp
mov    $0x1,%r15d
jmp    11e0 <dump_bytes+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r14,%r15,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl (%r14,%r15,1),%edi
call   1030 <to_ascii@plt>
mov    %al,(%rsp,%r12,1)
movb   $0x0,0x1(%rsp,%r12,1)
add    $0x1,%r12
add    $0x1,%r15
cmp    %r15,%rbx
je     120d <dump_bytes+0xed>
test   $0xf,%r15b
jne    11b0 <dump_bytes+0x90>
lea    0xe13(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0x0,(%rsp)
mov    %r13,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %r12d,%r12d
jmp    11b0 <dump_bytes+0x90>
mov    (%rsp),%al
test   %al,%al
je     1250 <dump_bytes+0x130>
and    $0xf,%rbx
je     123f <dump_bytes+0x11f>
add    $0xfffffffffffffff0,%rbx
lea    0xdef(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
inc    %rbx
jne    1230 <dump_bytes+0x110>
lea    0xdba(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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