#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(unsigned int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stdout;
void mdb_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; j < start + len; j++) {
    unsigned int c = ((const unsigned char *)(buf))[j];
    if (k == 0) {
      fprintf(stdout, "%04x  ", j);
    }
    fprintf(stdout, "%02x ", (unsigned char)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):
<mdb_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    1275 <mdb_buffer_dump+0x145>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    11a8 <mdb_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),%eax
movzbl %al,%edx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x3c(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11e2 <mdb_buffer_dump+0xb2>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    11ef <mdb_buffer_dump+0xbf>
mov    $0x2e,%eax
mov    %eax,-0x40(%rbp)
jmp    11ef <mdb_buffer_dump+0xbf>
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    1226 <mdb_buffer_dump+0xf6>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpl   $0x10,-0x38(%rbp)
jne    1262 <mdb_buffer_dump+0x132>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xdc9(%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    1267 <mdb_buffer_dump+0x137>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1160 <mdb_buffer_dump+0x30>
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x10,-0x34(%rbp)
jge    12aa <mdb_buffer_dump+0x17a>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    127b <mdb_buffer_dump+0x14b>
cmpl   $0x8,-0x38(%rbp)
jge    12cb <mdb_buffer_dump+0x19b>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xd2e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdb_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 <mdb_buffer_dump+0x10d>
mov    0x2e73(%rip),%r13
xor    %ebp,%ebp
jmp    11b6 <mdb_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 <mdb_buffer_dump+0x108>
movzbl (%r14,%rbx,1),%r12d
test   %ebp,%ebp
jne    11d3 <mdb_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 <mdb_buffer_dump+0x50>
cmp    $0x7,%ebp
jne    1230 <mdb_buffer_dump+0x100>
mov    0x0(%r13),%edi
lea    0xdf9(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x8,%ebp
jmp    11a9 <mdb_buffer_dump+0x79>
nopl   (%rax)
add    $0x1,%ebp
jmp    11a9 <mdb_buffer_dump+0x79>
cmp    $0xf,%ebp
jg     127a <mdb_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 <mdb_buffer_dump+0x120>
cmp    $0x7,%ebp
jg     127a <mdb_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 @mdb_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 = %70, %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 %73
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 = trunc i32 %37 to i8
%39 = zext i8 %38 to i32
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %10
%42 = call i64 @isprint(i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %35
%45 = load i32, i32* %10
br label %47
46: ; preds = %35
br label %47
47: ; preds = %46, %44
%48 = phi i32 [ %45, %44 ], [ 46, %46 ]
%49 = trunc i32 %48 to i8
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %51
store i8 %49, i8* %52
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = icmp eq i32 %55, 8
br i1 %56, label %57, label %60
57: ; preds = %47
%58 = load i32, i32* @stdout
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %57, %47
%61 = load i32, i32* %9
%62 = icmp eq i32 %61, 16
br i1 %62, label %63, label %69
63: ; preds = %60
%64 = load i32, i32* @stdout
%65 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %65)
%67 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%68 = call i32 @memset(i8* %67, i32 0, i32 20)
store i32 0, i32* %9
br label %69
69: ; preds = %63, %60
br label %70
70: ; preds = %69
%71 = load i32, i32* %8
%72 = add nsw i32 %71, 1
store i32 %72, i32* %8
br label %14
73: ; preds = %14
%74 = load i32, i32* %9
store i32 %74, i32* %8
br label %75
75: ; preds = %81, %73
%76 = load i32, i32* %8
%77 = icmp slt i32 %76, 16
br i1 %77, label %78, label %84
78: ; preds = %75
%79 = load i32, i32* @stdout
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %81
81: ; preds = %78
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
br label %75
84: ; preds = %75
%85 = load i32, i32* %9
%86 = icmp slt i32 %85, 8
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = load i32, i32* @stdout
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %90
90: ; preds = %87, %84
%91 = load i32, i32* @stdout
%92 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %92)
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 @mdb_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
}