#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 */
scalar_t__ isprint(int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ putchar(char);
void VisibleDumpBuffer(char *buf, int len) {
  char *cp;
  for (cp = buf; cp < buf + len; cp++) {
    if (isprint((int)(*cp)) || *cp == ' ')
      putchar(*cp);
    else if (*cp == '\n') {
      putchar('\\');
      putchar('n');
    } else if (*cp == '\r') {
      putchar('\\');
      putchar('r');
    } else if (*cp == '\b') {
      putchar('\\');
      putchar('b');
    } else if (*cp < ' ') {
      putchar('\\');
      putchar('^');
      putchar('@' + *cp);
    } else
      printf("\\0x%02x", *cp);
  }
}


x86 assembly (clang, -O0):
<VisibleDumpBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    1289 <VisibleDumpBuffer+0x159>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
jne    1185 <VisibleDumpBuffer+0x55>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1196 <VisibleDumpBuffer+0x66>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    1273 <VisibleDumpBuffer+0x143>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11bf <VisibleDumpBuffer+0x8f>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x6e,%edi
call   1030 <putchar@plt>
jmp    126e <VisibleDumpBuffer+0x13e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    11e8 <VisibleDumpBuffer+0xb8>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x72,%edi
call   1030 <putchar@plt>
jmp    1269 <VisibleDumpBuffer+0x139>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x8,%eax
jne    1211 <VisibleDumpBuffer+0xe1>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x62,%edi
call   1030 <putchar@plt>
jmp    1264 <VisibleDumpBuffer+0x134>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jge    124c <VisibleDumpBuffer+0x11c>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x5e,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0x40,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    125f <VisibleDumpBuffer+0x12f>
mov    -0x18(%rbp),%rax
lea    0xda9(%rip),%rdi
movsbl (%rax),%esi
call   1040 <printf@plt>
jmp    1264 <VisibleDumpBuffer+0x134>
jmp    1269 <VisibleDumpBuffer+0x139>
jmp    126e <VisibleDumpBuffer+0x13e>
jmp    1273 <VisibleDumpBuffer+0x143>
jmp    1278 <VisibleDumpBuffer+0x148>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1147 <VisibleDumpBuffer+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VisibleDumpBuffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    120c <VisibleDumpBuffer+0xdc>
mov    %rdi,%rbx
movslq %esi,%r15
add    %rdi,%r15
lea    0xf14(%rip),%r14
lea    0xea9(%rip),%r12
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1050 <isprint@plt>
movzbl (%rbx),%ecx
test   %rax,%rax
je     1190 <VisibleDumpBuffer+0x60>
movsbl %cl,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %r15,%rbx
jb     1160 <VisibleDumpBuffer+0x30>
jmp    120c <VisibleDumpBuffer+0xdc>
cs nopw 0x0(%rax,%rax,1)
lea    -0x8(%rcx),%eax
cmp    $0x18,%al
ja     11b4 <VisibleDumpBuffer+0x84>
movzbl %al,%eax
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x62,%edi
jmp    1173 <VisibleDumpBuffer+0x43>
cmp    $0x1f,%cl
jg     11fc <VisibleDumpBuffer+0xcc>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x5e,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x40,%al
movsbl %al,%edi
jmp    1173 <VisibleDumpBuffer+0x43>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x6e,%edi
jmp    1173 <VisibleDumpBuffer+0x43>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x72,%edi
jmp    1173 <VisibleDumpBuffer+0x43>
movsbl %cl,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    1178 <VisibleDumpBuffer+0x48>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"\\0x%02x\00"
define void @VisibleDumpBuffer(i8* %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %38
6: ; preds = %2, %35
%7 = phi i8* [ %36, %35 ], [ %0, %2 ]
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = tail call i64 @isprint(i32 %9)
%11 = icmp eq i64 %10, 0
%12 = load i8, i8* %7
br i1 %11, label %13, label %14
13: ; preds = %6
switch i8 %12, label %25 [
i8 32, label %14
i8 10, label %16
i8 13, label %19
i8 8, label %22
]
14: ; preds = %6, %13
%15 = tail call i32 @putchar(i8 signext %12)
br label %35
16: ; preds = %13
%17 = tail call i32 @putchar(i8 signext 92)
%18 = tail call i32 @putchar(i8 signext 110)
br label %35
19: ; preds = %13
%20 = tail call i32 @putchar(i8 signext 92)
%21 = tail call i32 @putchar(i8 signext 114)
br label %35
22: ; preds = %13
%23 = tail call i32 @putchar(i8 signext 92)
%24 = tail call i32 @putchar(i8 signext 98)
br label %35
25: ; preds = %13
%26 = icmp slt i8 %12, 32
br i1 %26, label %27, label %33
27: ; preds = %25
%28 = tail call i32 @putchar(i8 signext 92)
%29 = tail call i32 @putchar(i8 signext 94)
%30 = load i8, i8* %7
%31 = add i8 %30, 64
%32 = tail call i32 @putchar(i8 signext %31)
br label %35
33: ; preds = %25
%34 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 signext %12)
br label %35
35: ; preds = %14, %19, %27, %33, %22, %16
%36 = getelementptr inbounds i8, i8* %7, i64 1
%37 = icmp ult i8* %36, %4
br i1 %37, label %6, label %38
38: ; preds = %35, %2
ret void
}