#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
scalar_t__ malloc(unsigned int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *rand_text() {
  srand(time(NULL));
  unsigned length = rand() % 50;
  fprintf(stderr, "length is %d\n", length);
  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   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x32,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe73(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bc <rand_text+0x6c>
movq   $0x0,-0x8(%rbp)
jmp    1211 <rand_text+0xc1>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11f9 <rand_text+0xa9>
mov    $0x0,%al
call   1070 <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    11c3 <rand_text+0x73>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $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   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%r14
imul   $0x51eb851f,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x24,%rax
add    %ecx,%eax
imul   $0x32,%eax,%eax
sub    %eax,%r14d
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
mov    %r14d,%edx
call   1040 <fprintf@plt>
mov    %r14d,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     120a <rand_text+0xba>
mov    %rax,%r12
test   %r14d,%r14d
je     11fc <rand_text+0xac>
mov    %r14d,%r15d
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1070 <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,%r15
jne    11c0 <rand_text+0x70>
add    $0xffffffff,%r14d
jmp    1202 <rand_text+0xb2>
mov    $0xffffffff,%r14d
movb   $0x0,(%r12,%r14,1)
mov    %r12,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"length is %d\0A\00"
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, 50
store i32 %8, i32* %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %0
store i8* null, i8** %1
br label %45
21: ; preds = %0
store i32 0, i32* %4
br label %22
22: ; preds = %35, %21
%23 = load i32, i32* %4
%24 = load i32, i32* %2
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = call i32 (...) @rand()
%28 = srem i32 %27, 26
%29 = add nsw i32 %28, 97
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %3
%32 = load i32, i32* %4
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
br label %35
35: ; preds = %26
%36 = load i32, i32* %4
%37 = add i32 %36, 1
store i32 %37, i32* %4
br label %22
38: ; preds = %22
%39 = load i8*, i8** %3
%40 = load i32, i32* %4
%41 = sub i32 %40, 1
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %3
store i8* %44, i8** %1
br label %45
45: ; preds = %38, %20
%46 = load i8*, i8** %1
ret i8* %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"length is %d\0A\00"
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, 50
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
%7 = tail call i64 @malloc(i32 %4)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %29, label %10
10: ; preds = %0
%11 = icmp eq i32 %4, 0
br i1 %11, label %26, label %12
12: ; preds = %10
%13 = zext i32 %4 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %21, %14 ]
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 26
%18 = trunc i32 %17 to i8
%19 = add nsw i8 %18, 97
%20 = getelementptr inbounds i8, i8* %8, i64 %15
store i8 %19, i8* %20
%21 = add nuw nsw i64 %15, 1
%22 = icmp eq i64 %21, %13
br i1 %22, label %23, label %14
23: ; preds = %14
%24 = add nsw i32 %4, -1
%25 = zext i32 %24 to i64
br label %26
26: ; preds = %23, %10
%27 = phi i64 [ 4294967295, %10 ], [ %25, %23 ]
%28 = getelementptr inbounds i8, i8* %8, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %0, %26
%30 = phi i8* [ %8, %26 ], [ null, %0 ]
ret i8* %30
}