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

/* Variables and functions */
int prng();
void random_string(char *buf, size_t len) {
  int i;
  int r;
  char str[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  for (i = 0; i < len; ++i) {
    r = prng();
    buf[i] = str[r % (sizeof(str) - 1)];
  }
}


x86 assembly (clang, -O0):
<random_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xec5(%rip),%rsi
mov    $0x3f,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118f <random_string+0x6f>
mov    $0x0,%al
call   1030 <prng@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x60(%rbp,%rdx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <random_string+0x2c>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     117c <random_string+0x6c>
mov    %rsi,%r13
mov    %rdi,%r14
movabs $0x8421084210842109,%r15
08 21 84
lea    0xecb(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <prng@plt>
movslq %eax,%rcx
mov    %rcx,%rax
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,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1140 <random_string+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.random_string.str = [63 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\00"
define void @random_string(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca [63 x i8]
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = bitcast [63 x i8]* %7 to i8*
store i32 0, i32* %5
br label %9
9: ; preds = %25, %2
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = load i64, i64* %4
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %9
%15 = call i32 (...) @prng()
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = urem i64 %17, 62
%19 = getelementptr inbounds [63 x i8], [63 x i8]* %7, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 %20, i8* %24
br label %25
25: ; preds = %14
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %9
28: ; preds = %9
ret void
}

LLVM IR (-O2):
@__const.random_string.str = [63 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\00"
define void @random_string(i8* nocapture writeonly %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %14, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %12, %4 ], [ 0, %2 ]
%6 = tail call i32 (...) @prng()
%7 = sext i32 %6 to i64
%8 = urem i64 %7, 62
%9 = getelementptr inbounds [63 x i8], [63 x i8]* @__const.random_string.str, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 %10, i8* %11
%12 = add nuw i64 %5, 1
%13 = icmp eq i64 %12, %1
br i1 %13, label %14, label %4
14: ; preds = %4, %2
ret void
}