#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__ printf(char *, unsigned char);
int show_str(const char *str, unsigned int max_length) {
  int printed = 0;
  while (max_length-- > 0) {
    printed +=
        printf("%c", (*str >= ' ' && *str <= '~') ? (unsigned char)*str : '.');
    str += 1;
  }
  return printed;
}


x86 assembly (clang, -O0):
<show_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jbe    11a6 <show_str+0x96>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jl     1169 <show_str+0x59>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jg     1169 <show_str+0x59>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1176 <show_str+0x66>
mov    $0x2e,%eax
mov    %eax,-0x14(%rbp)
jmp    1176 <show_str+0x66>
mov    -0x14(%rbp),%eax
lea    0xe80(%rip),%rdi
movzbl %al,%esi
call   1030 <printf@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1126 <show_str+0x16>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1167 <show_str+0x57>
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
mov    $0x2e,%r13d
lea    0xecc(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
cmovb  %r13d,%eax
movzbl %al,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1140 <show_str+0x30>
jmp    1169 <show_str+0x59>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define i32 @show_str(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %25, %2
%7 = load i32, i32* %4
%8 = add i32 %7, -1
store i32 %8, i32* %4
%9 = icmp ugt i32 %7, 0
br i1 %9, label %10, label %35
10: ; preds = %6
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp sge i32 %13, 32
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp sle i32 %18, 126
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
br label %25
24: ; preds = %15, %10
br label %25
25: ; preds = %24, %20
%26 = phi i32 [ %23, %20 ], [ 46, %24 ]
%27 = trunc i32 %26 to i8
%28 = call i64 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %27)
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %5
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %3
br label %6
35: ; preds = %6
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define i32 @show_str(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %18, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %15, %4 ], [ 0, %2 ]
%6 = phi i32 [ %8, %4 ], [ %1, %2 ]
%7 = phi i8* [ %16, %4 ], [ %0, %2 ]
%8 = add i32 %6, -1
%9 = load i8, i8* %7
%10 = add i8 %9, -127
%11 = icmp ult i8 %10, -95
%12 = select i1 %11, i8 46, i8 %9
%13 = tail call i64 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
%14 = trunc i64 %13 to i32
%15 = add i32 %5, %14
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = icmp eq i32 %8, 0
br i1 %17, label %18, label %4
18: ; preds = %4, %2
%19 = phi i32 [ 0, %2 ], [ %15, %4 ]
ret i32 %19
}