#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 uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ alphaset;

/* Variables and functions */
int rand_next();
void rand_alphastr(uint8_t *str, int len) {
  const char alphaset[] = "abcdefghijklmnopqrstuvw012345678";
  while (len > 0) {
    if (len >= sizeof(uint32_t)) {
      int i;
      uint32_t entropy = rand_next();
      for (i = 0; i < sizeof(uint32_t); i++) {
        uint8_t tmp = entropy & 0xff;
        entropy = entropy >> 8;
        tmp = tmp >> 3;
        *str++ = alphaset[tmp];
      }
      len -= sizeof(uint32_t);
    } else {
      *str++ = rand_next() % (sizeof(alphaset));
      len--;
    }
  }
}


x86 assembly (clang, -O0):
<rand_alphastr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x21,%edx
call   1040 <memcpy@plt>
cmpl   $0x0,-0xc(%rbp)
jle    1204 <rand_alphastr+0xe4>
movslq -0xc(%rbp),%rax
cmp    $0x4,%rax
jb     11d0 <rand_alphastr+0xb0>
mov    $0x0,%al
call   1030 <rand_next@plt>
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x4,%rax
jae    11c0 <rand_alphastr+0xa0>
mov    -0x38(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
sar    $0x3,%eax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116d <rand_alphastr+0x4d>
movslq -0xc(%rbp),%rax
sub    $0x4,%rax
mov    %eax,-0xc(%rbp)
jmp    11ff <rand_alphastr+0xdf>
mov    $0x0,%al
call   1030 <rand_next@plt>
cltq
mov    $0x21,%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <rand_alphastr+0x24>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_alphastr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    11b6 <rand_alphastr+0xa6>
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xed5(%rip),%r14
movabs $0xf83e0f83e0f83e1,%r15
e0 83 0f
jmp    1164 <rand_alphastr+0x54>
nopw   0x0(%rax,%rax,1)
movslq %eax,%rcx
mov    %rcx,%rax
mul    %r15
shr    %rdx
mov    %edx,%eax
shl    $0x5,%eax
add    %edx,%eax
sub    %eax,%ecx
mov    %ecx,(%rbx)
mov    $0xffffffff,%eax
add    $0x4,%rbx
add    %eax,%ebp
je     11b6 <rand_alphastr+0xa6>
xor    %eax,%eax
call   1030 <rand_next@plt>
cmp    $0x4,%ebp
jb     1140 <rand_alphastr+0x30>
mov    %eax,%ecx
shr    $0xb,%ecx
mov    %eax,%edx
shr    $0x3,%edx
and    $0x1f,%edx
movsbl (%rdx,%r14,1),%edx
mov    %edx,(%rbx)
and    $0x1f,%ecx
movsbl (%rcx,%r14,1),%ecx
mov    %ecx,0x4(%rbx)
mov    %eax,%ecx
shr    $0x13,%eax
shr    $0x1b,%rcx
and    $0x1f,%eax
movsbl (%rax,%r14,1),%eax
mov    %eax,0x8(%rbx)
movsbl (%rcx,%r14,1),%eax
mov    %eax,0xc(%rbx)
add    $0xc,%rbx
mov    $0xfffffffc,%eax
jmp    115c <rand_alphastr+0x4c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.rand_alphastr.alphaset = [33 x i8] c"abcdefghijklmnopqrstuvw012345678\00"
define void @rand_alphastr(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [33 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = bitcast [33 x i8]* %5 to i8*
br label %10
10: ; preds = %54, %2
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %55
13: ; preds = %10
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = icmp uge i64 %15, 4
br i1 %16, label %17, label %45
17: ; preds = %13
%18 = call i32 (...) @rand_next()
store i32 %18, i32* %7
store i32 0, i32* %6
br label %19
19: ; preds = %37, %17
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = icmp ult i64 %21, 4
br i1 %22, label %23, label %40
23: ; preds = %19
%24 = load i32, i32* %7
%25 = and i32 %24, 255
store i32 %25, i32* %8
%26 = load i32, i32* %7
%27 = ashr i32 %26, 8
store i32 %27, i32* %7
%28 = load i32, i32* %8
%29 = ashr i32 %28, 3
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [33 x i8], [33 x i8]* %5, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = load i32*, i32** %3
%36 = getelementptr inbounds i32, i32* %35, i32 1
store i32* %36, i32** %3
store i32 %34, i32* %35
br label %37
37: ; preds = %23
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %19
40: ; preds = %19
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = sub i64 %42, 4
%44 = trunc i64 %43 to i32
store i32 %44, i32* %4
br label %54
45: ; preds = %13
%46 = call i32 (...) @rand_next()
%47 = sext i32 %46 to i64
%48 = urem i64 %47, 33
%49 = trunc i64 %48 to i32
%50 = load i32*, i32** %3
%51 = getelementptr inbounds i32, i32* %50, i32 1
store i32* %51, i32** %3
store i32 %49, i32* %50
%52 = load i32, i32* %4
%53 = add nsw i32 %52, -1
store i32 %53, i32* %4
br label %54
54: ; preds = %45, %40
br label %10
55: ; preds = %10
ret void
}

LLVM IR (-O2):
@__const.rand_alphastr.alphaset = [33 x i8] c"abcdefghijklmnopqrstuvw012345678\00"
define void @rand_alphastr(i32* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %46
4: ; preds = %2, %40
%5 = phi i32* [ %44, %40 ], [ %0, %2 ]
%6 = phi i32 [ %43, %40 ], [ %1, %2 ]
%7 = icmp ugt i32 %6, 3
%8 = tail call i32 (...) @rand_next()
br i1 %7, label %9, label %36
9: ; preds = %4
%10 = lshr i32 %8, 11
%11 = lshr i32 %8, 3
%12 = and i32 %11, 31
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [33 x i8], [33 x i8]* @__const.rand_alphastr.alphaset, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = getelementptr inbounds i32, i32* %5, i64 1
store i32 %16, i32* %5
%18 = lshr i32 %8, 19
%19 = and i32 %10, 31
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [33 x i8], [33 x i8]* @__const.rand_alphastr.alphaset, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = getelementptr inbounds i32, i32* %5, i64 2
store i32 %23, i32* %17
%25 = lshr i32 %8, 27
%26 = and i32 %18, 31
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [33 x i8], [33 x i8]* @__const.rand_alphastr.alphaset, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = getelementptr inbounds i32, i32* %5, i64 3
store i32 %30, i32* %24
%32 = zext i32 %25 to i64
%33 = getelementptr inbounds [33 x i8], [33 x i8]* @__const.rand_alphastr.alphaset, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
store i32 %35, i32* %31
br label %40
36: ; preds = %4
%37 = sext i32 %8 to i64
%38 = urem i64 %37, 33
%39 = trunc i64 %38 to i32
store i32 %39, i32* %5
br label %40
40: ; preds = %36, %9
%41 = phi i32 [ -1, %36 ], [ -4, %9 ]
%42 = phi i32* [ %5, %36 ], [ %31, %9 ]
%43 = add nsw i32 %6, %41
%44 = getelementptr inbounds i32, i32* %42, i64 1
%45 = icmp eq i32 %43, 0
br i1 %45, label %46, label %4
46: ; preds = %40, %2
ret void
}