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

/* Variables and functions */
double RAND_MAX;
double rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int str_rand(char *s, int len) {
  char alphanum[64] =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\0";
  static unsigned int seq = 0;
  unsigned int idx, i;
  time_t lt;
  if (!s) {
    return -1;
  }
  lt = time(NULL);
  srand(lt);
  for (i = 0; i < len; ++i) {
    idx = (int)(61.0 * rand() / RAND_MAX);
    idx += seq;
    idx %= 62;
    s[i] = alphanum[idx];
  }
  s[i] = 0;
  ++seq;
  seq %= 62;
  return 0;
}


x86 assembly (clang, -O0):
<str_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
cmpq   $0x0,-0x10(%rbp)
jne    117b <str_rand+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    123a <str_rand+0xfa>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%edi
call   1030 <srand@plt>
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1204 <str_rand+0xc4>
mov    $0x0,%al
call   1060 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xe4c(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e29(%rip),%rax
divsd  (%rax),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x64(%rbp)
mov    0x2e78(%rip),%eax
add    -0x64(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x60(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x68(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1196 <str_rand+0x56>
mov    -0x10(%rbp),%rax
mov    -0x68(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    0x2e33(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e2a(%rip)
mov    0x2e24(%rip),%eax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,0x2e15(%rip)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_rand>:
test   %rdi,%rdi
je     11ce <str_rand+0x9e>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r13
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %ebp,%ebp
je     11d4 <str_rand+0xa4>
mov    %ebp,%ebp
mov    0x2e84(%rip),%r14
mov    $0x84210843,%r15d
lea    0xe9f(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <rand@plt>
mulsd  0xe71(%rip),%xmm0
divsd  (%r14),%xmm0
mov    0x2ea6(%rip),%eax
cvttsd2si %xmm0,%ecx
add    %eax,%ecx
mov    %ecx,%edx
shr    %edx
imul   %r15,%rdx
shr    $0x24,%rdx
mov    %edx,%esi
shl    $0x6,%esi
mov    %edx,%edi
sub    %esi,%edi
add    %edx,%edi
add    %ecx,%edi
movzbl (%rdi,%r12,1),%ecx
mov    %cl,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <str_rand+0x50>
jmp    11dc <str_rand+0xac>
mov    $0xffffffff,%eax
ret
mov    0x2e66(%rip),%eax
xor    %ebp,%ebp
movb   $0x0,0x0(%r13,%rbp,1)
lea    0x1(%rax),%ecx
shr    %ecx
mov    $0x84210843,%edx
imul   %rcx,%rdx
shr    $0x24,%rdx
mov    %edx,%ecx
shl    $0x6,%ecx
mov    %edx,%esi
sub    %ecx,%esi
add    %edx,%esi
add    %esi,%eax
add    $0x1,%eax
mov    %eax,0x2e36(%rip)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.str_rand.alphanum = [64 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\00\00"
@str_rand.seq = internal global i32 0
@RAND_MAX = global double 0.000000e+00
define i32 @str_rand(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = bitcast [64 x i8]* %6 to i8*
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 -1, i32* %3
br label %53
14: ; preds = %2
%15 = call i32 @time(i32* null)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = call i32 @srand(i32 %16)
store i32 0, i32* %8
br label %18
18: ; preds = %41, %14
%19 = load i32, i32* %8
%20 = load i32, i32* %5
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %44
22: ; preds = %18
%23 = call double (...) @rand()
%24 = fmul double 6.100000e+01, %23
%25 = load double, double* @RAND_MAX
%26 = fdiv double %24, %25
%27 = fptosi double %26 to i32
store i32 %27, i32* %7
%28 = load i32, i32* @str_rand.seq
%29 = load i32, i32* %7
%30 = add i32 %29, %28
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = urem i32 %31, 62
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = load i8*, i8** %4
%38 = load i32, i32* %8
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 %36, i8* %40
br label %41
41: ; preds = %22
%42 = load i32, i32* %8
%43 = add i32 %42, 1
store i32 %43, i32* %8
br label %18
44: ; preds = %18
%45 = load i8*, i8** %4
%46 = load i32, i32* %8
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
%49 = load i32, i32* @str_rand.seq
%50 = add i32 %49, 1
store i32 %50, i32* @str_rand.seq
%51 = load i32, i32* @str_rand.seq
%52 = urem i32 %51, 62
store i32 %52, i32* @str_rand.seq
store i32 0, i32* %3
br label %53
53: ; preds = %44, %13
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@__const.str_rand.alphanum = [64 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\00\00"
@str_rand.seq = internal unnamed_addr global i32 0
@RAND_MAX = global double 0.000000e+00
define i32 @str_rand(i8* writeonly %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %36, label %4
4: ; preds = %2
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = icmp eq i32 %1, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = load i32, i32* @str_rand.seq
br label %30
10: ; preds = %4
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %26, %12 ]
%14 = tail call double (...) @rand()
%15 = fmul double %14, 6.100000e+01
%16 = load double, double* @RAND_MAX
%17 = fdiv double %15, %16
%18 = fptosi double %17 to i32
%19 = load i32, i32* @str_rand.seq
%20 = add i32 %19, %18
%21 = urem i32 %20, 62
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.str_rand.alphanum, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %24, i8* %25
%26 = add nuw nsw i64 %13, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %28, label %12
28: ; preds = %12
%29 = zext i32 %1 to i64
br label %30
30: ; preds = %8, %28
%31 = phi i32 [ %9, %8 ], [ %19, %28 ]
%32 = phi i64 [ 0, %8 ], [ %29, %28 ]
%33 = getelementptr inbounds i8, i8* %0, i64 %32
store i8 0, i8* %33
%34 = add i32 %31, 1
%35 = urem i32 %34, 62
store i32 %35, i32* @str_rand.seq
br label %36
36: ; preds = %2, %30
%37 = phi i32 [ 0, %30 ], [ -1, %2 ]
ret i32 %37
}