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

/* Variables and functions */
int rand();
void get_strrnd(char *restrict s, int len) {
  static const char a[] =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
  while (len) {
    s[--len] = a[rand() % (int)(sizeof(a) - 1)];
  }
}


x86 assembly (clang, -O0):
<get_strrnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     115d <get_strrnd+0x4d>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3e,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xebe(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    111f <get_strrnd+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_strrnd>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1182 <get_strrnd+0x72>
mov    %esi,%r12d
movslq %esi,%rax
neg    %r12d
lea    (%rax,%rdi,1),%r14
add    $0xffffffffffffffff,%r14
lea    0xecc(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff84210843,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x5,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x6,%edx
mov    %ecx,%esi
sub    %edx,%esi
add    %ecx,%esi
add    %eax,%esi
movslq %esi,%rax
movzbl (%rax,%r15,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r12d
jne    1140 <get_strrnd+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@get_strrnd.a = internal constant [63 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890\00"
define void @get_strrnd(i8* noalias %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %5
5: ; preds = %8, %2
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 62
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [63 x i8], [63 x i8]* @get_strrnd.a, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -1
store i32 %16, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8 %13, i8* %18
br label %5
19: ; preds = %5
ret void
}

LLVM IR (-O2):
@get_strrnd.a = internal unnamed_addr constant [63 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890\00"
define void @get_strrnd(i8* noalias nocapture writeonly %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = sext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ %5, %4 ], [ %13, %6 ]
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 62
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [63 x i8], [63 x i8]* @get_strrnd.a, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = add nsw i64 %7, -1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %12, i8* %14
%15 = trunc i64 %13 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %6
17: ; preds = %6, %2
ret void
}