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


x86 assembly (clang, -O0):
<_random_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x24,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1186 <_random_buffer+0x66>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x24,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x40(%rbp,%rax,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    114b <_random_buffer+0x2b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_random_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1169 <_random_buffer+0x59>
mov    %rdi,%r14
mov    %esi,%r12d
lea    0xed7(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x38e38e39,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,8),%ecx
sub    %ecx,%eax
cltq
movzbl (%rax,%r15,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <_random_buffer+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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