#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 */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, void *, int);
scalar_t__ time(int /*<<< orphan*/ *);
unsigned long long hw_rand(void) {
  unsigned long long seed;
  int nbytes = 0, fd = open("/dev/urandom", O_RDONLY);
  if (fd == -1)
    return (unsigned long long)time(NULL);
  read(fd, (void *)&seed, sizeof(unsigned long long));
  close(fd);
  return seed;
}


x86 assembly (clang, -O0):
<hw_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x14(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1183 <hw_rand+0x43>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x8(%rbp)
jmp    11a4 <hw_rand+0x64>
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hw_rand>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1184 <hw_rand+0x44>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %ebx,%edi
call   1030 <close@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
xor    %edi,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1050 <time@plt>

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

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