#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 int /*<<< orphan*/ seed;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *crypt(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned long long *, int, int, int /*<<< orphan*/ *);
char *getpass(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned long long);
int main(void) {
  char *pass;
  do {
    pass = getpass("Give me a password: ");
  } while (pass == NULL);
  unsigned long long seed;
  FILE *f;
  f = fopen("/dev/random", "r");
  fread(&seed, sizeof(seed), 1, f);
  fclose(f);
  char *sseed = malloc(1024 * sizeof(char));
  sprintf(sseed, "$2b$%llu", seed);
  char *enc = crypt(pass, sseed);
  printf("\n%s\n", enc);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
call   1080 <getpass@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118f <main+0xf>
lea    0xe64(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe25(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <crypt@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe0d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe75(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1080 <getpass@plt>
test   %rax,%rax
je     1190 <main+0x10>
mov    %rax,%rbx
lea    0xe6e(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    (%rsp),%rdx
lea    0xe38(%rip),%rsi
mov    %rax,%rdi
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <crypt@plt>
lea    0xe27(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Give me a password: \00"
@.str.1 = [12 x i8] c"/dev/random\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"$2b$%llu\00"
@.str.4 = [5 x i8] c"\0A%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
br label %7
7: ; preds = %9, %0
%8 = call i8* @getpass(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %2
br label %9
9: ; preds = %7
%10 = load i8*, i8** %2
%11 = icmp eq i8* %10, null
br i1 %11, label %7, label %12
12: ; preds = %9
%13 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = call i32 @fread(i64* %3, i32 8, i32 1, i32* %14)
%16 = load i32*, i32** %4
%17 = call i32 @fclose(i32* %16)
%18 = call i8* @malloc(i32 1024)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = load i64, i64* %3
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %20)
%22 = load i8*, i8** %2
%23 = load i8*, i8** %5
%24 = call i8* @crypt(i8* %22, i8* %23)
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [21 x i8] c"Give me a password: \00"
@.str.1 = [12 x i8] c"/dev/random\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"$2b$%llu\00"
@.str.4 = [5 x i8] c"\0A%s\0A\00"
define i32 @main() {
%1 = alloca i64
br label %2
2: ; preds = %2, %0
%3 = tail call i8* @getpass(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %2, label %5
5: ; preds = %2
%6 = bitcast i64* %1 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @fread(i64* %1, i32 8, i32 1, i32* %7)
%9 = tail call i32 @fclose(i32* %7)
%10 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%11 = load i64, i64* %1
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %11)
%13 = tail call i8* @crypt(i8* %3, i8* %10)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %13)
ret i32 0
}