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

/* Variables and functions */
size_t rand();
size_t strlen(char *);
void random_string(char *str, size_t len) {
  size_t i, alnumlen;
  static char alnum[] = "1234567890"
                        "abcdefghijklmnopqrstuvwxyz"
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  alnumlen = strlen(alnum);
  for (i = 0; i < len - 1; i++)
    str[i] = alnum[rand() % alnumlen];
  str[len - 1] = '\0';
}


x86 assembly (clang, -O0):
<random_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0x2f09(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1192 <random_string+0x72>
mov    $0x0,%al
call   1040 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
lea    0x2ecd(%rip),%rax
mov    (%rax,%rdx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1148 <random_string+0x28>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x2f0a(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0xffffffffffffffff,%r12
je     1181 <random_string+0x61>
mov    %rax,%r13
xor    %ebx,%ebx
jmp    1167 <random_string+0x47>
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %r13
movzbl (%rdx,%r15,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1181 <random_string+0x61>
xor    %eax,%eax
call   1040 <rand@plt>
mov    %rax,%rcx
or     %r13,%rcx
shr    $0x20,%rcx
jne    1150 <random_string+0x30>
xor    %edx,%edx
div    %r13d
jmp    1155 <random_string+0x35>
movb   $0x0,(%r14,%r12,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@random_string.alnum = internal global [63 x i8] c"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define void @random_string(i8* nocapture writeonly %0, i64 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @random_string.alnum, i64 0, i64 0))
%4 = add i64 %1, -1
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %2, %6
%7 = phi i64 [ %13, %6 ], [ 0, %2 ]
%8 = tail call i64 (...) @rand()
%9 = urem i64 %8, %3
%10 = getelementptr inbounds [63 x i8], [63 x i8]* @random_string.alnum, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 %11, i8* %12
%13 = add nuw i64 %7, 1
%14 = icmp eq i64 %13, %4
br i1 %14, label %15, label %6
15: ; preds = %6, %2
%16 = getelementptr inbounds i8, i8* %0, i64 %4
store i8 0, i8* %16
ret void
}