#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 size_t u_int32_t;

/* Variables and functions */
int arc4random();
int strlen(char const *);
void randomString(char *str, int chars) {
  const char *alphanumeric = "abcdefghijklmnopqrstuvwxyz0123456789";
  int max = strlen(alphanumeric);
  int i = 0;
  for (; i < chars; i++) {
    u_int32_t j = arc4random() % (max - 1);
    str[i] = alphanumeric[j];
  }
  str[i + 1] = '\0';
}


x86 assembly (clang, -O0):
<randomString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1194 <randomString+0x74>
mov    $0x0,%al
call   1030 <arc4random@plt>
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114d <randomString+0x2d>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r12
lea    0xec8(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %r14d,%r14d
jle    1186 <randomString+0x66>
mov    %eax,%r13d
add    $0xffffffff,%r13d
mov    %r14d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <arc4random@plt>
cltd
idiv   %r13d
movslq %edx,%rax
movzbl (%rax,%r15,1),%eax
mov    %al,(%r12,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <randomString+0x40>
add    $0x1,%r14d
jmp    118c <randomString+0x6c>
mov    $0x1,%r14d
movb   $0x0,(%r12,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"abcdefghijklmnopqrstuvwxyz0123456789\00"
define void @randomString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
store i32 0, i32* %7
br label %11
11: ; preds = %29, %2
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = call i32 (...) @arc4random()
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 1
%19 = srem i32 %16, %18
%20 = sext i32 %19 to i64
store i64 %20, i64* %8
%21 = load i8*, i8** %5
%22 = load i64, i64* %8
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %3
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
br label %29
29: ; preds = %15
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %11
32: ; preds = %11
%33 = load i8*, i8** %3
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 0, i8* %37
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"abcdefghijklmnopqrstuvwxyz0123456789\00"
define void @randomString(i8* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %21
5: ; preds = %2
%6 = add nsw i32 %3, -1
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %16, %8 ]
%10 = tail call i32 (...) @arc4random()
%11 = srem i32 %10, %6
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [37 x i8], [37 x i8]* @.str, 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, %7
br i1 %17, label %18, label %8
18: ; preds = %8
%19 = add i32 %1, 1
%20 = zext i32 %19 to i64
br label %21
21: ; preds = %18, %2
%22 = phi i64 [ 1, %2 ], [ %20, %18 ]
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 0, i8* %23
ret void
}