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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ isblank(char);
scalar_t__ isprint(char);
char *printablestring(char *s, int len) {
  static char b[1024];
  assert(len < (int)sizeof(b));
  for (int i = 0; i < len; i++) {
    if (s[i] == 0) {
      b[i] = '$';
    } else if (isblank(s[i])) {
      b[i] = '_';
    } else if (isprint(s[i])) {
      b[i] = s[i];
    } else {
      b[i] = '?';
    }
  }
  b[len - 1] = 0;
  return b;
}


x86 assembly (clang, -O0):
<printablestring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x400,-0xc(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1223 <printablestring+0xf3>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    118f <printablestring+0x5f>
movslq -0x10(%rbp),%rcx
lea    0x2eca(%rip),%rax
movb   $0x24,(%rax,%rcx,1)
jmp    1210 <printablestring+0xe0>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isblank@plt>
cmp    $0x0,%rax
je     11be <printablestring+0x8e>
movslq -0x10(%rbp),%rcx
lea    0x2e9b(%rip),%rax
movb   $0x5f,(%rax,%rcx,1)
jmp    120b <printablestring+0xdb>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11f7 <printablestring+0xc7>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x10(%rbp),%rcx
lea    0x2e61(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    1206 <printablestring+0xd6>
movslq -0x10(%rbp),%rcx
lea    0x2e4e(%rip),%rax
movb   $0x3f,(%rax,%rcx,1)
jmp    120b <printablestring+0xdb>
jmp    1210 <printablestring+0xe0>
jmp    1215 <printablestring+0xe5>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115a <printablestring+0x2a>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e1d(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e12(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printablestring>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %edi,%edi
cmp    $0x400,%esi
setl   %dil
call   1040 <assert@plt>
test   %r14d,%r14d
jle    11af <printablestring+0x7f>
mov    %r14d,%r15d
xor    %ebp,%ebp
lea    0x2ef0(%rip),%r12
jmp    1180 <printablestring+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x24,%cl
mov    %cl,0x0(%rbp,%r12,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     11af <printablestring+0x7f>
movzbl (%rbx,%rbp,1),%eax
test   %al,%al
je     1170 <printablestring+0x40>
movsbl %al,%edi
call   1030 <isblank@plt>
mov    $0x5f,%cl
test   %rax,%rax
jne    1172 <printablestring+0x42>
movsbl (%rbx,%rbp,1),%edi
call   1050 <isprint@plt>
test   %rax,%rax
je     11ab <printablestring+0x7b>
movzbl (%rbx,%rbp,1),%ecx
jmp    1172 <printablestring+0x42>
mov    $0x3f,%cl
jmp    1172 <printablestring+0x42>
movslq %r14d,%rcx
lea    0x2e97(%rip),%rax
movb   $0x0,-0x1(%rcx,%rax,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@printablestring.b = internal global [1024 x i8] zeroinitializer
define i8* @printablestring(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 1024
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
store i32 0, i32* %5
br label %10
10: ; preds = %62, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %65
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* @printablestring.b, i64 0, i64 %24
store i8 36, i8* %25
br label %61
26: ; preds = %14
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i64 @isblank(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %26
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* @printablestring.b, i64 0, i64 %36
store i8 95, i8* %37
br label %60
38: ; preds = %26
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = call i64 @isprint(i8 signext %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %38
%47 = load i8*, i8** %3
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* @printablestring.b, i64 0, i64 %53
store i8 %51, i8* %54
br label %59
55: ; preds = %38
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* @printablestring.b, i64 0, i64 %57
store i8 63, i8* %58
br label %59
59: ; preds = %55, %46
br label %60
60: ; preds = %59, %34
br label %61
61: ; preds = %60, %22
br label %62
62: ; preds = %61
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %10
65: ; preds = %10
%66 = load i32, i32* %4
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* @printablestring.b, i64 0, i64 %68
store i8 0, i8* %69
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @printablestring.b, i64 0, i64 0)
}

LLVM IR (-O2):
@printablestring.b = internal global [1024 x i8] zeroinitializer
define i8* @printablestring(i8* nocapture %0, i32 %1) {
%3 = icmp slt i32 %1, 1024
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = zext i32 %1 to i64
br label %13
9: ; preds = %27, %2
%10 = add nsw i32 %1, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* @printablestring.b, i64 0, i64 %11
store i8 0, i8* %12
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @printablestring.b, i64 0, i64 0)
13: ; preds = %7, %27
%14 = phi i64 [ 0, %7 ], [ %30, %27 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %13
%19 = tail call i64 @isblank(i8 signext %16)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i8, i8* %15
%23 = tail call i64 @isprint(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = load i8, i8* %15
br label %27
27: ; preds = %21, %18, %13, %25
%28 = phi i8 [ %26, %25 ], [ 36, %13 ], [ 95, %18 ], [ 63, %21 ]
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* @printablestring.b, i64 0, i64 %14
store i8 %28, i8* %29
%30 = add nuw nsw i64 %14, 1
%31 = icmp eq i64 %30, %8
br i1 %31, label %9, label %13
}