#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 rand();
char randomChar(int);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ strcpy(char *, char *);
void randomString(char a[20]) {
  strcpy(a, "");
  int i;
  srand(rand());
  int length = rand() % 20;
  for (i = 0; i < length; i++) {
    a[i] = randomChar(rand());
  }
}


x86 assembly (clang, -O0):
<randomString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b8 <randomString+0x78>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%edi
call   1060 <randomChar@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1183 <randomString+0x43>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomString>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xeb1(%rip),%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
test   %eax,%eax
jle    11ab <randomString+0x6b>
mov    %eax,%r15d
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%edi
call   1060 <randomChar@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1190 <randomString+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @randomString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (...) @rand()
%8 = call i32 @srand(i32 %7)
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 20
store i32 %10, i32* %4
store i32 0, i32* %3
br label %11
11: ; preds = %22, %1
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = call i32 (...) @rand()
%17 = call signext i8 @randomChar(i32 %16)
%18 = load i8*, i8** %2
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 %17, i8* %21
br label %22
22: ; preds = %15
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %11
25: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @randomString(i8* %0) {
%2 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (...) @rand()
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 20
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = zext i32 %6 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = tail call i32 (...) @rand()
%13 = tail call signext i8 @randomChar(i32 %12)
%14 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 %13, i8* %14
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10, %1
ret void
}