#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 */
scalar_t__ malloc(unsigned int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *rand_text() {
  srand(time(NULL));
  unsigned length = (rand() % 25) - 1;
  char *t = (char *)malloc(length * sizeof(char));
  if (!t)
    return NULL;
  unsigned i = 0;
  for (; i < length; ++i) {
    t[i] = (char)((rand() % 26) + 'a');
  }
  t[i + 1] = '\0';
  return t;
}


x86 assembly (clang, -O0):
<rand_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x19,%ecx
cltd
idiv   %ecx
sub    $0x1,%edx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1197 <rand_text+0x57>
movq   $0x0,-0x8(%rbp)
jmp    11ec <rand_text+0xac>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11d4 <rand_text+0x94>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119e <rand_text+0x5e>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_text>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%r14d
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,4),%ebx
mov    %ebx,%eax
neg    %eax
lea    (%r14,%rax,1),%ebp
add    $0xffffffff,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11f8 <rand_text+0xb8>
mov    %rax,%r12
test   %ebp,%ebp
je     11eb <rand_text+0xab>
sub    %ebx,%r14d
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <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,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <rand_text+0x70>
mov    %r14d,%eax
jmp    11f0 <rand_text+0xb0>
mov    $0x1,%eax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%r15
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @rand_text() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 25
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %0
store i8* null, i8** %1
br label %43
19: ; preds = %0
store i32 0, i32* %4
br label %20
20: ; preds = %33, %19
%21 = load i32, i32* %4
%22 = load i32, i32* %2
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 26
%27 = add nsw i32 %26, 97
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %3
%30 = load i32, i32* %4
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
br label %33
33: ; preds = %24
%34 = load i32, i32* %4
%35 = add i32 %34, 1
store i32 %35, i32* %4
br label %20
36: ; preds = %20
%37 = load i8*, i8** %3
%38 = load i32, i32* %4
%39 = add i32 %38, 1
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %3
store i8* %42, i8** %1
br label %43
43: ; preds = %36, %18
%44 = load i8*, i8** %1
ret i8* %44
}

LLVM IR (-O2):
define i8* @rand_text() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 25
%5 = add nsw i32 %4, -1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %27, label %9
9: ; preds = %0
%10 = icmp eq i32 %5, 0
br i1 %10, label %24, label %11
11: ; preds = %9
%12 = zext i32 %5 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %20, %13 ]
%15 = tail call i32 (...) @rand()
%16 = srem i32 %15, 26
%17 = trunc i32 %16 to i8
%18 = add nsw i8 %17, 97
%19 = getelementptr inbounds i8, i8* %7, i64 %14
store i8 %18, i8* %19
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %12
br i1 %21, label %22, label %13
22: ; preds = %13
%23 = zext i32 %4 to i64
br label %24
24: ; preds = %22, %9
%25 = phi i64 [ 1, %9 ], [ %23, %22 ]
%26 = getelementptr inbounds i8, i8* %7, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %0, %24
%28 = phi i8* [ %7, %24 ], [ null, %0 ]
ret i8* %28
}