#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 timespec {
  int tv_sec;
  int tv_nsec;
};
typedef int /*<<< orphan*/ salt;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
char *crypt(char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int random();
int /*<<< orphan*/ srandom(int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  static const char salt_chars[64] =
      "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  char salt[21];
  int i;
  if (argc < 4) {
    printf("Usage: passcrypt -l <256/512/md5> <password>\n");
    exit(EXIT_FAILURE);
  }
  memset(salt, 0, sizeof(salt));
  if (strcmp(argv[2], "256") == 0) {
    strcpy(salt, "$5$");
  } else if (strcmp(argv[2], "512") == 0) {
    strcpy(salt, "$6$");
  } else if (strcmp(argv[2], "md5") == 0) {
    strcpy(salt, "$1$");
  } else {
    printf("Unknown hash type.\n");
    exit(EXIT_FAILURE);
  }
  for (i = 3; i < 19; i++) {
    long r;
    struct timespec tp;
    clock_gettime(CLOCK_REALTIME, &tp);
    srandom(tp.tv_sec * tp.tv_nsec);
    r = random() % 64;
    salt[i] = salt_chars[r];
  }
  strcat(salt, "$");
  printf("%s\n", crypt(argv[3], salt));
  exit(EXIT_SUCCESS);
}


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)
cmpl   $0x4,-0x8(%rbp)
jge    11dc <main+0x3c>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe73(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <main+0x7f>
lea    -0x30(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <strcpy@plt>
jmp    12ab <main+0x10b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe48(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1252 <main+0xb2>
lea    -0x30(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1040 <strcpy@plt>
jmp    12a6 <main+0x106>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1285 <main+0xe5>
lea    -0x30(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1040 <strcpy@plt>
jmp    12a1 <main+0x101>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    12a6 <main+0x106>
jmp    12ab <main+0x10b>
movl   $0x3,-0x34(%rbp)
cmpl   $0x13,-0x34(%rbp)
jge    1314 <main+0x174>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x48(%rbp),%edi
imul   -0x44(%rbp),%edi
call   1030 <srandom@plt>
mov    $0x0,%al
call   10a0 <random@plt>
mov    $0x40,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
lea    0xd05(%rip),%rax
mov    (%rax,%rcx,1),%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12b2 <main+0x112>
lea    -0x30(%rbp),%rdi
lea    0xd65(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <crypt@plt>
mov    %rax,%rsi
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
cmp    $0x3,%edi
jg     11cc <main+0x2c>
lea    0xeb2(%rip),%rdi
call   1050 <puts@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    %rsi,%r14
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1080 <memset@plt>
mov    0x10(%r14),%rdi
lea    0xe55(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    11fe <main+0x5e>
lea    0xe48(%rip),%rsi
jmp    123c <main+0x9c>
mov    0x10(%r14),%rdi
lea    0xe3f(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    121c <main+0x7c>
lea    0xe32(%rip),%rsi
jmp    123c <main+0x9c>
mov    0x10(%r14),%rdi
lea    0xe29(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    12d8 <main+0x138>
lea    0xe18(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x2d8b(%rip),%r15
lea    0x8(%rsp),%r12
lea    0xda7(%rip),%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %r12,%rsi
call   1060 <clock_gettime@plt>
mov    0xc(%rsp),%edi
imul   0x8(%rsp),%edi
call   1030 <srandom@plt>
xor    %eax,%eax
call   10a0 <random@plt>
lea    0x3f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffc0,%ecx
sub    %ecx,%eax
cltq
movzbl (%rax,%r13,1),%eax
mov    %al,0x13(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x10,%rbx
jne    1260 <main+0xc0>
lea    0xdad(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    0x18(%r14),%rdi
mov    %rbx,%rsi
call   1070 <crypt@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xd79(%rip),%rdi
jmp    11b9 <main+0x19>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@main.salt_chars = internal constant [64 x i8] c"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
@.str = [46 x i8] c"Usage: passcrypt -l <256/512/md5> <password>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"256\00"
@.str.2 = [4 x i8] c"$5$\00"
@.str.3 = [4 x i8] c"512\00"
@.str.4 = [4 x i8] c"$6$\00"
@.str.5 = [4 x i8] c"md5\00"
@.str.6 = [4 x i8] c"$1$\00"
@.str.7 = [20 x i8] c"Unknown hash type.\0A\00"
@CLOCK_REALTIME = global i32 0
@.str.8 = [2 x i8] c"$\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [21 x i8]
%7 = alloca i32
%8 = alloca i64
%9 = alloca %struct.timespec
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 21)
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %51
27: ; preds = %16
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %50
36: ; preds = %27
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %49
45: ; preds = %36
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42
br label %50
50: ; preds = %49, %33
br label %51
51: ; preds = %50, %24
store i32 3, i32* %7
br label %52
52: ; preds = %73, %51
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 19
br i1 %54, label %55, label %76
55: ; preds = %52
%56 = load i32, i32* @CLOCK_REALTIME
%57 = call i32 @clock_gettime(i32 %56, %struct.timespec* %9)
%58 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 1
%61 = load i32, i32* %60
%62 = mul nsw i32 %59, %61
%63 = call i32 @srandom(i32 %62)
%64 = call i32 (...) @random()
%65 = srem i32 %64, 64
%66 = sext i32 %65 to i64
store i64 %66, i64* %8
%67 = load i64, i64* %8
%68 = getelementptr inbounds [64 x i8], [64 x i8]* @main.salt_chars, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = load i32, i32* %7
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 %71
store i8 %69, i8* %72
br label %73
73: ; preds = %55
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %52
76: ; preds = %52
%77 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%78 = call i32 @strcat(i8* %77, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 3
%81 = load i8*, i8** %80
%82 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%83 = call i8* @crypt(i8* %81, i8* %82)
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %83)
%85 = load i32, i32* @EXIT_SUCCESS
%86 = call i32 @exit(i32 %85)
unreachable
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@main.salt_chars = internal unnamed_addr constant [64 x i8] c"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"256\00"
@.str.2 = [4 x i8] c"$5$\00"
@.str.3 = [4 x i8] c"512\00"
@.str.4 = [4 x i8] c"$6$\00"
@.str.5 = [4 x i8] c"md5\00"
@.str.6 = [4 x i8] c"$1$\00"
@CLOCK_REALTIME = global i32 0
@.str.8 = [2 x i8] c"$\00"
@EXIT_SUCCESS = global i32 0
@str = [19 x i8] c"Unknown hash type.\00"
@str.10 = [45 x i8] c"Usage: passcrypt -l <256/512/md5> <password>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [21 x i8]
%4 = alloca %struct.timespec
%5 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 4
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.10, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = call i32 @memset(i8* %5, i32 0, i32 21)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %11
%18 = load i8*, i8** %13
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %17
%22 = load i8*, i8** %13
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %21, %17, %11
%30 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %11 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %17 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), %21 ]
%31 = call i32 @strcpy(i8* %5, i8* %30)
%32 = bitcast %struct.timespec* %4 to i8*
%33 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
br label %35
35: ; preds = %29, %35
%36 = phi i64 [ 3, %29 ], [ %49, %35 ]
%37 = load i32, i32* @CLOCK_REALTIME
%38 = call i32 @clock_gettime(i32 %37, %struct.timespec* %4)
%39 = load i32, i32* %33
%40 = load i32, i32* %34
%41 = mul nsw i32 %40, %39
%42 = call i32 @srandom(i32 %41)
%43 = call i32 (...) @random()
%44 = srem i32 %43, 64
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [64 x i8], [64 x i8]* @main.salt_chars, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 %36
store i8 %47, i8* %48
%49 = add nuw nsw i64 %36, 1
%50 = icmp eq i64 %49, 19
br i1 %50, label %51, label %35
51: ; preds = %35
%52 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%53 = getelementptr inbounds i8*, i8** %1, i64 3
%54 = load i8*, i8** %53
%55 = call i8* @crypt(i8* %54, i8* %5)
%56 = call i32 @puts(i8* dereferenceable(1) %55)
%57 = load i32, i32* @EXIT_SUCCESS
%58 = call i32 @exit(i32 %57)
unreachable
}