#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 */
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int /*<<< orphan*/);
char *string_printable(char *in) {
  static char out[1024];
  char octal[1024];
  char *ret;
  memset(out, '\0', 1024);
  ret = out;
  while (*in) {
    if (*in >= 32 && *in != 127) {
      *ret++ = *in;
    } else if (*in == '\\') {
      *ret++ = '\\';
      *ret++ = '\\';
    } else if (*in == '\a') {
      *ret++ = '\\';
      *ret++ = 'a';
    } else if (*in == '\b') {
      *ret++ = '\\';
      *ret++ = 'b';
    } else if (*in == '\n') {
      *ret++ = '\\';
      *ret++ = 'n';
    } else if (*in == '\r') {
      *ret++ = '\\';
      *ret++ = 'r';
    } else {
      snprintf(octal, 1024, "\\%03o", (unsigned char)*in);
      strncat(ret, octal, strlen(octal));
      ret += strlen(octal);
    }
    in++;
  }
  return out;
}


x86 assembly (clang, -O0):
<string_printable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2efa(%rip),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    0x2ee7(%rip),%rax
mov    %rax,-0x418(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     13c0 <string_printable+0x280>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jl     11bf <string_printable+0x7f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7f,%eax
je     11bf <string_printable+0x7f>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x418(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x418(%rbp)
mov    %cl,(%rax)
jmp    13af <string_printable+0x26f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1204 <string_printable+0xc4>
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x5c,(%rax)
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x5c,(%rax)
jmp    13aa <string_printable+0x26a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7,%eax
jne    1249 <string_printable+0x109>
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x5c,(%rax)
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x61,(%rax)
jmp    13a5 <string_printable+0x265>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x8,%eax
jne    128e <string_printable+0x14e>
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x5c,(%rax)
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x62,(%rax)
jmp    13a0 <string_printable+0x260>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    12d3 <string_printable+0x193>
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x5c,(%rax)
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x6e,(%rax)
jmp    139b <string_printable+0x25b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    1318 <string_printable+0x1d8>
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x5c,(%rax)
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x72,(%rax)
jmp    1396 <string_printable+0x256>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0x400,%esi
lea    0xcd1(%rip),%rdx
movzbl (%rax),%ecx
call   1040 <snprintf@plt>
mov    -0x418(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x428(%rbp),%rdi
mov    -0x420(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x418(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x418(%rbp)
jmp    139b <string_printable+0x25b>
jmp    13a0 <string_printable+0x260>
jmp    13a5 <string_printable+0x265>
jmp    13aa <string_printable+0x26a>
jmp    13af <string_printable+0x26f>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1170 <string_printable+0x30>
lea    0x2c89(%rip),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_printable>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
lea    0x2ef6(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    (%rbx),%al
test   %al,%al
je     1230 <string_printable+0xf0>
add    $0x1,%rbx
lea    0xe9e(%rip),%r15
mov    %rsp,%r12
lea    0xe78(%rip),%r13
jmp    11a6 <string_printable+0x66>
nopw   0x0(%rax,%rax,1)
mov    %al,(%r14)
add    $0x1,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1230 <string_printable+0xf0>
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
jae    1190 <string_printable+0x50>
lea    -0x7(%rax),%ecx
cmp    $0x6,%cl
ja     11db <string_printable+0x9b>
movzbl %cl,%ecx
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
movw   $0x615c,(%r14)
add    $0x2,%r14
jmp    1197 <string_printable+0x57>
movw   $0x625c,(%r14)
add    $0x2,%r14
jmp    1197 <string_printable+0x57>
movzbl %al,%ecx
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1040 <snprintf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r14
jmp    1197 <string_printable+0x57>
movw   $0x6e5c,(%r14)
add    $0x2,%r14
jmp    1197 <string_printable+0x57>
movw   $0x725c,(%r14)
add    $0x2,%r14
jmp    1197 <string_printable+0x57>
lea    0x2e19(%rip),%rax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@string_printable.out = internal global [1024 x i8] zeroinitializer
@.str = [6 x i8] c"\\%03o\00"
define i8* @string_printable(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @string_printable.out, i64 0, i64 0), i8 signext 0, i32 1024)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @string_printable.out, i64 0, i64 0), i8** %4
br label %6
6: ; preds = %95, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %98
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp sge i32 %13, 32
br i1 %14, label %15, label %25
15: ; preds = %10
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 127
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %2
%22 = load i8, i8* %21
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
store i8 %22, i8* %23
br label %95
25: ; preds = %15, %10
%26 = load i8*, i8** %2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 92
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
store i8 92, i8* %31
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %4
store i8 92, i8* %33
br label %94
35: ; preds = %25
%36 = load i8*, i8** %2
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 7
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %4
store i8 92, i8* %41
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %4
store i8 97, i8* %43
br label %93
45: ; preds = %35
%46 = load i8*, i8** %2
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 8
br i1 %49, label %50, label %55
50: ; preds = %45
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %4
store i8 92, i8* %51
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %4
store i8 98, i8* %53
br label %92
55: ; preds = %45
%56 = load i8*, i8** %2
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 10
br i1 %59, label %60, label %65
60: ; preds = %55
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %4
store i8 92, i8* %61
%63 = load i8*, i8** %4
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %4
store i8 110, i8* %63
br label %91
65: ; preds = %55
%66 = load i8*, i8** %2
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 13
br i1 %69, label %70, label %75
70: ; preds = %65
%71 = load i8*, i8** %4
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %4
store i8 92, i8* %71
%73 = load i8*, i8** %4
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** %4
store i8 114, i8* %73
br label %90
75: ; preds = %65
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%77 = load i8*, i8** %2
%78 = load i8, i8* %77
%79 = call i32 @snprintf(i8* %76, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %78)
%80 = load i8*, i8** %4
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%83 = call i32 @strlen(i8* %82)
%84 = call i32 @strncat(i8* %80, i8* %81, i32 %83)
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%86 = call i32 @strlen(i8* %85)
%87 = load i8*, i8** %4
%88 = sext i32 %86 to i64
%89 = getelementptr inbounds i8, i8* %87, i64 %88
store i8* %89, i8** %4
br label %90
90: ; preds = %75, %70
br label %91
91: ; preds = %90, %60
br label %92
92: ; preds = %91, %50
br label %93
93: ; preds = %92, %40
br label %94
94: ; preds = %93, %30
br label %95
95: ; preds = %94, %20
%96 = load i8*, i8** %2
%97 = getelementptr inbounds i8, i8* %96, i32 1
store i8* %97, i8** %2
br label %6
98: ; preds = %6
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @string_printable.out, i64 0, i64 0)
}

LLVM IR (-O2):
@string_printable.out = internal global [1024 x i8] zeroinitializer
@.str = [6 x i8] c"\\%03o\00"
define i8* @string_printable(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @string_printable.out, i64 0, i64 0), i8 signext 0, i32 1024)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %40, label %7
7: ; preds = %1, %35
%8 = phi i8 [ %38, %35 ], [ %5, %1 ]
%9 = phi i8* [ %36, %35 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @string_printable.out, i64 0, i64 0), %1 ]
%10 = phi i8* [ %37, %35 ], [ %0, %1 ]
%11 = add i8 %8, -127
%12 = icmp ult i8 %11, -95
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %8, i8* %9
br label %35
15: ; preds = %7
switch i8 %8, label %28 [
i8 13, label %25
i8 7, label %16
i8 8, label %19
i8 10, label %22
]
16: ; preds = %15
%17 = getelementptr inbounds i8, i8* %9, i64 1
store i8 92, i8* %9
%18 = getelementptr inbounds i8, i8* %9, i64 2
store i8 97, i8* %17
br label %35
19: ; preds = %15
%20 = getelementptr inbounds i8, i8* %9, i64 1
store i8 92, i8* %9
%21 = getelementptr inbounds i8, i8* %9, i64 2
store i8 98, i8* %20
br label %35
22: ; preds = %15
%23 = getelementptr inbounds i8, i8* %9, i64 1
store i8 92, i8* %9
%24 = getelementptr inbounds i8, i8* %9, i64 2
store i8 110, i8* %23
br label %35
25: ; preds = %15
%26 = getelementptr inbounds i8, i8* %9, i64 1
store i8 92, i8* %9
%27 = getelementptr inbounds i8, i8* %9, i64 2
store i8 114, i8* %26
br label %35
28: ; preds = %15
%29 = call i32 @snprintf(i8* %3, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %8)
%30 = call i32 @strlen(i8* %3)
%31 = call i32 @strncat(i8* %9, i8* %3, i32 %30)
%32 = call i32 @strlen(i8* %3)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %9, i64 %33
br label %35
35: ; preds = %19, %25, %28, %22, %16, %13
%36 = phi i8* [ %14, %13 ], [ %18, %16 ], [ %21, %19 ], [ %24, %22 ], [ %27, %25 ], [ %34, %28 ]
%37 = getelementptr inbounds i8, i8* %10, i64 1
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %7
40: ; preds = %35, %1
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @string_printable.out, i64 0, i64 0)
}