#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 */
scalar_t__ isprint(char);
char *write(char *, char);
char *safe_puts(char *out, char *in, int size) {
  for (int i = 0; i < size; i++) {
    char c = in[i];
    out = write(out, isprint(c) ? c : '.');
  }
  return out;
}


x86 assembly (clang, -O0):
<safe_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a9 <safe_puts+0x89>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movsbl -0x19(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     117b <safe_puts+0x5b>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1188 <safe_puts+0x68>
mov    $0x2e,%eax
mov    %eax,-0x2c(%rbp)
jmp    1188 <safe_puts+0x68>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%eax
movsbl %al,%esi
call   1030 <write@plt>
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <safe_puts+0x1a>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_puts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
test   %edx,%edx
jle    1169 <safe_puts+0x49>
mov    %rsi,%r14
mov    %edx,%r15d
xor    %ebx,%ebx
mov    $0x2e,%r13d
movsbl (%r14,%rbx,1),%ebp
mov    %ebp,%edi
call   1040 <isprint@plt>
test   %rax,%rax
cmove  %r13d,%ebp
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <write@plt>
mov    %rax,%r12
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <safe_puts+0x20>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @safe_puts(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %31, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
store i8 %18, i8* %8
%19 = load i8*, i8** %4
%20 = load i8, i8* %8
%21 = call i64 @isprint(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %13
%24 = load i8, i8* %8
%25 = sext i8 %24 to i32
br label %27
26: ; preds = %13
br label %27
27: ; preds = %26, %23
%28 = phi i32 [ %25, %23 ], [ 46, %26 ]
%29 = trunc i32 %28 to i8
%30 = call i8* @write(i8* %19, i8 signext %29)
store i8* %30, i8** %4
br label %31
31: ; preds = %27
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %9
34: ; preds = %9
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
define i8* @safe_puts(i8* %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %9
7: ; preds = %9, %3
%8 = phi i8* [ %0, %3 ], [ %17, %9 ]
ret i8* %8
9: ; preds = %5, %9
%10 = phi i64 [ 0, %5 ], [ %18, %9 ]
%11 = phi i8* [ %0, %5 ], [ %17, %9 ]
%12 = getelementptr inbounds i8, i8* %1, i64 %10
%13 = load i8, i8* %12
%14 = tail call i64 @isprint(i8 signext %13)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8 46, i8 %13
%17 = tail call i8* @write(i8* %11, i8 signext %16)
%18 = add nuw nsw i64 %10, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %7, label %9
}