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

/* Variables and functions */
int rand();
void random_string(char *s, const int len) {
  int i;
  static const char alphanum[] = "0123456789abcdefghijklmnopqrstuvwxyz";
  for (i = 0; i < len - 1; ++i)
    s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
  s[len - 1] = 0;
}


x86 assembly (clang, -O0):
<random_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    116d <random_string+0x5d>
mov    $0x0,%al
call   1030 <rand@plt>
cltq
mov    $0x24,%ecx
xor    %edx,%edx
div    %rcx
lea    0xeaf(%rip),%rax
mov    (%rax,%rdx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <random_string+0x16>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
lea    -0x1(%rsi),%r14d
cmp    $0x2,%esi
jl     1172 <random_string+0x62>
mov    %r14d,%ebp
movabs $0xe38e38e38e38e38f,%r15
38 8e e3
lea    0xec5(%rip),%r12
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1030 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
mul    %r15
shr    $0x3,%rdx
and    $0xfffffffffffffffc,%rdx
lea    (%rdx,%rdx,8),%rax
sub    %rax,%rcx
movzbl (%r12,%rcx,1),%eax
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <random_string+0x30>
movslq %r14d,%rax
movb   $0x0,0x0(%r13,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@random_string.alphanum = internal constant [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
define void @random_string(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %21, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %24
11: ; preds = %6
%12 = call i32 (...) @rand()
%13 = sext i32 %12 to i64
%14 = urem i64 %13, 36
%15 = getelementptr inbounds [37 x i8], [37 x i8]* @random_string.alphanum, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 %16, i8* %20
br label %21
21: ; preds = %11
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %6
24: ; preds = %6
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 0, i8* %29
ret void
}

LLVM IR (-O2):
@random_string.alphanum = internal unnamed_addr constant [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
define void @random_string(i8* nocapture writeonly %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %15, %7 ]
%9 = tail call i32 (...) @rand()
%10 = sext i32 %9 to i64
%11 = urem i64 %10, 36
%12 = getelementptr inbounds [37 x i8], [37 x i8]* @random_string.alphanum, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %13, i8* %14
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %17, label %7
17: ; preds = %7, %2
%18 = sext i32 %3 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 0, i8* %19
ret void
}