#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(size_t);
int rand();
char *random_string() {
  size_t length, ii;
  char *str;
  length = rand() % 15 + 5;
  str = malloc((length + 1) * sizeof(char));
  for (ii = 0; ii < length; ii++) {
    str[ii] = rand() % 62 + 64;
  }
  str[length] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<random_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xf,%ecx
cltd
idiv   %ecx
add    $0x5,%edx
movslq %edx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    119a <random_string+0x7a>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x3e,%ecx
cltd
idiv   %ecx
add    $0x40,%edx
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115e <random_string+0x3e>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x3,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
movslq %eax,%rdi
lea    0x5(%rdi),%r14
add    $0x6,%rdi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
je     11be <random_string+0x9e>
cmp    $0x2,%r14
mov    $0x1,%r12d
cmovae %r14,%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffff84210843,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x5,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x6,%edx
mov    %ecx,%esi
sub    %edx,%esi
add    %ecx,%esi
add    %eax,%esi
add    $0x40,%sil
mov    %sil,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <random_string+0x60>
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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