#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*/ asc;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ isprint(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stdout;
void buffer_dump(const void *buf, int start, size_t len) {
  char asc[20];
  int j, k;
  memset(asc, 0, sizeof(asc));
  k = 0;
  for (j = start; (size_t)j < (start + len); j++) {
    int c = ((const unsigned char *)(buf))[j];
    if (k == 0) {
      fprintf(stdout, "%04x  ", j);
    }
    fprintf(stdout, "%02x ", c);
    asc[k] = isprint(c) ? c : '.';
    k++;
    if (k == 8) {
      fprintf(stdout, " ");
    }
    if (k == 16) {
      fprintf(stdout, "  %s\n", asc);
      memset(asc, 0, sizeof(asc));
      k = 0;
    }
  }
  for (j = k; j < 16; j++) {
    fprintf(stdout, "   ");
  }
  if (k < 8) {
    fprintf(stdout, " ");
  }
  fprintf(stdout, "  %s\n", asc);
}


x86 assembly (clang, -O0):
<buffer_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
movl   $0x0,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jae    1272 <buffer_dump+0x142>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    11a8 <buffer_dump+0x78>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%edx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x3c(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11df <buffer_dump+0xaf>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    11ec <buffer_dump+0xbc>
mov    $0x2e,%eax
mov    %eax,-0x40(%rbp)
jmp    11ec <buffer_dump+0xbc>
mov    -0x40(%rbp),%eax
mov    %al,%cl
movslq -0x38(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x8,-0x38(%rbp)
jne    1223 <buffer_dump+0xf3>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpl   $0x10,-0x38(%rbp)
jne    125f <buffer_dump+0x12f>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
movl   $0x0,-0x38(%rbp)
jmp    1264 <buffer_dump+0x134>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1160 <buffer_dump+0x30>
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x10,-0x34(%rbp)
jge    12a7 <buffer_dump+0x177>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1278 <buffer_dump+0x148>
cmpl   $0x8,-0x38(%rbp)
jge    12c8 <buffer_dump+0x198>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
movslq %ebx,%rbx
add    %rbx,%r15
cmp    %rbx,%r15
jbe    123d <buffer_dump+0x10d>
mov    0x2e73(%rip),%r13
xor    %ebp,%ebp
jmp    11b6 <buffer_dump+0x86>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
xor    %ebp,%ebp
lea    0xe80(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jbe    1238 <buffer_dump+0x108>
movzbl (%r14,%rbx,1),%r12d
test   %ebp,%ebp
jne    11d3 <buffer_dump+0xa3>
mov    0x0(%r13),%edi
lea    0xe36(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe29(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12d,%edi
call   1050 <isprint@plt>
test   %rax,%rax
mov    $0x2e,%eax
cmove  %eax,%r12d
movslq %ebp,%rax
mov    %r12b,(%rsp,%rax,1)
cmp    $0xf,%ebp
je     1180 <buffer_dump+0x50>
cmp    $0x7,%ebp
jne    1230 <buffer_dump+0x100>
mov    0x0(%r13),%edi
lea    0xdf9(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x8,%ebp
jmp    11a9 <buffer_dump+0x79>
nopl   (%rax)
add    $0x1,%ebp
jmp    11a9 <buffer_dump+0x79>
cmp    $0xf,%ebp
jg     127a <buffer_dump+0x14a>
mov    $0x10,%ebx
mov    0x2d97(%rip),%r14
lea    0xdc3(%rip),%r15
mov    (%r14),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffff,%ebx
cmp    %ebx,%ebp
jne    1250 <buffer_dump+0x120>
cmp    $0x7,%ebp
jg     127a <buffer_dump+0x14a>
mov    (%r14),%edi
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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