#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 */
typedef int /*<<< orphan*/ charset;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *r_utils_alea_filename(char *file, int len) {
  static int seeded = 0;
  const char charset[] =
      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
  int i;
  assert(len > 0);
  assert(file != NULL);
  if (!seeded) {
    srand(time(NULL));
    seeded = 1;
  }
  for (i = 0; i < len; i++) {
    file[i] = charset[rand() % (sizeof(charset) - 1)];
  }
  file[len - 1] = 0;
  return file;
}


x86 assembly (clang, -O0):
<r_utils_alea_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
cmpl   $0x0,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,0x2eae(%rip)
jne    11be <r_utils_alea_filename+0x6e>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x1,0x2e8e(%rip)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1201 <r_utils_alea_filename+0xb1>
mov    $0x0,%al
call   1070 <rand@plt>
cltq
mov    $0x3f,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x50(%rbp,%rdx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11c5 <r_utils_alea_filename+0x75>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r_utils_alea_filename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r13
xor    %edi,%edi
test   %esi,%esi
setg   %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   1040 <assert@plt>
cmpb   $0x0,0x2ed1(%rip)
jne    118a <r_utils_alea_filename+0x4a>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movb   $0x1,0x2eba(%rip)
test   %r14d,%r14d
jle    11f0 <r_utils_alea_filename+0xb0>
mov    %r14d,%ebp
movabs $0x410410410410411,%r15
41 10 04
lea    0xe5d(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
mul    %r15
mov    %rcx,%rax
sub    %rdx,%rax
shr    %rax
add    %rdx,%rax
shr    $0x5,%rax
mov    %rax,%rdx
shl    $0x6,%rdx
sub    %rdx,%rax
add    %rcx,%rax
movzbl (%r12,%rax,1),%eax
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <r_utils_alea_filename+0x70>
movslq %r14d,%rax
movb   $0x0,-0x1(%rax,%r13,1)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@r_utils_alea_filename.seeded = internal global i32 0
@__const.r_utils_alea_filename.charset = [64 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\00"
define i8* @r_utils_alea_filename(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [64 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = bitcast [64 x i8]* %5 to i8*
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* @r_utils_alea_filename.seeded
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = call i32 @time(i32* null)
%20 = call i32 @srand(i32 %19)
store i32 1, i32* @r_utils_alea_filename.seeded
br label %21
21: ; preds = %18, %2
store i32 0, i32* %6
br label %22
22: ; preds = %36, %21
%23 = load i32, i32* %6
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = call i32 (...) @rand()
%28 = sext i32 %27 to i64
%29 = urem i64 %28, 63
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %3
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %26
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %22
39: ; preds = %22
%40 = load i8*, i8** %3
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %3
ret i8* %45
}

LLVM IR (-O2):
@r_utils_alea_filename.seeded = internal unnamed_addr global i1 false
@__const.r_utils_alea_filename.charset = [64 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\00"
define i8* @r_utils_alea_filename(i8* returned writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne i8* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = load i1, i1* @r_utils_alea_filename.seeded
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = tail call i32 @time(i32* null)
%12 = tail call i32 @srand(i32 %11)
store i1 true, i1* @r_utils_alea_filename.seeded
br label %13
13: ; preds = %10, %2
br i1 %3, label %14, label %26
14: ; preds = %13
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %24, %16 ]
%18 = tail call i32 (...) @rand()
%19 = sext i32 %18 to i64
%20 = urem i64 %19, 63
%21 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.r_utils_alea_filename.charset, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 %22, i8* %23
%24 = add nuw nsw i64 %17, 1
%25 = icmp eq i64 %24, %15
br i1 %25, label %26, label %16
26: ; preds = %16, %13
%27 = add nsw i32 %1, -1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 0, i8* %29
ret i8* %0
}