#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;
  int tv_sec;
};
typedef int /*<<< orphan*/ alphanum;

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t const);
int rand();
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ strncpy(char *, char *, size_t const);
char *gen_random_str(char **dst, const size_t len) {
  struct timeval t1;
  char s[len + 1];
  static const char alphanum[] = "0123456789"
                                 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                 "abcdefghijklmnopqrstuvwxyz";
  gettimeofday(&t1, NULL);
  srand(t1.tv_usec * t1.tv_sec);
  memset(s, 0, len + 1);
  for (size_t i = 0; i < len; ++i) {
    s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
  }
  if (dst) {
    if (*dst) {
      strncpy(*dst, s, len);
    }
  }
  (*dst)[len] = '\0';
  return (*dst);
}


x86 assembly (clang, -O0):
<gen_random_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
mov    %rdx,%rax
add    $0x1,%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
add    $0x10,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%edi
imul   -0x14(%rbp),%edi
call   1060 <srand@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1050 <memset@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1206 <gen_random_str+0xb6>
mov    $0x0,%al
call   1070 <rand@plt>
cltq
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x38(%rbp),%rax
lea    0xe15(%rip),%rcx
mov    (%rcx,%rdx,1),%dl
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11bf <gen_random_str+0x6f>
cmpq   $0x0,-0x8(%rbp)
je     1238 <gen_random_str+0xe8>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1233 <gen_random_str+0xe3>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
call   1030 <strncpy@plt>
jmp    1238 <gen_random_str+0xe8>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_random_str>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,-0x40(%rbp)
mov    %rsp,-0x38(%rbp)
lea    0x1(%rsi),%r12
mov    %rsp,%rbx
lea    0x10(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    -0x2c(%rbp),%edi
imul   -0x30(%rbp),%edi
call   1060 <srand@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1050 <memset@plt>
test   %r15,%r15
je     11fd <gen_random_str+0xad>
movabs $0x8421084210842109,%r12
08 21 84
lea    0xe45(%rip),%r13
xor    %r14d,%r14d
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r12
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
movzbl 0x0(%r13,%rsi,1),%eax
mov    %al,(%rbx,%r14,1)
add    $0x1,%r14
cmp    %r14,%r15
jne    11c0 <gen_random_str+0x70>
mov    -0x40(%rbp),%r14
test   %r14,%r14
je     1219 <gen_random_str+0xc9>
mov    (%r14),%rdi
test   %rdi,%rdi
je     1219 <gen_random_str+0xc9>
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <strncpy@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%r15,1)
mov    (%r14),%rax
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@gen_random_str.alphanum = internal constant [63 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
define i8* @gen_random_str(i8** %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i64
%5 = alloca %struct.timeval
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8** %0, i8*** %3
store i64 %1, i64* %4
%9 = load i64, i64* %4
%10 = add i64 %9, 1
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%17 = load i32, i32* %16
%18 = mul nsw i32 %15, %17
%19 = call i32 @srand(i32 %18)
%20 = load i64, i64* %4
%21 = add i64 %20, 1
%22 = call i32 @memset(i8* %12, i32 0, i64 %21)
store i64 0, i64* %8
br label %23
23: ; preds = %35, %2
%24 = load i64, i64* %8
%25 = load i64, i64* %4
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = call i32 (...) @rand()
%29 = sext i32 %28 to i64
%30 = urem i64 %29, 62
%31 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_random_str.alphanum, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = load i64, i64* %8
%34 = getelementptr inbounds i8, i8* %12, i64 %33
store i8 %32, i8* %34
br label %35
35: ; preds = %27
%36 = load i64, i64* %8
%37 = add i64 %36, 1
store i64 %37, i64* %8
br label %23
38: ; preds = %23
%39 = load i8**, i8*** %3
%40 = icmp ne i8** %39, null
br i1 %40, label %41, label %51
41: ; preds = %38
%42 = load i8**, i8*** %3
%43 = load i8*, i8** %42
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %50
45: ; preds = %41
%46 = load i8**, i8*** %3
%47 = load i8*, i8** %46
%48 = load i64, i64* %4
%49 = call i32 @strncpy(i8* %47, i8* %12, i64 %48)
br label %50
50: ; preds = %45, %41
br label %51
51: ; preds = %50, %38
%52 = load i8**, i8*** %3
%53 = load i8*, i8** %52
%54 = load i64, i64* %4
%55 = getelementptr inbounds i8, i8* %53, i64 %54
store i8 0, i8* %55
%56 = load i8**, i8*** %3
%57 = load i8*, i8** %56
%58 = load i8*, i8** %6
ret i8* %57
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@gen_random_str.alphanum = internal unnamed_addr constant [63 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
define i8* @gen_random_str(i8** %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = add i64 %1, 1
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, %10
%14 = tail call i32 @srand(i32 %13)
%15 = call i32 @memset(i8* %7, i32 0, i64 %5)
%16 = icmp eq i64 %1, 0
br i1 %16, label %17, label %19
17: ; preds = %19, %2
%18 = icmp eq i8** %0, null
br i1 %18, label %34, label %29
19: ; preds = %2, %19
%20 = phi i64 [ %27, %19 ], [ 0, %2 ]
%21 = call i32 (...) @rand()
%22 = sext i32 %21 to i64
%23 = urem i64 %22, 62
%24 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_random_str.alphanum, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %7, i64 %20
store i8 %25, i8* %26
%27 = add nuw i64 %20, 1
%28 = icmp eq i64 %27, %1
br i1 %28, label %17, label %19
29: ; preds = %17
%30 = load i8*, i8** %0
%31 = icmp eq i8* %30, null
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @strncpy(i8* %30, i8* %7, i64 %1)
br label %34
34: ; preds = %29, %32, %17
%35 = load i8*, i8** %0
%36 = getelementptr inbounds i8, i8* %35, i64 %1
store i8 0, i8* %36
%37 = load i8*, i8** %0
ret i8* %37
}