#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 */
unsigned long rand_r(unsigned int *);
unsigned int time(int /*<<< orphan*/ *);
void genSalt(unsigned char *salt, unsigned int saltlen, const char *maps,
             unsigned long lMaps) {
  unsigned int seed = 0;
  unsigned long n = 0;
  seed = time(NULL);
  for (n = 0; n < saltlen; n++)
    salt[n] = maps[rand_r(&seed) % lMaps];
}


x86 assembly (clang, -O0):
<genSalt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%ecx
cmp    %rcx,%rax
jae    11a6 <genSalt+0x86>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x24(%rbp),%rdi
call   1030 <rand_r@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax,%rdx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    115a <genSalt+0x3a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genSalt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%r15
xor    %ebp,%ebp
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
test   %r12d,%r12d
je     1191 <genSalt+0x71>
mov    %r12d,%r13d
lea    0x4(%rsp),%r12
jmp    1177 <genSalt+0x57>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edx,%edx
div    %rbx
movzbl (%r14,%rdx,1),%eax
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r13
je     1191 <genSalt+0x71>
mov    %r12,%rdi
call   1030 <rand_r@plt>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
jne    1160 <genSalt+0x40>
xor    %edx,%edx
div    %ebx
jmp    1165 <genSalt+0x45>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @genSalt(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i32 0, i32* %9
store i64 0, i64* %10
%11 = call i32 @time(i32* null)
store i32 %11, i32* %9
store i64 0, i64* %10
br label %12
12: ; preds = %27, %4
%13 = load i64, i64* %10
%14 = load i32, i32* %6
%15 = zext i32 %14 to i64
%16 = icmp ult i64 %13, %15
br i1 %16, label %17, label %30
17: ; preds = %12
%18 = load i8*, i8** %7
%19 = call i64 @rand_r(i32* %9)
%20 = load i64, i64* %8
%21 = urem i64 %19, %20
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %5
%25 = load i64, i64* %10
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 %23, i8* %26
br label %27
27: ; preds = %17
%28 = load i64, i64* %10
%29 = add i64 %28, 1
store i64 %29, i64* %10
br label %12
30: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @genSalt(i8* nocapture writeonly %0, i32 %1, i8* nocapture %2, i64 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32 @time(i32* null)
store i32 %7, i32* %5
%8 = zext i32 %1 to i64
%9 = icmp eq i32 %1, 0
br i1 %9, label %19, label %10
10: ; preds = %4, %10
%11 = phi i64 [ %17, %10 ], [ 0, %4 ]
%12 = call i64 @rand_r(i32* %5)
%13 = urem i64 %12, %3
%14 = getelementptr inbounds i8, i8* %2, i64 %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 %15, i8* %16
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %8
br i1 %18, label %19, label %10
19: ; preds = %10, %4
ret void
}