#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(int);
size_t rand();
char *randstr(int length) {
  char *string =
      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#'?!";
  size_t stringLen = 26 * 2 + 10 + 7;
  char *randomString;
  randomString = malloc(sizeof(char) * (length + 1));
  if (!randomString)
    return (char *)0;
  unsigned int key = 0;
  for (int n = 0; n < length; n++) {
    key = rand() % stringLen;
    randomString[n] = string[key];
  }
  randomString[length] = '\0';
  return randomString;
}


x86 assembly (clang, -O0):
<randstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
lea    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x45,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116d <randstr+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <randstr+0xb2>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11be <randstr+0x9e>
mov    $0x0,%al
call   1040 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    %edx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    117b <randstr+0x5b>
mov    -0x28(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randstr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x1(%r14),%edi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1193 <randstr+0x73>
test   %r14d,%r14d
jle    118b <randstr+0x6b>
mov    %r14d,%ebx
movabs $0xed7303b5cc0ed731,%r12
03 73 ed
lea    0xea8(%rip),%r13
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %rax,%rcx
mul    %r12
shr    $0x6,%rdx
imul   $0x45,%rdx,%rax
sub    %rax,%rcx
movzbl 0x0(%r13,%rcx,1),%eax
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <randstr+0x40>
movslq %r14d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [70 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#'?!\00"
define i8* @randstr(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8** %4
store i64 69, i64* %5
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 1, %11
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %1
store i8* null, i8** %2
br label %46
18: ; preds = %1
store i32 0, i32* %7
store i32 0, i32* %8
br label %19
19: ; preds = %37, %18
%20 = load i32, i32* %8
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %40
23: ; preds = %19
%24 = call i64 (...) @rand()
%25 = load i64, i64* %5
%26 = urem i64 %24, %25
%27 = trunc i64 %26 to i32
store i32 %27, i32* %7
%28 = load i8*, i8** %4
%29 = load i32, i32* %7
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %6
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %23
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %19
40: ; preds = %19
%41 = load i8*, i8** %6
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %6
store i8* %45, i8** %2
br label %46
46: ; preds = %40, %17
%47 = load i8*, i8** %2
ret i8* %47
}

LLVM IR (-O2):
@.str = [70 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#'?!\00"
define noalias i8* @randstr(i32 %0) {
%2 = add nsw i32 %0, 1
%3 = tail call i8* @malloc(i32 %2)
%4 = icmp eq i8* %3, null
br i1 %4, label %21, label %5
5: ; preds = %1
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = zext i32 %0 to i64
br label %12
9: ; preds = %12, %5
%10 = sext i32 %0 to i64
%11 = getelementptr inbounds i8, i8* %3, i64 %10
store i8 0, i8* %11
br label %21
12: ; preds = %7, %12
%13 = phi i64 [ 0, %7 ], [ %19, %12 ]
%14 = tail call i64 (...) @rand()
%15 = urem i64 %14, 69
%16 = getelementptr inbounds [70 x i8], [70 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %3, i64 %13
store i8 %17, i8* %18
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %9, label %12
21: ; preds = %1, %9
ret i8* %3
}