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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
uint32_t get_random_seed() {
  const int nread = 4;
  FILE *r = NULL;
  uint32_t seed = (uint32_t)0;
  char buffer[4];
  assert((size_t)nread == sizeof(uint32_t));
  r = fopen("/dev/random", "r");
  if (r == NULL) {
    time_t current_time;
    fprintf(stderr, "*** Warning: Failed to open /dev/random, "
                    "falling back on system clock for random seed ***\n");
    current_time = time(NULL);
    return (uint32_t)current_time;
  }
  assert((size_t)nread == fread(buffer, sizeof(char), (size_t)nread, r));
  seed = *((uint32_t *)buffer);
  fclose(r);
  return seed;
}


x86 assembly (clang, -O0):
<get_random_seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x4,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x1,%edi
call   1050 <assert@plt>
lea    0xe71(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d6 <get_random_seed+0x76>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121a <get_random_seed+0xba>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %rax,%rcx
mov    $0x4,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_random_seed>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%edi
call   1050 <assert@plt>
lea    0xe8c(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c3 <get_random_seed+0x63>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
mov    $0x4,%edx
mov    $0x1,%esi
mov    %rax,%rcx
call   1030 <fread@plt>
xor    %edi,%edi
cmp    $0x4,%rax
sete   %dil
call   1050 <assert@plt>
mov    0x4(%rsp),%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <time@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [91 x i8] c"*** Warning: Failed to open /dev/random, falling back on system clock for random seed ***\0A\00"
define i32 @get_random_seed() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [4 x i8]
%6 = alloca i32
store i32 4, i32* %2
store i32* null, i32** %3
store i32 0, i32* %4
%7 = call i32 @assert(i32 1)
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @time(i32* null)
store i32 %14, i32* %6
%15 = load i32, i32* %6
store i32 %15, i32* %1
br label %29
16: ; preds = %0
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%18 = load i32*, i32** %3
%19 = call i64 @fread(i8* %17, i32 1, i64 4, i32* %18)
%20 = icmp eq i64 4, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
store i32 %25, i32* %4
%26 = load i32*, i32** %3
%27 = call i32 @fclose(i32* %26)
%28 = load i32, i32* %4
store i32 %28, i32* %1
br label %29
29: ; preds = %16, %11
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/random\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [91 x i8] c"*** Warning: Failed to open /dev/random, falling back on system clock for random seed ***\0A\00"
define i32 @get_random_seed() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @assert(i32 1)
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @time(i32* null)
br label %17
10: ; preds = %0
%11 = call i64 @fread(i8* %2, i32 1, i64 4, i32* %4)
%12 = icmp eq i64 %11, 4
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = load i32, i32* %1
%16 = tail call i32 @fclose(i32* %4)
br label %17
17: ; preds = %10, %6
%18 = phi i32 [ %9, %6 ], [ %15, %10 ]
ret i32 %18
}