#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*/ alpha_numbers;

/* Variables and functions */
int /*<<< orphan*/ generateRandomSeed();
size_t const random();
char *CUTIL_GenerateRandomString(char *buf, size_t size) {
  static const char alpha_numbers[] = "0123456789"
                                      "abcdefghijklmnopqrstuvwxyz"
                                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  static const size_t max_size = sizeof(alpha_numbers) - 1;
  if (!buf) {
    return NULL;
  }
  generateRandomSeed();
  char *p = buf;
  for (size_t i = 0; i < size; ++i, ++p) {
    *p = alpha_numbers[random() % max_size];
  }
  return buf;
}


x86 assembly (clang, -O0):
<CUTIL_GenerateRandomString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1148 <CUTIL_GenerateRandomString+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11b3 <CUTIL_GenerateRandomString+0x93>
mov    $0x0,%al
call   1030 <generateRandomSeed@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ab <CUTIL_GenerateRandomString+0x8b>
mov    $0x0,%al
call   1040 <random@plt>
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
lea    0xe7b(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115f <CUTIL_GenerateRandomString+0x3f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CUTIL_GenerateRandomString>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r13
test   %rdi,%rdi
je     119a <CUTIL_GenerateRandomString+0x7a>
mov    %rsi,%r14
xor    %eax,%eax
call   1030 <generateRandomSeed@plt>
test   %r14,%r14
je     119a <CUTIL_GenerateRandomString+0x7a>
movabs $0x8421084210842109,%r15
08 21 84
lea    0xeaf(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <random@plt>
mov    %rax,%rcx
shr    %rax
mul    %r15
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
movzbl (%r12,%rsi,1),%eax
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <CUTIL_GenerateRandomString+0x40>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@CUTIL_GenerateRandomString.alpha_numbers = internal constant [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@CUTIL_GenerateRandomString.max_size = internal constant i64 62
define i8* @CUTIL_GenerateRandomString(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %2
store i8* null, i8** %3
br label %31
11: ; preds = %2
%12 = call i32 (...) @generateRandomSeed()
%13 = load i8*, i8** %4
store i8* %13, i8** %6
store i64 0, i64* %7
br label %14
14: ; preds = %24, %11
%15 = load i64, i64* %7
%16 = load i64, i64* %5
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = call i64 (...) @random()
%20 = urem i64 %19, 62
%21 = getelementptr inbounds [63 x i8], [63 x i8]* @CUTIL_GenerateRandomString.alpha_numbers, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = load i8*, i8** %6
store i8 %22, i8* %23
br label %24
24: ; preds = %18
%25 = load i64, i64* %7
%26 = add i64 %25, 1
store i64 %26, i64* %7
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
br label %14
29: ; preds = %14
%30 = load i8*, i8** %4
store i8* %30, i8** %3
br label %31
31: ; preds = %29, %10
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
@CUTIL_GenerateRandomString.alpha_numbers = internal unnamed_addr constant [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @CUTIL_GenerateRandomString(i8* writeonly %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = tail call i32 (...) @generateRandomSeed()
%6 = icmp eq i64 %1, 0
br i1 %6, label %17, label %7
7: ; preds = %4, %7
%8 = phi i64 [ %14, %7 ], [ 0, %4 ]
%9 = phi i8* [ %15, %7 ], [ %0, %4 ]
%10 = tail call i64 (...) @random()
%11 = urem i64 %10, 62
%12 = getelementptr inbounds [63 x i8], [63 x i8]* @CUTIL_GenerateRandomString.alpha_numbers, i64 0, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %9
%14 = add nuw i64 %8, 1
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = icmp eq i64 %14, %1
br i1 %16, label %17, label %7
17: ; preds = %7, %4, %2
ret i8* %0
}