#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 unsigned int time_t;
typedef unsigned int pid_t;

/* Variables and functions */
int abs(unsigned int);
unsigned int getpid();
int rand();
int /*<<< orphan*/ srand(unsigned int);
unsigned int time(int /*<<< orphan*/ *);
void generate_passwd(char password[], int length) {
  pid_t pid = getpid();
  time_t current_time = time(NULL);
  unsigned int seed = current_time / pid;
  srand(seed);
  for (int i = 0; i < abs(pid); i++)
    rand();
  for (int i = 0; i < length; i++)
    password[i] = 'A' + (rand() % 26);
}


x86 assembly (clang, -O0):
<generate_passwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <srand@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11bf <generate_passwd+0x6f>
mov    $0x0,%al
call   1070 <rand@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <generate_passwd+0x3f>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fd <generate_passwd+0xad>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c6 <generate_passwd+0x76>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_passwd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1050 <time@plt>
xor    %edx,%edx
div    %ebp
mov    %eax,%edi
call   1040 <srand@plt>
test   %ebp,%ebp
je     118c <generate_passwd+0x4c>
mov    %ebp,%ebx
neg    %ebx
cmovs  %ebp,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <rand@plt>
add    $0xffffffff,%ebx
jne    1180 <generate_passwd+0x40>
test   %r14d,%r14d
jle    11d6 <generate_passwd+0x96>
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <generate_passwd+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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