#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 */
char getRandomCharacter();
scalar_t__ isprint(char);
char *malloc(size_t);
char *getPrintableCharacters(size_t size) {
  char *text = malloc((size + 1) * sizeof(char));
  for (int i = 0; i < size; i++) {
    char c = getRandomCharacter();
    while (!(isprint(c) || c == '\n')) {
      c = getRandomCharacter();
    }
    text[i] = c;
  }
  text[size] = '\0';
  return text;
}


x86 assembly (clang, -O0):
<getPrintableCharacters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11d5 <getPrintableCharacters+0xa5>
mov    $0x0,%al
call   1030 <getRandomCharacter@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1050 <isprint@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x16(%rbp)
jne    1198 <getPrintableCharacters+0x68>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    11aa <getPrintableCharacters+0x7a>
jmp    11b9 <getPrintableCharacters+0x89>
mov    $0x0,%al
call   1030 <getRandomCharacter@plt>
mov    %al,-0x15(%rbp)
jmp    1170 <getPrintableCharacters+0x40>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1158 <getPrintableCharacters+0x28>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPrintableCharacters>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %r14,%r14
je     1180 <getPrintableCharacters+0x50>
xor    %r12d,%r12d
jmp    1160 <getPrintableCharacters+0x30>
mov    %bl,(%r15,%r12,1)
add    $0x1,%r12
cmp    %r14,%r12
je     1180 <getPrintableCharacters+0x50>
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <getRandomCharacter@plt>
mov    %eax,%ebx
movsbl %al,%ebp
mov    %ebp,%edi
call   1050 <isprint@plt>
cmp    $0xa,%bpl
je     1151 <getPrintableCharacters+0x21>
test   %rax,%rax
je     1160 <getPrintableCharacters+0x30>
jmp    1151 <getPrintableCharacters+0x21>
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @getPrintableCharacters(i64 %0) {
%2 = add i64 %0, 1
%3 = tail call i8* @malloc(i64 %2)
%4 = icmp eq i64 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %20, %1
%6 = getelementptr inbounds i8, i8* %3, i64 %0
store i8 0, i8* %6
ret i8* %3
7: ; preds = %1, %20
%8 = phi i64 [ %23, %20 ], [ 0, %1 ]
%9 = tail call signext i8 (...) @getRandomCharacter()
%10 = tail call i64 @isprint(i8 signext %9)
%11 = icmp eq i64 %10, 0
%12 = icmp ne i8 %9, 10
%13 = and i1 %12, %11
br i1 %13, label %14, label %20
14: ; preds = %7, %14
%15 = tail call signext i8 (...) @getRandomCharacter()
%16 = tail call i64 @isprint(i8 signext %15)
%17 = icmp eq i64 %16, 0
%18 = icmp ne i8 %15, 10
%19 = and i1 %18, %17
br i1 %19, label %14, label %20
20: ; preds = %14, %7
%21 = phi i8 [ %9, %7 ], [ %15, %14 ]
%22 = getelementptr inbounds i8, i8* %3, i64 %8
store i8 %21, i8* %22
%23 = add nuw i64 %8, 1
%24 = icmp eq i64 %23, %0
br i1 %24, label %5, label %7
}