#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 */
typedef int /*<<< orphan*/ time_t;

/* Variables and functions */
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
const char *random_string(int length, char signs[], int signsSize) {
  time_t now = time(0);
  time(&now);
  srand(now);
  char password[length];
  for (int i = 0; i < length; ++i) {
    password[i] = signs[rand() % (signsSize - 1)];
  }
  password[length] = 0;
  return password;
}


x86 assembly (clang, -O0):
<random_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <time@plt>
mov    -0x18(%rbp),%edi
call   1030 <srand@plt>
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d3 <random_string+0xa3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    -0x40(%rbp),%rcx
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
cltd
idiv   %esi
mov    -0x38(%rbp),%rax
movslq %edx,%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118c <random_string+0x5c>
mov    -0x38(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_string>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %edi,%ebx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x2c(%rbp),%rdi
call   1040 <time@plt>
mov    -0x2c(%rbp),%edi
call   1030 <srand@plt>
mov    %rsp,-0x38(%rbp)
mov    %ebx,%r13d
mov    %rsp,%r12
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %ebx,%ebx
jle    11b0 <random_string+0x80>
add    $0xffffffff,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %r15d
movslq %edx,%rax
movzbl (%r14,%rax,1),%eax
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1190 <random_string+0x60>
mov    -0x38(%rbp),%rsp
mov    %r12,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @random_string(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = call i32 @time(i32* null)
store i32 %11, i32* %7
%12 = call i32 @time(i32* %7)
%13 = load i32, i32* %7
%14 = call i32 @srand(i32 %13)
%15 = load i32, i32* %4
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
store i32 0, i32* %10
br label %19
19: ; preds = %35, %3
%20 = load i32, i32* %10
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = call i32 (...) @rand()
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 1
%28 = srem i32 %25, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %24, i64 %29
%31 = load i8, i8* %30
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %18, i64 %33
store i8 %31, i8* %34
br label %35
35: ; preds = %23
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %19
38: ; preds = %19
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %18, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %8
ret i8* %18
}

LLVM IR (-O2):
define noalias i8* @random_string(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %4
%7 = call i32 @time(i32* %4)
%8 = load i32, i32* %4
%9 = call i32 @srand(i32 %8)
%10 = zext i32 %0 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = icmp sgt i32 %0, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = add nsw i32 %2, -1
br label %17
16: ; preds = %17, %3
ret i8* %12
17: ; preds = %14, %17
%18 = phi i64 [ 0, %14 ], [ %25, %17 ]
%19 = call i32 (...) @rand()
%20 = srem i32 %19, %15
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %12, i64 %18
store i8 %23, i8* %24
%25 = add nuw nsw i64 %18, 1
%26 = icmp eq i64 %25, %10
br i1 %26, label %16, label %17
}