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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned char *);
void safe_output(FILE *stream, unsigned char *str) {
  unsigned char *p;
  for (p = str; *p != '\0'; ++p) {
    if (*p < 0x20 || *p >= 0x7f) {
      *p = '?';
    }
  }
  fprintf(stream, "%s", str);
}


x86 assembly (clang, -O0):
<safe_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     1175 <safe_output+0x65>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jl     1158 <safe_output+0x48>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jl     115f <safe_output+0x4f>
mov    -0x18(%rbp),%rax
movb   $0x3f,(%rax)
jmp    1164 <safe_output+0x54>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <safe_output+0x18>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe7c(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_output>:
mov    %rsi,%rax
mov    %rdi,%rsi
mov    (%rax),%dl
test   %dl,%dl
je     1149 <safe_output+0x39>
lea    0x1(%rax),%rcx
jmp    113b <safe_output+0x2b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rcx),%edx
add    $0x1,%rcx
test   %dl,%dl
je     1149 <safe_output+0x39>
add    $0x81,%dl
cmp    $0xa0,%dl
ja     1130 <safe_output+0x20>
movb   $0x3f,-0x1(%rcx)
jmp    1130 <safe_output+0x20>
mov    %rax,%rdi
jmp    1030 <fputs@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @safe_output(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
store i8* %6, i8** %5
br label %7
7: ; preds = %25, %2
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %7
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = icmp slt i32 %15, 32
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = icmp sge i32 %20, 127
br i1 %21, label %22, label %24
22: ; preds = %17, %12
%23 = load i8*, i8** %5
store i8 63, i8* %23
br label %24
24: ; preds = %22, %17
br label %25
25: ; preds = %24
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
br label %7
28: ; preds = %7
%29 = load i32*, i32** %3
%30 = load i8*, i8** %4
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %30)
ret void
}

LLVM IR (-O2):
define void @safe_output(i32* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %2, %11
%6 = phi i8 [ %13, %11 ], [ %3, %2 ]
%7 = phi i8* [ %12, %11 ], [ %1, %2 ]
%8 = add i8 %6, -127
%9 = icmp ult i8 %8, -95
br i1 %9, label %10, label %11
10: ; preds = %5
store i8 63, i8* %7
br label %11
11: ; preds = %5, %10
%12 = getelementptr inbounds i8, i8* %7, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %11, %2
%16 = tail call i32 @fputs(i8* %1, i32* %0)
ret void
}