#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*/ ssize_t;
typedef int /*<<< orphan*/ key;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, unsigned long long *, int);
int time(int /*<<< orphan*/ *);
unsigned long long random_key() {
  unsigned long long key = time(NULL) * 0xc6a4a7935bd1e995ULL;
  int fd = open("/dev/urandom", O_RDONLY);
  if (fd >= 0) {
    ssize_t r = read(fd, &key, sizeof(key));
    (void)r;
    close(fd);
  }
  return key;
}


x86 assembly (clang, -O0):
<random_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
cltq
movabs $0xc6a4a7935bd1e995,%rcx
a7 a4 c6
imul   %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11a3 <random_key+0x63>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_key>:
push   %rbp
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <time@plt>
cltq
movabs $0xc6a4a7935bd1e995,%rbx
a7 a4 c6
imul   %rax,%rbx
mov    %rbx,(%rsp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1193 <random_key+0x53>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    (%rsp),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i64 @random_key() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @time(i32* null)
%5 = sext i32 %4 to i64
%6 = mul i64 %5, -4132994306676758123
store i64 %6, i64* %1
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 @read(i32 %12, i64* %1, i32 8)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = load i32, i32* %2
%16 = call i32 @close(i32 %15)
br label %17
17: ; preds = %11, %0
%18 = load i64, i64* %1
ret i64 %18
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i64 @random_key() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = sext i32 %3 to i64
%5 = mul i64 %4, -4132994306676758123
store i64 %5, i64* %1
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @read(i32 %7, i64* %1, i32 8)
%11 = tail call i32 @close(i32 %7)
%12 = load i64, i64* %1
br label %13
13: ; preds = %9, %0
%14 = phi i64 [ %12, %9 ], [ %5, %0 ]
ret i64 %14
}