#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 *strn2print(char *dest, char *src, int c) {
  dest[c] = '\0';
  for (; c >= 0; c--)
    dest[c] = (isprint(src[c]) ? src[c] : '.');
  return dest;
}


x86 assembly (clang, -O0):
<strn2print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x14(%rbp)
jl     1193 <strn2print+0x83>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isprint@plt>
cmp    $0x0,%rax
je     1168 <strn2print+0x58>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
jmp    1175 <strn2print+0x65>
mov    $0x2e,%eax
mov    %eax,-0x18(%rbp)
jmp    1175 <strn2print+0x65>
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <strn2print+0x1f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strn2print>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
movslq %edx,%rax
movb   $0x0,(%rdi,%rax,1)
test   %eax,%eax
js     1155 <strn2print+0x45>
mov    %rsi,%r15
mov    %edx,%ebx
add    $0x1,%rbx
jmp    1141 <strn2print+0x31>
xchg   %ax,%ax
movzbl -0x1(%r15,%rbx,1),%eax
mov    %al,-0x1(%r14,%rbx,1)
add    $0xffffffffffffffff,%rbx
jle    1155 <strn2print+0x45>
movsbl -0x1(%r15,%rbx,1),%edi
call   1030 <isprint@plt>
test   %rax,%rax
jne    1130 <strn2print+0x20>
mov    $0x2e,%al
jmp    1136 <strn2print+0x26>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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