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

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
size_t rand();
int /*<<< orphan*/ srand(scalar_t__);
size_t strlen(char *);
scalar_t__ time(int /*<<< orphan*/ *);
char *generate_password(int len) {
  int i;
  char *out = NULL;
  char h[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  out = (char *)malloc((len + 1) * sizeof(char));
  memset(out, 0, len + 1);
  srand(time(NULL) + rand());
  for (i = 0; i < len; i++)
    out[i] = h[rand() % strlen(h)];
  return out;
}


x86 assembly (clang, -O0):
<generate_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x3f,%edx
call   1060 <memcpy@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x58(%rbp),%rdi
add    %rax,%rdi
call   1050 <srand@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1230 <generate_password+0xc0>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    -0x50(%rbp,%rdx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e7 <generate_password+0x77>
mov    -0x10(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_password>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
lea    0x1(%r14),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1070 <rand@plt>
add    %rax,%rbp
mov    %rbp,%rdi
call   1040 <srand@plt>
test   %r14d,%r14d
jle    11e9 <generate_password+0x99>
mov    %r14d,%ebp
movabs $0x8421084210842109,%r14
08 21 84
lea    0xe56(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
mov    %rax,%rcx
shr    %rax
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
movzbl (%r15,%rsi,1),%eax
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <generate_password+0x60>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.generate_password.h = [63 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\00"
define i8* @generate_password(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [63 x i8]
store i32 %0, i32* %2
store i8* null, i8** %4
%6 = bitcast [63 x i8]* %5 to i8*
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 1
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
%17 = call i32 @memset(i8* %14, i32 0, i32 %16)
%18 = call i64 @time(i32* null)
%19 = call i64 (...) @rand()
%20 = add i64 %18, %19
%21 = call i32 @srand(i64 %20)
store i32 0, i32* %3
br label %22
22: ; preds = %37, %1
%23 = load i32, i32* %3
%24 = load i32, i32* %2
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %22
%27 = call i64 (...) @rand()
%28 = getelementptr inbounds [63 x i8], [63 x i8]* %5, i64 0, i64 0
%29 = call i64 @strlen(i8* %28)
%30 = urem i64 %27, %29
%31 = getelementptr inbounds [63 x i8], [63 x i8]* %5, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %4
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %26
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %22
40: ; preds = %22
%41 = load i8*, i8** %4
ret i8* %41
}

LLVM IR (-O2):
@__const.generate_password.h = [63 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\00"
define i8* @generate_password(i32 %0) {
%2 = add nsw i32 %0, 1
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @memset(i8* %4, i32 0, i32 %2)
%6 = tail call i64 @time(i32* null)
%7 = tail call i64 (...) @rand()
%8 = add i64 %7, %6
%9 = tail call i32 @srand(i64 %8)
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %22
11: ; preds = %1
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %20, %13 ]
%15 = tail call i64 (...) @rand()
%16 = urem i64 %15, 62
%17 = getelementptr inbounds [63 x i8], [63 x i8]* @__const.generate_password.h, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %4, i64 %14
store i8 %18, i8* %19
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %12
br i1 %21, label %22, label %13
22: ; preds = %13, %1
ret i8* %4
}