#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
char toAscii(char const);
void dump_bytes(FILE *outstream, const void *_buf, size_t size) {
  const char *buf = _buf;
  size_t i, ascii_cnt = 0;
  char ascii[17] = {
      0,
  };
  for (i = 0; i < size; i++) {
    if (i % 16 == 0) {
      if (i != 0) {
        fprintf(outstream, "  |%s|\n", ascii);
        ascii[0] = 0;
        ascii_cnt = 0;
      }
      fprintf(outstream, "[%04X]: ", (unsigned int)i);
    }
    fprintf(outstream, " %02X", buf[i] & 0xFF);
    ascii[ascii_cnt] = toAscii(buf[i]);
    ascii[ascii_cnt + 1] = 0;
    ascii_cnt++;
  }
  if (ascii[0]) {
    if (size % 16) {
      for (i = 0; i < 16 - (size % 16); i++)
        fprintf(outstream, "   ");
    }
    fprintf(outstream, "  |%s|\n", ascii);
  }
}


x86 assembly (clang, -O0):
<dump_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1030 <memset@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1236 <dump_bytes+0x106>
mov    -0x28(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11d1 <dump_bytes+0xa1>
cmpq   $0x0,-0x28(%rbp)
je     11b9 <dump_bytes+0x89>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movb   $0x0,-0x50(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <toAscii@plt>
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x30(%rbp),%rax
movb   $0x0,-0x4f(%rbp,%rax,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116c <dump_bytes+0x3c>
cmpb   $0x0,-0x50(%rbp)
je     12b5 <dump_bytes+0x185>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     129f <dump_bytes+0x16f>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rdx
and    $0xf,%rdx
mov    $0x10,%ecx
sub    %rdx,%rcx
cmp    %rcx,%rax
jae    129a <dump_bytes+0x16a>
mov    -0x8(%rbp),%rdi
lea    0xd95(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    125a <dump_bytes+0x12a>
jmp    129f <dump_bytes+0x16f>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x50,%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   %rdx,%rdx
je     125e <dump_bytes+0x12e>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xea5(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
movzbl (%r15),%edx
lea    0xe9a(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
movsbl (%r15),%edi
call   1040 <toAscii@plt>
mov    %al,(%rsp)
movb   $0x0,0x1(%rsp)
cmp    $0x1,%rbx
je     121a <dump_bytes+0xea>
mov    $0x1,%ebp
lea    0xe69(%rip),%r12
mov    $0x1,%r13d
jmp    11e1 <dump_bytes+0xb1>
movzbl (%r15,%r13,1),%edx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
movsbl (%r15,%r13,1),%edi
call   1040 <toAscii@plt>
mov    %al,(%rsp,%rbp,1)
movb   $0x0,0x1(%rsp,%rbp,1)
add    $0x1,%rbp
add    $0x1,%r13
cmp    %r13,%rbx
je     1217 <dump_bytes+0xe7>
test   $0xf,%r13b
jne    11b0 <dump_bytes+0x80>
mov    %r14,%rdi
lea    0xe0f(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
movb   $0x0,(%rsp)
mov    %r14,%rdi
lea    0xdff(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %ebp,%ebp
jmp    11b0 <dump_bytes+0x80>
mov    (%rsp),%al
test   %al,%al
je     125e <dump_bytes+0x12e>
and    $0xf,%rbx
je     124a <dump_bytes+0x11a>
add    $0xfffffffffffffff0,%rbx
lea    0xde8(%rip),%rbp
nop
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   1050 <fwrite@plt>
inc    %rbx
jne    1230 <dump_bytes+0x100>
lea    0xdaf(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <fprintf@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 = [9 x i8] c"[%04X]: \00"
@.str.2 = [6 x i8] c" %02X\00"
@.str.3 = [4 x i8] c" \00"
define void @dump_bytes(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca [17 x i8]
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%11 = load i8*, i8** %5
store i8* %11, i8** %7
store i64 0, i64* %9
%12 = bitcast [17 x i8]* %10 to i8*
store i64 0, i64* %8
br label %13
13: ; preds = %55, %3
%14 = load i64, i64* %8
%15 = load i64, i64* %6
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %58
17: ; preds = %13
%18 = load i64, i64* %8
%19 = urem i64 %18, 16
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i64, i64* %8
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32*, i32** %4
%26 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
store i8 0, i8* %28
store i64 0, i64* %9
br label %29
29: ; preds = %24, %21
%30 = load i32*, i32** %4
%31 = load i64, i64* %8
%32 = trunc i64 %31 to i32
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %29, %17
%35 = load i32*, i32** %4
%36 = load i8*, i8** %7
%37 = load i64, i64* %8
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = and i32 %40, 255
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load i8*, i8** %7
%44 = load i64, i64* %8
%45 = getelementptr inbounds i8, i8* %43, i64 %44
%46 = load i8, i8* %45
%47 = call signext i8 @toAscii(i8 signext %46)
%48 = load i64, i64* %9
%49 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 %48
store i8 %47, i8* %49
%50 = load i64, i64* %9
%51 = add i64 %50, 1
%52 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 %51
store i8 0, i8* %52
%53 = load i64, i64* %9
%54 = add i64 %53, 1
store i64 %54, i64* %9
br label %55
55: ; preds = %34
%56 = load i64, i64* %8
%57 = add i64 %56, 1
store i64 %57, i64* %8
br label %13
58: ; preds = %13
%59 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%60 = load i8, i8* %59
%61 = icmp ne i8 %60, 0
br i1 %61, label %62, label %84
62: ; preds = %58
%63 = load i64, i64* %6
%64 = urem i64 %63, 16
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %80
66: ; preds = %62
store i64 0, i64* %8
br label %67
67: ; preds = %76, %66
%68 = load i64, i64* %8
%69 = load i64, i64* %6
%70 = urem i64 %69, 16
%71 = sub i64 16, %70
%72 = icmp ult i64 %68, %71
br i1 %72, label %73, label %79
73: ; preds = %67
%74 = load i32*, i32** %4
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %74, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %76
76: ; preds = %73
%77 = load i64, i64* %8
%78 = add i64 %77, 1
store i64 %78, i64* %8
br label %67
79: ; preds = %67
br label %80
80: ; preds = %79, %62
%81 = load i32*, i32** %4
%82 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%83 = call i32 (i32*, i8*, ...) @fprintf(i32* %81, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %82)
br label %84
84: ; preds = %80, %58
ret void
}

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