#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 */
int /*<<< orphan*/ isprint(char);
void pattern(register char *cp, register int cnt) {
  register char c;
  c = 0;
  while (cnt-- > 0) {
    while (!isprint((c & 0x7F)))
      c++;
    *cp++ = (c++ & 0x7F);
  }
}


x86 assembly (clang, -O0):
<pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    1196 <pattern+0x86>
jmp    113c <pattern+0x2c>
movsbl -0xd(%rbp),%eax
and    $0x7f,%eax
movsbl %al,%edi
call   1030 <isprint@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1160 <pattern+0x50>
jmp    116d <pattern+0x5d>
mov    -0xd(%rbp),%al
add    $0x1,%al
mov    %al,-0xd(%rbp)
jmp    113c <pattern+0x2c>
mov    -0xd(%rbp),%al
mov    %al,%cl
add    $0x1,%cl
mov    %cl,-0xd(%rbp)
movsbl %al,%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1123 <pattern+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pattern>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1159 <pattern+0x49>
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%ebx
and    $0x7f,%bl
movzbl %bl,%edi
call   1030 <isprint@plt>
add    $0x1,%bpl
test   %eax,%eax
je     1130 <pattern+0x20>
lea    -0x1(%r14),%eax
mov    %bl,(%r15)
add    $0x1,%r15
cmp    $0x1,%r14d
mov    %eax,%r14d
jg     1130 <pattern+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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