#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 */
int rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
char *genera_cadena(char *str, unsigned int length, const int mode) {
  unsigned int i = 0;
  static const char charset1[64] =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  static const char charset2[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
  srand((unsigned int)time(NULL));
  for (i = 0; i < length - 1; ++i) {
    if (mode == 1)
      str[i] = charset1[rand() % 64];
    else
      str[i] = charset2[rand() % 36];
  }
  str[length - 1] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<genera_cadena>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    11df <genera_cadena+0xaf>
cmpl   $0x1,-0x10(%rbp)
jne    11a6 <genera_cadena+0x76>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x40,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xe6c(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    11cc <genera_cadena+0x9c>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x24,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xe81(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    11d1 <genera_cadena+0xa1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <genera_cadena+0x30>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genera_cadena>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%r13
xor    %ebp,%ebp
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
add    $0xffffffff,%r14d
je     11c5 <genera_cadena+0x95>
mov    %r14d,%ebp
lea    0xe9c(%rip),%r14
lea    0xed5(%rip),%r12
xor    %ebx,%ebx
jmp    11a4 <genera_cadena+0x74>
nop
cltq
imul   $0x38e38e39,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,8),%ecx
sub    %ecx,%eax
cltq
add    %r12,%rax
movzbl (%rax),%eax
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11c5 <genera_cadena+0x95>
xor    %eax,%eax
call   1050 <rand@plt>
cmp    $0x1,%r15d
jne    1170 <genera_cadena+0x40>
lea    0x3f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffc0,%ecx
sub    %ecx,%eax
cltq
add    %r14,%rax
jmp    1193 <genera_cadena+0x63>
movb   $0x0,0x0(%r13,%rbp,1)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@genera_cadena.charset1 = internal constant [64 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
@genera_cadena.charset2 = internal constant [36 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz"
define i8* @genera_cadena(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = call i64 @time(i32* null)
%9 = trunc i64 %8 to i32
%10 = call i32 @srand(i32 %9)
store i32 0, i32* %7
br label %11
11: ; preds = %40, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = sub i32 %13, 1
%15 = icmp ult i32 %12, %14
br i1 %15, label %16, label %43
16: ; preds = %11
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 64
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [64 x i8], [64 x i8]* @genera_cadena.charset1, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
br label %39
29: ; preds = %16
%30 = call i32 (...) @rand()
%31 = srem i32 %30, 36
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [36 x i8], [36 x i8]* @genera_cadena.charset2, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = load i8*, i8** %4
%36 = load i32, i32* %7
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
br label %39
39: ; preds = %29, %19
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add i32 %41, 1
store i32 %42, i32* %7
br label %11
43: ; preds = %11
%44 = load i8*, i8** %4
%45 = load i32, i32* %5
%46 = sub i32 %45, 1
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %4
ret i8* %49
}

LLVM IR (-O2):
@genera_cadena.charset1 = internal unnamed_addr constant [64 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
@genera_cadena.charset2 = internal unnamed_addr constant [36 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz"
define i8* @genera_cadena(i8* returned writeonly %0, i32 %1, i32 %2) {
%4 = tail call i64 @time(i32* null)
%5 = trunc i64 %4 to i32
%6 = tail call i32 @srand(i32 %5)
%7 = add i32 %1, -1
%8 = icmp eq i32 %7, 0
br i1 %8, label %29, label %9
9: ; preds = %3
%10 = icmp eq i32 %2, 1
%11 = zext i32 %7 to i64
br label %12
12: ; preds = %9, %23
%13 = phi i64 [ 0, %9 ], [ %27, %23 ]
%14 = tail call i32 (...) @rand()
br i1 %10, label %15, label %19
15: ; preds = %12
%16 = srem i32 %14, 64
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [64 x i8], [64 x i8]* @genera_cadena.charset1, i64 0, i64 %17
br label %23
19: ; preds = %12
%20 = srem i32 %14, 36
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [36 x i8], [36 x i8]* @genera_cadena.charset2, i64 0, i64 %21
br label %23
23: ; preds = %15, %19
%24 = phi i8* [ %18, %15 ], [ %22, %19 ]
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %25, i8* %26
%27 = add nuw nsw i64 %13, 1
%28 = icmp eq i64 %27, %11
br i1 %28, label %29, label %12
29: ; preds = %23, %3
%30 = phi i64 [ 0, %3 ], [ %11, %23 ]
%31 = getelementptr inbounds i8, i8* %0, i64 %30
store i8 0, i8* %31
ret i8* %0
}