#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 *rand_str(char *dst, int size) {
  static const char text[] = "abcdefghijklmnopqrstuvwxyz"
                             "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int i, len = rand() % (size - 1);
  if (!len)
    len = 8;
  for (i = 0; i < len; ++i)
    dst[i] = text[rand() % (sizeof text - 1)];
  dst[i] = '\0';
  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 <rand@plt>
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1143 <rand_str+0x33>
movl   $0x8,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118c <rand_str+0x7c>
mov    $0x0,%al
call   1030 <rand@plt>
cltq
mov    $0x34,%ecx
xor    %edx,%edx
div    %rcx
lea    0xe90(%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    114a <rand_str+0x3a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
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 <rand@plt>
add    $0xffffffff,%r14d
cltd
idiv   %r14d
test   %edx,%edx
mov    $0x8,%eax
cmovne %edx,%eax
test   %eax,%eax
jle    118d <rand_str+0x7d>
mov    %eax,%ebp
movabs $0x4ec4ec4ec4ec4ec5,%r14
ec c4 4e
lea    0xeb0(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@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    1160 <rand_str+0x50>
movb   $0x0,(%r12,%rbp,1)
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 (...) @rand()
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = srem i32 %7, %9
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 8, i32* %6
br label %14
14: ; preds = %13, %2
store i32 0, i32* %5
br label %15
15: ; preds = %29, %14
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = call i32 (...) @rand()
%21 = sext i32 %20 to i64
%22 = urem i64 %21, 52
%23 = getelementptr inbounds [53 x i8], [53 x i8]* @rand_str.text, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
br label %29
29: ; preds = %19
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %15
32: ; preds = %15
%33 = load i8*, i8** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %3
ret i8* %37
}

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 (...) @rand()
%4 = add nsw i32 %1, -1
%5 = srem i32 %3, %4
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i32 8, i32 %5
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %19, %11 ]
%13 = tail call i32 (...) @rand()
%14 = sext i32 %13 to i64
%15 = urem i64 %14, 52
%16 = getelementptr inbounds [53 x i8], [53 x i8]* @rand_str.text, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 %17, i8* %18
%19 = add nuw nsw i64 %12, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %21, label %11
21: ; preds = %11
%22 = zext i32 %7 to i64
br label %23
23: ; preds = %2, %21
%24 = phi i64 [ %22, %21 ], [ 0, %2 ]
%25 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 0, i8* %25
ret i8* %0
}