#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*/ append(char *);
int /*<<< orphan*/ cats(char *);
void safecats(char *s) {
  char ch;
  int i;
  for (i = 0; i < 100; ++i) {
    ch = s[i];
    if (!ch)
      return;
    if (ch < 33)
      ch = '?';
    if (ch > 126)
      ch = '?';
    if (ch == '%')
      ch = '?';
    if (ch == ':')
      ch = '?';
    append(&ch);
  }
  cats("...");
}


x86 assembly (clang, -O0):
<safecats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x64,-0x10(%rbp)
jge    11b5 <safecats+0x95>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x9(%rbp)
cmpb   $0x0,-0x9(%rbp)
jne    115a <safecats+0x3a>
jmp    11c1 <safecats+0xa1>
movsbl -0x9(%rbp),%eax
cmp    $0x21,%eax
jge    116b <safecats+0x4b>
movb   $0x3f,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x7e,%eax
jle    117c <safecats+0x5c>
movb   $0x3f,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x25,%eax
jne    118d <safecats+0x6d>
movb   $0x3f,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x3a,%eax
jne    119e <safecats+0x7e>
movb   $0x3f,-0x9(%rbp)
lea    -0x9(%rbp),%rdi
call   1030 <append@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1133 <safecats+0x13>
lea    0xe44(%rip),%rdi
call   1040 <cats@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safecats>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0xf(%rsp),%r14
jmp    1157 <safecats+0x37>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x3f,0xf(%rsp)
mov    %r14,%rdi
call   1030 <append@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
je     1176 <safecats+0x56>
movzbl (%r15,%rbx,1),%eax
mov    %al,0xf(%rsp)
test   %al,%al
je     1182 <safecats+0x62>
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
jbe    1140 <safecats+0x20>
cmp    $0x3a,%al
je     1140 <safecats+0x20>
cmp    $0x25,%al
je     1140 <safecats+0x20>
jmp    1145 <safecats+0x25>
lea    0xe83(%rip),%rdi
call   1040 <cats@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"...\00"
define void @safecats(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
br label %5
5: ; preds = %39, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %42
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %3
%14 = load i8, i8* %3
%15 = icmp ne i8 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %8
br label %44
17: ; preds = %8
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp slt i32 %19, 33
br i1 %20, label %21, label %22
21: ; preds = %17
store i8 63, i8* %3
br label %22
22: ; preds = %21, %17
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = icmp sgt i32 %24, 126
br i1 %25, label %26, label %27
26: ; preds = %22
store i8 63, i8* %3
br label %27
27: ; preds = %26, %22
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 37
br i1 %30, label %31, label %32
31: ; preds = %27
store i8 63, i8* %3
br label %32
32: ; preds = %31, %27
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 58
br i1 %35, label %36, label %37
36: ; preds = %32
store i8 63, i8* %3
br label %37
37: ; preds = %36, %32
%38 = call i32 @append(i8* %3)
br label %39
39: ; preds = %37
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %5
42: ; preds = %5
%43 = call i32 @cats(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %42, %16
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"...\00"
define void @safecats(i8* nocapture %0) {
%2 = alloca i8
br label %3
3: ; preds = %1, %15
%4 = phi i64 [ 0, %1 ], [ %17, %15 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
store i8 %6, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = add i8 %6, -127
%10 = icmp ult i8 %9, -94
br i1 %10, label %11, label %12
11: ; preds = %8
store i8 63, i8* %2
br label %15
12: ; preds = %8
switch i8 %6, label %15 [
i8 37, label %13
i8 58, label %14
]
13: ; preds = %12
store i8 63, i8* %2
br label %15
14: ; preds = %12
store i8 63, i8* %2
br label %15
15: ; preds = %12, %11, %13, %14
%16 = call i32 @append(i8* %2)
%17 = add nuw nsw i64 %4, 1
%18 = icmp eq i64 %17, 100
br i1 %18, label %19, label %3
19: ; preds = %15
%20 = call i32 @cats(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %3, %19
ret void
}