#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 s_prt(const void *p, size_t len) {
  const char *s = (const char *)p;
  putchar('"');
  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('"');
  printf("(%lu)", len);
}


x86 assembly (clang, -O0):
<s_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    $0x22,%edi
call   1030 <putchar@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11c7 <s_prt+0x97>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     1199 <s_prt+0x69>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
jmp    11b1 <s_prt+0x81>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
lea    0xe58(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
jmp    11b6 <s_prt+0x86>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115a <s_prt+0x2a>
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rax
lea    0xe33(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

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

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

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