#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;

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


x86 assembly (clang, -O0):
<get_seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1184 <get_seed+0x44>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a5 <get_seed+0x65>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_seed>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,0x8(%rsp)
test   %ebx,%ebx
js     1189 <get_seed+0x49>
lea    0x8(%rsp),%rsi
mov    %ebx,%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

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