#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 */
struct timeval {
  int tv_usec;
};
typedef int /*<<< orphan*/ alphabets;

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int rand();
int /*<<< orphan*/ srand(int);
int sysapi_stringrand(char *elem, int len) {
  char alphabets[] = {
      'a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', 'g',
      'G', 'h', 'H', 'i', 'I', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M',
      'n', 'N', 'o', 'O', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S', 't',
      'T', 'u', 'U', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', 'z', 'Z',
  };
  int i;
  int seed;
  struct timeval tv;
  int size_alphabets = sizeof(alphabets) / sizeof(alphabets[0]);
  gettimeofday(&tv, 0);
  seed = tv.tv_usec;
  srand(seed);
  for (i = 0; i < len - 1; i++)
    elem[i] = alphabets[rand() % size_alphabets];
  elem[i] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<sysapi_stringrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x34,%edx
call   1050 <memcpy@plt>
movl   $0x34,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x50(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
call   1040 <srand@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c7 <sysapi_stringrand+0x87>
mov    $0x0,%al
call   1060 <rand@plt>
cltd
idivl  -0x54(%rbp)
movslq %edx,%rax
mov    -0x40(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    118b <sysapi_stringrand+0x4b>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysapi_stringrand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%edi
call   1040 <srand@plt>
cmp    $0x2,%r14d
jl     11a6 <sysapi_stringrand+0x76>
add    $0xffffffff,%r14d
mov    %r14d,%ebp
lea    0xe9b(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x24,%rcx
add    %edx,%ecx
imul   $0x34,%ecx,%ecx
sub    %ecx,%eax
cltq
movzbl (%rax,%r14,1),%eax
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <sysapi_stringrand+0x40>
movb   $0x0,(%r15,%rbp,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@__const.sysapi_stringrand.alphabets = [52 x i8] c"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"
define i32 @sysapi_stringrand(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [52 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = bitcast [52 x i8]* %5 to i8*
store i32 52, i32* %9
%11 = call i32 @gettimeofday(%struct.timeval* %8, i32 0)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%13 = load i32, i32* %12
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = call i32 @srand(i32 %14)
store i32 0, i32* %6
br label %16
16: ; preds = %32, %2
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %35
21: ; preds = %16
%22 = call i32 (...) @rand()
%23 = load i32, i32* %9
%24 = srem i32 %22, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [52 x i8], [52 x i8]* %5, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %3
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %21
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %16
35: ; preds = %16
%36 = load i8*, i8** %3
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@__const.sysapi_stringrand.alphabets = [52 x i8] c"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"
define i32 @sysapi_stringrand(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = call i32 @srand(i32 %7)
%9 = add i32 %1, -1
%10 = icmp sgt i32 %1, 1
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %21, %13 ]
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 52
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [52 x i8], [52 x i8]* @__const.sysapi_stringrand.alphabets, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %19, i8* %20
%21 = add nuw nsw i64 %14, 1
%22 = icmp eq i64 %21, %12
br i1 %22, label %23, label %13
23: ; preds = %13
%24 = zext i32 %9 to i64
br label %25
25: ; preds = %2, %23
%26 = phi i64 [ %24, %23 ], [ 0, %2 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 0, i8* %27
ret i32 0
}