#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 *calloc(int, int);
int rand();
char *randstr() {
  int len = 20 + rand() % 40;
  char *str = calloc(1, len + 1);
  str[len] = '\0';
  for (int i = 0; i < len; i++) {
    str[i] = 'a' + (rand() % 26);
  }
  return str;
}


x86 assembly (clang, -O0):
<randstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x28,%ecx
cltd
idiv   %ecx
add    $0x14,%edx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119b <randstr+0x7b>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%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    1164 <randstr+0x44>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randstr>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x24,%rcx
add    %edx,%ecx
shl    $0x3,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%r15d
sub    %ecx,%r15d
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0x15,%esi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,%r14
cmp    $0xffffffed,%r15d
jl     11a6 <randstr+0x86>
add    $0x14,%r15d
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x61,%al
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <randstr+0x50>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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