#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 */
double RAND_MAX;
scalar_t__ rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void gensalt(char *dest, size_t length) {
  srand(time(NULL));
  char charset[] = "0123456789"
                   "abcdefghijklmnopqrstuvwxyz"
                   "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                   ":;?@[\\]^_`{|}$#!~%&*()=+-<>,./";
  while (length-- > 0) {
    size_t index = (double)rand() / RAND_MAX * (sizeof charset - 1);
    *dest++ = charset[index];
  }
  *dest = '\0';
}


x86 assembly (clang, -O0):
<gensalt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
lea    -0x70(%rbp),%rdi
lea    0xea2(%rip),%rsi
mov    $0x5d,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
jbe    1200 <gensalt+0xc0>
xor    %eax,%eax
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e44(%rip),%rax
movsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe4c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xe39(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1178 <gensalt+0x38>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gensalt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %rbx,%rbx
je     11b2 <gensalt+0x82>
mov    0x2e90(%rip),%r15
lea    0xeb1(%rip),%r12
nop
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
mulsd  0xe84(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
subsd  0xe7c(%rip),%xmm0
sar    $0x3f,%rcx
cvttsd2si %xmm0,%rdx
and    %rcx,%rdx
or     %rax,%rdx
lea    0x1(%r14),%rax
movzbl (%rdx,%r12,1),%ecx
mov    %cl,(%r14)
mov    %rax,%r14
add    $0xffffffffffffffff,%rbx
jne    1160 <gensalt+0x30>
jmp    11b5 <gensalt+0x85>
mov    %r14,%rax
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.gensalt.charset = [93 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;?@[\\]^_`{|}$#!~%&*()=+-<>,./\00"
@RAND_MAX = global double 0.000000e+00
define void @gensalt(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [93 x i8]
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
%9 = bitcast [93 x i8]* %5 to i8*
br label %10
10: ; preds = %14, %2
%11 = load i64, i64* %4
%12 = add i64 %11, -1
store i64 %12, i64* %4
%13 = icmp ugt i64 %11, 0
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = call i64 (...) @rand()
%16 = sitofp i64 %15 to double
%17 = load double, double* @RAND_MAX
%18 = fdiv double %16, %17
%19 = fmul double %18, 9.200000e+01
%20 = fptoui double %19 to i64
store i64 %20, i64* %6
%21 = load i64, i64* %6
%22 = getelementptr inbounds [93 x i8], [93 x i8]* %5, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
store i8 %23, i8* %24
br label %10
26: ; preds = %10
%27 = load i8*, i8** %3
store i8 0, i8* %27
ret void
}

LLVM IR (-O2):
@__const.gensalt.charset = [93 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;?@[\\]^_`{|}$#!~%&*()=+-<>,./\00"
@RAND_MAX = global double 0.000000e+00
define void @gensalt(i8* nocapture writeonly %0, i64 %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = icmp eq i64 %1, 0
br i1 %5, label %20, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %18, %6 ], [ %0, %2 ]
%8 = phi i64 [ %9, %6 ], [ %1, %2 ]
%9 = add i64 %8, -1
%10 = tail call i64 (...) @rand()
%11 = sitofp i64 %10 to double
%12 = load double, double* @RAND_MAX
%13 = fdiv double %11, %12
%14 = fmul double %13, 9.200000e+01
%15 = fptoui double %14 to i64
%16 = getelementptr inbounds [93 x i8], [93 x i8]* @__const.gensalt.charset, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %17, i8* %7
%19 = icmp eq i64 %9, 0
br i1 %19, label %20, label %6
20: ; preds = %6, %2
%21 = phi i8* [ %0, %2 ], [ %18, %6 ]
store i8 0, i8* %21
ret void
}