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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ srandom(unsigned int);
void seed(void) {
  FILE *urandom = fopen("/dev/urandom", "r");
  if (urandom == NULL) {
    perror("Could not open urandom seed file:");
    exit(EXIT_FAILURE);
  }
  unsigned int seedval;
  if (fread(&seedval, sizeof(seedval), 1, urandom) < 1) {
    perror("Could not read urandom seed file:");
    exit(EXIT_FAILURE);
  }
  srandom(seedval);
}


x86 assembly (clang, -O0):
<seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1194 <seed+0x44>
lea    0xe8e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
jge    11ce <seed+0x7e>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%edi
call   1030 <srandom@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seed>:
push   %rax
lea    0xea8(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118e <seed+0x3e>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    1197 <seed+0x47>
mov    0x4(%rsp),%edi
pop    %rax
jmp    1030 <srandom@plt>
lea    0xe7a(%rip),%rdi
jmp    119e <seed+0x4e>
lea    0xe93(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"Could not open urandom seed file:\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [34 x i8] c"Could not read urandom seed file:\00"
define void @seed() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32*, i32** %1
%12 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
%19 = load i32, i32* %2
%20 = call i32 @srandom(i32 %19)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"Could not open urandom seed file:\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [34 x i8] c"Could not read urandom seed file:\00"
define void @seed() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = bitcast i32* %1 to i8*
%10 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %2)
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %8
%17 = load i32, i32* %1
%18 = tail call i32 @srandom(i32 %17)
ret void
}