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

/* Variables and functions */
int rand();
void strrand(char *s, size_t len) {
  const char dict[] = "abcdefghijklmnopqrstuvwxyz"
                      "0123456789"
                      "{}()<>"
                      "*-+~";
  if (0 == len) {
    return;
  }
  while (len > 1) {
    *s = dict[rand() % ((sizeof(dict) / sizeof(dict[0])) - 1)];
    ++s;
    --len;
  }
  *s = 0;
}


x86 assembly (clang, -O0):
<strrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xec5(%rip),%rsi
mov    $0x2f,%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1156 <strrand+0x36>
jmp    11a7 <strrand+0x87>
jmp    115b <strrand+0x3b>
cmpq   $0x1,-0x10(%rbp)
jbe    11a0 <strrand+0x80>
mov    $0x0,%al
call   1040 <rand@plt>
cltq
mov    $0x2e,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x40(%rbp,%rdx,1),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    115b <strrand+0x3b>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrand>:
test   %rsi,%rsi
je     1183 <strrand+0x73>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
cmp    $0x1,%rsi
je     1174 <strrand+0x64>
movabs $0xb21642c8590b2165,%r15
42 16 b2
lea    0xec6(%rip),%r12
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r15
shr    $0x4,%rdx
imul   $0x2e,%rdx,%rax
sub    %rax,%rcx
movzbl (%r12,%rcx,1),%eax
mov    %al,(%r14)
add    $0x1,%r14
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1140 <strrand+0x30>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.strrand.dict = [47 x i8] c"abcdefghijklmnopqrstuvwxyz0123456789{}()<>*-+~\00"
define void @strrand(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [47 x i8]
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = bitcast [47 x i8]* %5 to i8*
%7 = load i64, i64* %4
%8 = icmp eq i64 0, %7
br i1 %8, label %9, label %10
9: ; preds = %2
br label %27
10: ; preds = %2
br label %11
11: ; preds = %14, %10
%12 = load i64, i64* %4
%13 = icmp ugt i64 %12, 1
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = call i32 (...) @rand()
%16 = sext i32 %15 to i64
%17 = urem i64 %16, 46
%18 = getelementptr inbounds [47 x i8], [47 x i8]* %5, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = load i8*, i8** %3
store i8 %19, i8* %20
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
%23 = load i64, i64* %4
%24 = add i64 %23, -1
store i64 %24, i64* %4
br label %11
25: ; preds = %11
%26 = load i8*, i8** %3
store i8 0, i8* %26
br label %27
27: ; preds = %25, %9
ret void
}

LLVM IR (-O2):
@__const.strrand.dict = [47 x i8] c"abcdefghijklmnopqrstuvwxyz0123456789{}()<>*-+~\00"
define void @strrand(i8* nocapture writeonly %0, i64 %1) {
switch i64 %1, label %3 [
i64 0, label %16
i64 1, label %14
]
3: ; preds = %2, %3
%4 = phi i64 [ %12, %3 ], [ %1, %2 ]
%5 = phi i8* [ %11, %3 ], [ %0, %2 ]
%6 = tail call i32 (...) @rand()
%7 = sext i32 %6 to i64
%8 = urem i64 %7, 46
%9 = getelementptr inbounds [47 x i8], [47 x i8]* @__const.strrand.dict, i64 0, i64 %8
%10 = load i8, i8* %9
store i8 %10, i8* %5
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = add i64 %4, -1
%13 = icmp ugt i64 %12, 1
br i1 %13, label %3, label %14
14: ; preds = %3, %2
%15 = phi i8* [ %0, %2 ], [ %11, %3 ]
store i8 0, i8* %15
br label %16
16: ; preds = %2, %14
ret void
}