#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 *, char *);
unsigned long getpid();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
unsigned long time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  unsigned long seed[2];
  const char *const seedchars = "./0123456789ABCDEFGHIJKLMNOPQRST"
                                "UVWXYZabcdefghijklmnopqrstuvwxyz";
  char *password;
  int i;
  if (argc == 2) {
    char salt[] = "$1$........";
    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(argv[1], salt);
  } else if (argc == 3) {
    password = crypt(argv[1], argv[2]);
  } else {
    printf("Usage: %s password [salt]\n", argv[0]);
    return (1);
  }
  puts(password);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    123c <main+0xec>
mov    0xebf(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xebd(%rip),%eax
mov    %eax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x20(%rbp),%rcx
shr    $0xe,%rcx
and    $0x30000,%rcx
xor    %rcx,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jge    1222 <main+0xd2>
mov    -0x34(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cltq
mov    -0x20(%rbp,%rax,8),%rax
mov    %rax,-0x48(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    -0x48(%rbp),%rax
imul   $0x6,%edx,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
mov    %rax,%rcx
and    $0x3f,%rcx
lea    0xdfb(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x34(%rbp),%eax
add    $0x3,%eax
cltq
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c0 <main+0x70>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <crypt@plt>
mov    %rax,-0x30(%rbp)
jmp    1288 <main+0x138>
cmpl   $0x3,-0x8(%rbp)
jne    1264 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <crypt@plt>
mov    %rax,-0x30(%rbp)
jmp    1283 <main+0x133>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xddb(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1298 <main+0x148>
jmp    1288 <main+0x138>
mov    -0x30(%rbp),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
je     121f <main+0xcf>
cmp    $0x2,%edi
jne    1238 <main+0xe8>
movabs $0x2e2e2e2e2e243124,%rax
2e 2e 2e
mov    %rax,0x8(%rsp)
movl   $0x2e2e2e,0x10(%rsp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %ebx,%ecx
shr    $0xe,%ecx
and    $0x30000,%ecx
xor    %eax,%ecx
mov    %ebx,%esi
and    $0x3f,%esi
lea    0xe53(%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)
mov    0x8(%r14),%rdi
lea    0x8(%rsp),%rsi
jmp    1227 <main+0xd7>
mov    0x8(%r14),%rdi
mov    0x10(%r14),%rsi
call   1050 <crypt@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    124c <main+0xfc>
mov    (%r14),%rsi
lea    0xe0b(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [65 x i8] c"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
@__const.main.salt = [12 x i8] c"$1$........\00"
@.str.1 = [27 x i8] c"Usage: %s password [salt]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i64]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [12 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8** %7
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %54
13: ; preds = %2
%14 = bitcast [12 x i8]* %10 to i8*
%15 = call i64 @time(i32* null)
%16 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
store i64 %15, i64* %16
%17 = call i64 (...) @getpid()
%18 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
%19 = load i64, i64* %18
%20 = lshr i64 %19, 14
%21 = and i64 %20, 196608
%22 = xor i64 %17, %21
%23 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 1
store i64 %22, i64* %23
store i32 0, i32* %9
br label %24
24: ; preds = %45, %13
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 8
br i1 %26, label %27, label %48
27: ; preds = %24
%28 = load i32, i32* %9
%29 = sdiv i32 %28, 5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 %30
%32 = load i64, i64* %31
%33 = load i32, i32* %9
%34 = srem i32 %33, 5
%35 = mul nsw i32 %34, 6
%36 = zext i32 %35 to i64
%37 = lshr i64 %32, %36
%38 = and i64 %37, 63
%39 = getelementptr inbounds i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 0), i64 %38
%40 = load i8, i8* %39
%41 = load i32, i32* %9
%42 = add nsw i32 3, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 %43
store i8 %40, i8* %44
br label %45
45: ; preds = %27
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %24
48: ; preds = %24
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%53 = call i8* @crypt(i8* %51, i8* %52)
store i8* %53, i8** %8
br label %71
54: ; preds = %2
%55 = load i32, i32* %4
%56 = icmp eq i32 %55, 3
br i1 %56, label %57, label %65
57: ; preds = %54
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 2
%63 = load i8*, i8** %62
%64 = call i8* @crypt(i8* %60, i8* %63)
store i8* %64, i8** %8
br label %70
65: ; preds = %54
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 0
%68 = load i8*, i8** %67
%69 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %68)
store i32 1, i32* %3
br label %74
70: ; preds = %57
br label %71
71: ; preds = %70, %48
%72 = load i8*, i8** %8
%73 = call i32 @puts(i8* %72)
store i32 0, i32* %3
br label %74
74: ; preds = %71, %65
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@.str = [65 x i8] c"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
@__const.main.salt = [12 x i8] c"$1$........\00"
@.str.1 = [27 x i8] c"Usage: %s password [salt]\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [12 x i8]
switch i32 %0, label %58 [
i32 2, label %4
i32 3, label %52
]
4: ; preds = %2
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @time(i32* null)
%7 = tail call i64 (...) @getpid()
%8 = lshr i64 %6, 14
%9 = and i64 %8, 196608
%10 = xor i64 %7, %9
%11 = and i64 %6, 63
%12 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 3
store i8 %13, i8* %14
%15 = lshr i64 %6, 6
%16 = and i64 %15, 63
%17 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 4
store i8 %18, i8* %19
%20 = lshr i64 %6, 12
%21 = and i64 %20, 63
%22 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 5
store i8 %23, i8* %24
%25 = lshr i64 %6, 18
%26 = and i64 %25, 63
%27 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 6
store i8 %28, i8* %29
%30 = lshr i64 %6, 24
%31 = and i64 %30, 63
%32 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 7
store i8 %33, i8* %34
%35 = and i64 %7, 63
%36 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 8
store i8 %37, i8* %38
%39 = lshr i64 %7, 6
%40 = and i64 %39, 63
%41 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 9
store i8 %42, i8* %43
%44 = lshr i64 %10, 12
%45 = and i64 %44, 63
%46 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 10
store i8 %47, i8* %48
%49 = getelementptr inbounds i8*, i8** %1, i64 1
%50 = load i8*, i8** %49
%51 = call i8* @crypt(i8* %50, i8* %5)
br label %61
52: ; preds = %2
%53 = getelementptr inbounds i8*, i8** %1, i64 1
%54 = load i8*, i8** %53
%55 = getelementptr inbounds i8*, i8** %1, i64 2
%56 = load i8*, i8** %55
%57 = tail call i8* @crypt(i8* %54, i8* %56)
br label %61
58: ; preds = %2
%59 = load i8*, i8** %1
%60 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %59)
br label %64
61: ; preds = %52, %4
%62 = phi i8* [ %51, %4 ], [ %57, %52 ]
%63 = call i32 @puts(i8* dereferenceable(1) %62)
br label %64
64: ; preds = %61, %58
%65 = phi i32 [ 0, %61 ], [ 1, %58 ]
ret i32 %65
}