#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 *malloc(unsigned short);
int rand();
char *rndstr_ascii(unsigned short len) {
  char *ret = malloc(len);
  for (int i = 0; i < len; ++i)
    ret[i] = (rand() % (126 - 33 + 1) + 33);
  ret[len] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<rndstr_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movzwl -0x2(%rbp),%ecx
cmp    %ecx,%eax
jge    117d <rndstr_ascii+0x5d>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x5e,%ecx
cltd
idiv   %ecx
add    $0x21,%edx
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    1143 <rndstr_ascii+0x23>
mov    -0x10(%rbp),%rax
movzwl -0x2(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndstr_ascii>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
call   1030 <malloc@plt>
mov    %rax,%r15
movzwl %r14w,%ebp
test   %r14d,%r14d
je     1174 <rndstr_ascii+0x54>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffffae4c415d,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x6,%ecx
add    %edx,%ecx
imul   $0x5e,%ecx,%ecx
sub    %ecx,%eax
add    $0x21,%al
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <rndstr_ascii+0x20>
movb   $0x0,(%r15,%rbp,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @rndstr_ascii(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i8*
%4 = alloca i32
store i16 %0, i16* %2
%5 = load i16, i16* %2
%6 = call i8* @malloc(i16 zeroext %5)
store i8* %6, i8** %3
store i32 0, i32* %4
br label %7
7: ; preds = %21, %1
%8 = load i32, i32* %4
%9 = load i16, i16* %2
%10 = zext i16 %9 to i32
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %24
12: ; preds = %7
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 94
%15 = add nsw i32 %14, 33
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 %16, i8* %20
br label %21
21: ; preds = %12
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %7
24: ; preds = %7
%25 = load i8*, i8** %3
%26 = load i16, i16* %2
%27 = zext i16 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define noalias i8* @rndstr_ascii(i16 zeroext %0) {
%2 = tail call i8* @malloc(i16 zeroext %0)
%3 = icmp eq i16 %0, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = zext i16 %0 to i64
br label %9
6: ; preds = %9, %1
%7 = zext i16 %0 to i64
%8 = getelementptr inbounds i8, i8* %2, i64 %7
store i8 0, i8* %8
ret i8* %2
9: ; preds = %4, %9
%10 = phi i64 [ 0, %4 ], [ %16, %9 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 94
%13 = trunc i32 %12 to i8
%14 = add nsw i8 %13, 33
%15 = getelementptr inbounds i8, i8* %2, i64 %10
store i8 %14, i8* %15
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %5
br i1 %17, label %6, label %9
}