#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(char const);
int /*<<< orphan*/ printf(char *, char const);
int /*<<< orphan*/ putchar(char const);
void c_prt(const void *p, size_t len) {
  const char *s = (const char *)p;
  printf("%lu\t", len);
  for (size_t i = 0; i != len; ++i) {
    if (isprint(s[i]))
      putchar(s[i]);
    else
      printf("\033\[31m\\%02X\033\[0m", s[i]);
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<c_prt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
lea    0xead(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11d0 <c_prt+0xa0>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11a2 <c_prt+0x72>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
jmp    11ba <c_prt+0x8a>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
lea    0xe54(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
jmp    11bf <c_prt+0x8f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1163 <c_prt+0x33>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_prt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
movsbl %r14b,%esi
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
test   %r14,%r14
je     1192 <c_prt+0x62>
xor    %ebx,%ebx
lea    0xea9(%rip),%r15
jmp    1174 <c_prt+0x44>
xchg   %ax,%ax
movsbl %cl,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     1192 <c_prt+0x62>
movsbl (%r12,%rbx,1),%edi
call   1050 <isprint@plt>
movzbl (%r12,%rbx,1),%ecx
test   %rax,%rax
je     1160 <c_prt+0x30>
movsbl %cl,%edi
call   1030 <putchar@plt>
jmp    116b <c_prt+0x3b>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%lu\09\00"
@.str.1 = [15 x i8] c"\1B[31m\\%02X\1B[0m\00"
define void @c_prt(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
%8 = load i64, i64* %4
%9 = trunc i64 %8 to i8
%10 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %9)
store i64 0, i64* %6
br label %11
11: ; preds = %35, %2
%12 = load i64, i64* %6
%13 = load i64, i64* %4
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @isprint(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @putchar(i8 signext %26)
br label %34
28: ; preds = %15
%29 = load i8*, i8** %5
%30 = load i64, i64* %6
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 signext %32)
br label %34
34: ; preds = %28, %22
br label %35
35: ; preds = %34
%36 = load i64, i64* %6
%37 = add i64 %36, 1
store i64 %37, i64* %6
br label %11
38: ; preds = %11
%39 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lu\09\00"
@.str.1 = [15 x i8] c"\1B[31m\\%02X\1B[0m\00"
define void @c_prt(i8* nocapture %0, i64 %1) {
%3 = trunc i64 %1 to i8
%4 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %3)
%5 = icmp eq i64 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %19, %2
%7 = tail call i32 @putchar(i8 signext 10)
ret void
8: ; preds = %2, %19
%9 = phi i64 [ %20, %19 ], [ 0, %2 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @isprint(i8 signext %11)
%13 = icmp eq i64 %12, 0
%14 = load i8, i8* %10
br i1 %13, label %17, label %15
15: ; preds = %8
%16 = tail call i32 @putchar(i8 signext %14)
br label %19
17: ; preds = %8
%18 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 signext %14)
br label %19
19: ; preds = %15, %17
%20 = add nuw i64 %9, 1
%21 = icmp eq i64 %20, %1
br i1 %21, label %6, label %8
}