#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 */
struct timeval {
  int /*<<< orphan*/ tv_sec;
  int /*<<< orphan*/ tv_usec;
};

/* Variables and functions */
int getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ random();
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int time(int /*<<< orphan*/);
int /*<<< orphan*/ to64(char *, int /*<<< orphan*/, int);
char *ytht_crypt_crypt1(char *, char *);
char *ytht_crypt_genpasswd(char *pw) {
  char salt[10];
  static char pwbuf[68];
  struct timeval tv;
  if (strlen(pw) == 0)
    return "";
  srand(time(0) % getpid());
  gettimeofday(&tv, 0);
  to64(&salt[0], random(), 3);
  to64(&salt[3], tv.tv_usec, 3);
  to64(&salt[6], tv.tv_sec, 2);
  salt[8] = '\0';
  strcpy(pwbuf, pw);
  return ytht_crypt_crypt1(pwbuf, salt);
}


x86 assembly (clang, -O0):
<ytht_crypt_genpasswd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
jne    11bf <ytht_crypt_genpasswd+0x2f>
lea    0xe4a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    125b <ytht_crypt_genpasswd+0xcb>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,%edi
call   1080 <srand@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
lea    -0x1a(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   10b0 <random@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    $0x3,%edx
call   1050 <to64@plt>
lea    -0x1a(%rbp),%rdi
add    $0x3,%rdi
mov    -0x24(%rbp),%esi
mov    $0x3,%edx
call   1050 <to64@plt>
lea    -0x1a(%rbp),%rdi
add    $0x6,%rdi
mov    -0x28(%rbp),%esi
mov    $0x2,%edx
call   1050 <to64@plt>
movb   $0x0,-0x12(%rbp)
mov    -0x10(%rbp),%rsi
lea    0x2e3e(%rip),%rdi
call   1030 <strcpy@plt>
lea    -0x1a(%rbp),%rsi
lea    0x2e2e(%rip),%rdi
call   10a0 <ytht_crypt_crypt1@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ytht_crypt_genpasswd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
cmpb   $0x0,(%rdi)
je     1223 <ytht_crypt_genpasswd+0xa3>
mov    %rdi,%rbx
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %edx,%edi
call   1070 <srand@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
xor    %eax,%eax
call   10a0 <random@plt>
lea    0xe(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x3,%edx
call   1050 <to64@plt>
lea    0x11(%rsp),%rdi
mov    0x1c(%rsp),%esi
mov    $0x3,%edx
call   1050 <to64@plt>
lea    0x14(%rsp),%rdi
mov    0x18(%rsp),%esi
mov    $0x2,%edx
call   1050 <to64@plt>
movb   $0x0,0x16(%rsp)
lea    0x2e65(%rip),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1090 <ytht_crypt_crypt1@plt>
jmp    122a <ytht_crypt_genpasswd+0xaa>
lea    0xdd6(%rip),%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@ytht_crypt_genpasswd.pwbuf = internal global [68 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
define i8* @ytht_crypt_genpasswd(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [10 x i8]
%5 = alloca %struct.timeval
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %32
10: ; preds = %1
%11 = call i32 @time(i32 0)
%12 = call i32 (...) @getpid()
%13 = srem i32 %11, %12
%14 = call i32 @srand(i32 %13)
%15 = call i32 @gettimeofday(%struct.timeval* %5, i32 0)
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%17 = call i32 (...) @random()
%18 = call i32 @to64(i8* %16, i32 %17, i32 3)
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 3
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i32 @to64(i8* %19, i32 %21, i32 3)
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 6
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @to64(i8* %23, i32 %25, i32 2)
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 8
store i8 0, i8* %27
%28 = load i8*, i8** %3
%29 = call i32 @strcpy(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @ytht_crypt_genpasswd.pwbuf, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%31 = call i8* @ytht_crypt_crypt1(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @ytht_crypt_genpasswd.pwbuf, i64 0, i64 0), i8* %30)
store i8* %31, i8** %2
br label %32
32: ; preds = %10, %9
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@ytht_crypt_genpasswd.pwbuf = internal global [68 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
define i8* @ytht_crypt_genpasswd(i8* %0) {
%2 = alloca [10 x i8]
%3 = alloca %struct.timeval
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.timeval* %3 to i8*
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %27, label %8
8: ; preds = %1
%9 = tail call i32 @time(i32 0)
%10 = tail call i32 (...) @getpid()
%11 = srem i32 %9, %10
%12 = tail call i32 @srand(i32 %11)
%13 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%14 = call i32 (...) @random()
%15 = call i32 @to64(i8* %4, i32 %14, i32 3)
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 3
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 @to64(i8* %16, i32 %18, i32 3)
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 6
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @to64(i8* %20, i32 %22, i32 2)
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 8
store i8 0, i8* %24
%25 = call i32 @strcpy(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @ytht_crypt_genpasswd.pwbuf, i64 0, i64 0), i8* %0)
%26 = call i8* @ytht_crypt_crypt1(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @ytht_crypt_genpasswd.pwbuf, i64 0, i64 0), i8* %4)
br label %27
27: ; preds = %1, %8
%28 = phi i8* [ %26, %8 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %28
}