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

/* Variables and functions */
scalar_t__ isprint(char const);
int /*<<< orphan*/ sprintf(unsigned char *, char *, char const);
const char *firetalk_printable(const char *const str) {
  static unsigned char out[256];
  int s, o;
  for (o = s = 0; (str[s] != 0) && (o < sizeof(out) - 4); s++)
    if (isprint(str[s]) && (((s != 0) && isprint(str[s - 1])) ||
                            ((str[s + 1] != 0) && isprint(str[s + 1]))))
      out[o++] = str[s];
    else {
      sprintf(out + o, "\\x%02X", str[s]);
      o += 4;
    }
  out[o] = 0;
  return (out);
}


x86 assembly (clang, -O0):
<firetalk_printable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1164 <firetalk_printable+0x44>
movslq -0x10(%rbp),%rax
cmp    $0xfc,%rax
setb   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1174 <firetalk_printable+0x54>
jmp    125d <firetalk_printable+0x13d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isprint@plt>
cmp    $0x0,%rax
je     121b <firetalk_printable+0xfb>
cmpl   $0x0,-0xc(%rbp)
je     11b9 <firetalk_printable+0x99>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isprint@plt>
cmp    $0x0,%rax
jne    11f3 <firetalk_printable+0xd3>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     121b <firetalk_printable+0xfb>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isprint@plt>
cmp    $0x0,%rax
je     121b <firetalk_printable+0xfb>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2e2d(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    124a <firetalk_printable+0x12a>
movslq -0x10(%rbp),%rax
lea    0x2e1a(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
lea    0xdc8(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    124f <firetalk_printable+0x12f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <firetalk_printable+0x1a>
movslq -0x10(%rbp),%rcx
lea    0x2dd8(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2dcd(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<firetalk_printable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1230 <firetalk_printable+0x110>
mov    %rdi,%r15
movsbl %al,%edi
call   1030 <isprint@plt>
test   %rax,%rax
je     116a <firetalk_printable+0x4a>
mov    0x1(%r15),%al
test   %al,%al
je     116a <firetalk_printable+0x4a>
movsbl %al,%edi
call   1030 <isprint@plt>
test   %rax,%rax
je     116a <firetalk_printable+0x4a>
mov    (%r15),%al
mov    %al,0x2edd(%rip)
mov    $0x1,%eax
jmp    1186 <firetalk_printable+0x66>
movsbl (%r15),%edx
lea    0x2ecb(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1040 <sprintf@plt>
mov    $0x4,%eax
mov    0x1(%r15),%cl
test   %cl,%cl
je     1232 <firetalk_printable+0x112>
lea    0x1(%r15),%rbx
mov    $0x2,%r13d
lea    0x2e9d(%rip),%r12
lea    0xe56(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %eax,%ebp
movsbl %cl,%edi
call   1030 <isprint@plt>
test   %rax,%rax
je     1200 <firetalk_printable+0xe0>
movsbl -0x2(%r15,%r13,1),%edi
call   1030 <isprint@plt>
test   %rax,%rax
je     11e0 <firetalk_printable+0xc0>
movzbl (%rbx),%ecx
lea    0x1(%rbp),%eax
mov    %cl,0x0(%rbp,%r12,1)
jmp    1214 <firetalk_printable+0xf4>
nopl   0x0(%rax)
mov    %r13d,%eax
movzbl (%r15,%rax,1),%eax
test   %al,%al
je     1200 <firetalk_printable+0xe0>
movsbl %al,%edi
call   1030 <isprint@plt>
test   %rax,%rax
jne    11cf <firetalk_printable+0xaf>
nopl   0x0(%rax)
mov    %rbp,%rdi
add    %r12,%rdi
movsbl (%rbx),%edx
mov    %r14,%rsi
call   1040 <sprintf@plt>
lea    0x4(%rbp),%eax
mov    %r13d,%ebx
movzbl (%r15,%rbx,1),%ecx
test   %cl,%cl
je     1232 <firetalk_printable+0x112>
add    %r15,%rbx
add    $0x1,%r13
cmp    $0xfc,%eax
jb     11b0 <firetalk_printable+0x90>
jmp    1232 <firetalk_printable+0x112>
xor    %eax,%eax
mov    %eax,%ecx
lea    0x2e05(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@firetalk_printable.out = internal global [256 x i8] zeroinitializer
@.str = [7 x i8] c"\\x%02X\00"
define i8* @firetalk_printable(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %65, label %4
4: ; preds = %1
%5 = tail call i64 @isprint(i8 signext %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = tail call i64 @isprint(i8 signext %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = load i8, i8* %0
store i8 %15, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @firetalk_printable.out, i64 0, i64 0)
br label %19
16: ; preds = %11, %7, %4
%17 = load i8, i8* %0
%18 = tail call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @firetalk_printable.out, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %17)
br label %19
19: ; preds = %16, %14
%20 = phi i32 [ 1, %14 ], [ 4, %16 ]
%21 = getelementptr inbounds i8, i8* %0, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %65, label %24
24: ; preds = %19, %56
%25 = phi i64 [ %58, %56 ], [ 1, %19 ]
%26 = phi i32 [ %57, %56 ], [ %20, %19 ]
%27 = phi i8 [ %61, %56 ], [ %22, %19 ]
%28 = phi i8* [ %60, %56 ], [ %21, %19 ]
%29 = zext i32 %26 to i64
%30 = tail call i64 @isprint(i8 signext %27)
%31 = icmp eq i64 %30, 0
br i1 %31, label %51, label %32
32: ; preds = %24
%33 = add nsw i64 %25, -1
%34 = getelementptr inbounds i8, i8* %0, i64 %33
%35 = load i8, i8* %34
%36 = tail call i64 @isprint(i8 signext %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %47
38: ; preds = %32
%39 = add i64 %25, 1
%40 = and i64 %39, 4294967295
%41 = getelementptr inbounds i8, i8* %0, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %51, label %44
44: ; preds = %38
%45 = tail call i64 @isprint(i8 signext %42)
%46 = icmp eq i64 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %44, %32
%48 = load i8, i8* %28
%49 = add nuw nsw i32 %26, 1
%50 = getelementptr inbounds [256 x i8], [256 x i8]* @firetalk_printable.out, i64 0, i64 %29
store i8 %48, i8* %50
br label %56
51: ; preds = %44, %38, %24
%52 = getelementptr inbounds [256 x i8], [256 x i8]* @firetalk_printable.out, i64 0, i64 %29
%53 = load i8, i8* %28
%54 = tail call i32 @sprintf(i8* %52, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %53)
%55 = add nuw nsw i32 %26, 4
br label %56
56: ; preds = %47, %51
%57 = phi i32 [ %49, %47 ], [ %55, %51 ]
%58 = add nuw i64 %25, 1
%59 = and i64 %58, 4294967295
%60 = getelementptr inbounds i8, i8* %0, i64 %59
%61 = load i8, i8* %60
%62 = icmp ne i8 %61, 0
%63 = icmp ult i32 %57, 252
%64 = select i1 %62, i1 %63, i1 false
br i1 %64, label %24, label %65
65: ; preds = %56, %19, %1
%66 = phi i32 [ 0, %1 ], [ %20, %19 ], [ %57, %56 ]
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds [256 x i8], [256 x i8]* @firetalk_printable.out, i64 0, i64 %67
store i8 0, i8* %68
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @firetalk_printable.out, i64 0, i64 0)
}