#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 */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int rand();
void random_key(char *key, int length) {
  char salt[36] = "abcdefghijklmnopqrstuvwxyz0123456789";
  memset(key, 0, length);
  for (int i = 0; i < length; i++)
    key[i] = salt[rand() % length];
}


x86 assembly (clang, -O0):
<random_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x24,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a0 <random_key+0x70>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0xc(%rbp)
movslq %edx,%rax
mov    -0x30(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1169 <random_key+0x39>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_key>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%r14
xor    %esi,%esi
mov    %r12d,%edx
call   1030 <memset@plt>
test   %r12d,%r12d
jle    1170 <random_key+0x50>
mov    %r12d,%ebx
lea    0xeb9(%rip),%r15
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %r12d
movslq %edx,%rax
movzbl (%rax,%r15,1),%eax
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1150 <random_key+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.random_key.salt = [36 x i8] c"abcdefghijklmnopqrstuvwxyz0123456789"
define void @random_key(i8* %0, i32 %1) {
%3 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %8
7: ; preds = %8, %2
ret void
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %16, %8 ]
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [36 x i8], [36 x i8]* @__const.random_key.salt, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %14, i8* %15
%16 = add nuw nsw i64 %9, 1
%17 = icmp eq i64 %16, %6
br i1 %17, label %7, label %8
}