#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*/ entropy_clock();
int random();
char *rand_str(char *dst, int size) {
  static const char text[] = "abcdefghijklmnopqrstuvwxyz"
                             "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  entropy_clock();
  int i, len = random() % (size - 1);
  if (!len)
    len = 8;
  for (i = 0; i < len; ++i)
    dst[i] = text[random() % (sizeof text - 1)];
  dst[i] = '\0';
  entropy_clock();
  return dst;
}


x86 assembly (clang, -O0):
<rand_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <entropy_clock@plt>
mov    $0x0,%al
call   1040 <random@plt>
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    115a <rand_str+0x3a>
movl   $0x8,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <rand_str+0x83>
mov    $0x0,%al
call   1040 <random@plt>
cltq
mov    $0x34,%ecx
xor    %edx,%edx
div    %rcx
lea    0xe79(%rip),%rax
mov    (%rax,%rdx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1161 <rand_str+0x41>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1030 <entropy_clock@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_str>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <entropy_clock@plt>
xor    %eax,%eax
call   1040 <random@plt>
add    $0xffffffff,%r14d
cltd
idiv   %r14d
test   %edx,%edx
mov    $0x8,%eax
cmovne %edx,%eax
test   %eax,%eax
jle    119d <rand_str+0x7d>
mov    %eax,%ebp
movabs $0x4ec4ec4ec4ec4ec5,%r14
ec c4 4e
lea    0xe99(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <random@plt>
movslq %eax,%rcx
mov    %rcx,%rax
mul    %r14
shr    $0x4,%rdx
imul   $0x34,%rdx,%rax
sub    %rax,%rcx
movzbl (%r15,%rcx,1),%eax
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <rand_str+0x50>
movb   $0x0,(%r12,%rbp,1)
xor    %eax,%eax
call   1030 <entropy_clock@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@rand_str.text = internal constant [53 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @rand_str(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32 (...) @entropy_clock()
%8 = call i32 (...) @random()
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = srem i32 %8, %10
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 8, i32* %6
br label %15
15: ; preds = %14, %2
store i32 0, i32* %5
br label %16
16: ; preds = %30, %15
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = call i32 (...) @random()
%22 = sext i32 %21 to i64
%23 = urem i64 %22, 52
%24 = getelementptr inbounds [53 x i8], [53 x i8]* @rand_str.text, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
br label %30
30: ; preds = %20
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %16
33: ; preds = %16
%34 = load i8*, i8** %3
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = call i32 (...) @entropy_clock()
%39 = load i8*, i8** %3
ret i8* %39
}

LLVM IR (-O2):
@rand_str.text = internal unnamed_addr constant [53 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @rand_str(i8* returned writeonly %0, i32 %1) {
%3 = tail call i32 (...) @entropy_clock()
%4 = tail call i32 (...) @random()
%5 = add nsw i32 %1, -1
%6 = srem i32 %4, %5
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i32 8, i32 %6
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %2
%11 = zext i32 %8 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %20, %12 ]
%14 = tail call i32 (...) @random()
%15 = sext i32 %14 to i64
%16 = urem i64 %15, 52
%17 = getelementptr inbounds [53 x i8], [53 x i8]* @rand_str.text, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %18, i8* %19
%20 = add nuw nsw i64 %13, 1
%21 = icmp eq i64 %20, %11
br i1 %21, label %22, label %12
22: ; preds = %12
%23 = zext i32 %8 to i64
br label %24
24: ; preds = %2, %22
%25 = phi i64 [ %23, %22 ], [ 0, %2 ]
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 0, i8* %26
%27 = tail call i32 (...) @entropy_clock()
ret i8* %0
}