#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 */
char *crypt(char const *, char *);
unsigned long getpid();
unsigned long time(int /*<<< orphan*/ *);
char *mkpasswd(const char *words) {
  unsigned long seed[2];
  char salt[] = "$6$........";
  const char *const seedchars = "./0123456789ABCDEFGHIJKLMNOPQRST"
                                "UVWXYZabcdefghijklmnopqrstuvwxyz";
  char *password;
  int i;
  seed[0] = time(NULL);
  seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);
  for (i = 0; i < 8; i++) {
    salt[3 + i] = seedchars[(seed[i / 5] >> (i % 5) * 6) & 0x3f];
  }
  password = crypt(words, salt);
  return password;
}


x86 assembly (clang, -O0):
<mkpasswd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xebd(%rip),%rax
mov    %rax,-0x2c(%rbp)
mov    0xebb(%rip),%eax
mov    %eax,-0x24(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%rcx
shr    $0xe,%rcx
and    $0x30000,%rcx
xor    %rcx,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x8,-0x44(%rbp)
jge    11ee <mkpasswd+0xbe>
mov    -0x44(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cltq
mov    -0x20(%rbp,%rax,8),%rax
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    -0x50(%rbp),%rax
imul   $0x6,%edx,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
mov    %rax,%rcx
and    $0x3f,%rcx
lea    0xe3b(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x44(%rbp),%eax
add    $0x3,%eax
cltq
mov    %cl,-0x2c(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    118c <mkpasswd+0x5c>
mov    -0x8(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <crypt@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkpasswd>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movabs $0x2e2e2e2e2e243624,%rax
2e 2e 2e
mov    %rax,0x8(%rsp)
movl   $0x2e2e2e,0x10(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %ebx,%ecx
shr    $0xe,%ecx
and    $0x30000,%ecx
xor    %eax,%ecx
mov    %ebx,%esi
and    $0x3f,%esi
lea    0xe91(%rip),%rdi
mov    (%rsi,%rdi,1),%dl
mov    %dl,0xb(%rsp)
mov    %ebx,%edx
shr    $0x6,%edx
and    $0x3f,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0xc(%rsp)
mov    %ebx,%edx
shr    $0xc,%edx
and    $0x3f,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0xd(%rsp)
mov    %ebx,%edx
shr    $0x12,%edx
and    $0x3f,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0xe(%rsp)
shr    $0x18,%ebx
and    $0x3f,%ebx
mov    (%rbx,%rdi,1),%dl
mov    %dl,0xf(%rsp)
mov    %eax,%edx
and    $0x3f,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0x10(%rsp)
shr    $0x6,%eax
and    $0x3f,%eax
mov    (%rax,%rdi,1),%al
mov    %al,0x11(%rsp)
shr    $0xc,%ecx
and    $0x3f,%ecx
mov    (%rcx,%rdi,1),%al
mov    %al,0x12(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <crypt@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.mkpasswd.salt = [12 x i8] c"$6$........\00"
@.str = [65 x i8] c"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
define i8* @mkpasswd(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i64]
%4 = alloca [12 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
%8 = bitcast [12 x i8]* %4 to i8*
store i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8** %5
%9 = call i64 @time(i32* null)
%10 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
store i64 %9, i64* %10
%11 = call i64 (...) @getpid()
%12 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
%13 = load i64, i64* %12
%14 = lshr i64 %13, 14
%15 = and i64 %14, 196608
%16 = xor i64 %11, %15
%17 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
store i64 %16, i64* %17
store i32 0, i32* %7
br label %18
18: ; preds = %39, %1
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %42
21: ; preds = %18
%22 = load i32, i32* %7
%23 = sdiv i32 %22, 5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 %24
%26 = load i64, i64* %25
%27 = load i32, i32* %7
%28 = srem i32 %27, 5
%29 = mul nsw i32 %28, 6
%30 = zext i32 %29 to i64
%31 = lshr i64 %26, %30
%32 = and i64 %31, 63
%33 = getelementptr inbounds i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 0), i64 %32
%34 = load i8, i8* %33
%35 = load i32, i32* %7
%36 = add nsw i32 3, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 %37
store i8 %34, i8* %38
br label %39
39: ; preds = %21
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %18
42: ; preds = %18
%43 = load i8*, i8** %2
%44 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%45 = call i8* @crypt(i8* %43, i8* %44)
store i8* %45, i8** %6
%46 = load i8*, i8** %6
ret i8* %46
}

LLVM IR (-O2):
@__const.mkpasswd.salt = [12 x i8] c"$6$........\00"
@.str = [65 x i8] c"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
define i8* @mkpasswd(i8* %0) {
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @time(i32* null)
%5 = tail call i64 (...) @getpid()
%6 = lshr i64 %4, 14
%7 = and i64 %6, 196608
%8 = xor i64 %5, %7
%9 = and i64 %4, 63
%10 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 3
store i8 %11, i8* %12
%13 = lshr i64 %4, 6
%14 = and i64 %13, 63
%15 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 4
store i8 %16, i8* %17
%18 = lshr i64 %4, 12
%19 = and i64 %18, 63
%20 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 5
store i8 %21, i8* %22
%23 = lshr i64 %4, 18
%24 = and i64 %23, 63
%25 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 6
store i8 %26, i8* %27
%28 = lshr i64 %4, 24
%29 = and i64 %28, 63
%30 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 7
store i8 %31, i8* %32
%33 = and i64 %5, 63
%34 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 8
store i8 %35, i8* %36
%37 = lshr i64 %5, 6
%38 = and i64 %37, 63
%39 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 9
store i8 %40, i8* %41
%42 = lshr i64 %8, 12
%43 = and i64 %42, 63
%44 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 10
store i8 %45, i8* %46
%47 = call i8* @crypt(i8* %0, i8* %3)
ret i8* %47
}