#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__ psf_isprint(char);
void psf_sanitize_string(char *cptr, int len) {
  do {
    len--;
    cptr[len] = psf_isprint(cptr[len]) ? cptr[len] : '.';
  } while (len > 0);
}


x86 assembly (clang, -O0):
<psf_sanitize_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <psf_isprint@plt>
cmp    $0x0,%rax
je     1157 <psf_sanitize_string+0x47>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x10(%rbp)
jmp    1164 <psf_sanitize_string+0x54>
mov    $0x2e,%eax
mov    %eax,-0x10(%rbp)
jmp    1164 <psf_sanitize_string+0x54>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x0,-0xc(%rbp)
jg     111f <psf_sanitize_string+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psf_sanitize_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movslq %esi,%rbx
add    $0x1,%rbx
jmp    1135 <psf_sanitize_string+0x25>
movzbl -0x2(%r14,%rbx,1),%eax
mov    %al,-0x2(%r14,%rbx,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jle    1149 <psf_sanitize_string+0x39>
movsbl -0x2(%r14,%rbx,1),%edi
call   1030 <psf_isprint@plt>
test   %rax,%rax
jne    1120 <psf_sanitize_string+0x10>
mov    $0x2e,%al
jmp    1126 <psf_sanitize_string+0x16>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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