#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(unsigned int);
unsigned int random_integer(int, int);
char *random_sentence(int, int);
char *realloc(char *, unsigned int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *random_text() {
  unsigned int len = sizeof(char);
  char *text = malloc(len);
  char *sentence;
  unsigned int count_sentences = random_integer(3, 5);
  while (count_sentences-- > 0) {
    sentence = random_sentence(3, 10);
    len += (sizeof(char) * strlen(sentence) + 1);
    text = realloc(text, len);
    strcpy(text, sentence);
    strcat(text, " ");
  }
  return text;
}


x86 assembly (clang, -O0):
<random_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x3,%edi
mov    $0x5,%esi
call   1070 <random_integer@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
jbe    1213 <random_text+0xa3>
mov    $0x3,%edi
mov    $0xa,%esi
call   1090 <random_sentence@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
shl    $0x0,%rcx
add    $0x1,%rcx
mov    -0x4(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1080 <strcat@plt>
jmp    119d <random_text+0x2d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_text>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x3,%edi
mov    $0x5,%esi
call   1070 <random_integer@plt>
test   %eax,%eax
je     11fe <random_text+0x8e>
mov    %eax,%ebp
mov    $0x1,%ebx
lea    0xe5a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    $0x3,%edi
mov    $0xa,%esi
call   1090 <random_sentence@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
mov    %ebx,%ecx
lea    (%rcx,%rax,1),%rbx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <realloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
add    $0xffffffff,%ebp
jne    11b0 <random_text+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @random_text() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i32 1, i32* %1
%5 = load i32, i32* %1
%6 = call i8* @malloc(i32 %5)
store i8* %6, i8** %2
%7 = call i32 @random_integer(i32 3, i32 5)
store i32 %7, i32* %4
br label %8
8: ; preds = %12, %0
%9 = load i32, i32* %4
%10 = add i32 %9, -1
store i32 %10, i32* %4
%11 = icmp ugt i32 %9, 0
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = call i8* @random_sentence(i32 3, i32 10)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = add i64 %17, 1
%19 = load i32, i32* %1
%20 = zext i32 %19 to i64
%21 = add i64 %20, %18
%22 = trunc i64 %21 to i32
store i32 %22, i32* %1
%23 = load i8*, i8** %2
%24 = load i32, i32* %1
%25 = call i8* @realloc(i8* %23, i32 %24)
store i8* %25, i8** %2
%26 = load i8*, i8** %2
%27 = load i8*, i8** %3
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = load i8*, i8** %2
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %8
31: ; preds = %8
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @random_text() {
%1 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%2 = tail call i32 @random_integer(i32 3, i32 5)
%3 = icmp eq i32 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %0, %4
%5 = phi i32 [ %8, %4 ], [ %2, %0 ]
%6 = phi i64 [ %14, %4 ], [ 1, %0 ]
%7 = phi i8* [ %16, %4 ], [ %1, %0 ]
%8 = add i32 %5, -1
%9 = tail call i8* @random_sentence(i32 3, i32 10)
%10 = tail call i32 @strlen(i8* %9)
%11 = zext i32 %10 to i64
%12 = and i64 %6, 4294967295
%13 = add nuw nsw i64 %12, 1
%14 = add nuw nsw i64 %13, %11
%15 = trunc i64 %14 to i32
%16 = tail call i8* @realloc(i8* %7, i32 %15)
%17 = tail call i32 @strcpy(i8* %16, i8* %9)
%18 = tail call i32 @strcat(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32 %8, 0
br i1 %19, label %20, label %4
20: ; preds = %4, %0
%21 = phi i8* [ %1, %0 ], [ %16, %4 ]
ret i8* %21
}