#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ 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("Couldn't open urandom file");
    exit(EXIT_FAILURE);
  }
  unsigned int seedVal;
  if (fread(&seedVal, sizeof(seedVal), 1, urandom) == 0) {
    perror("Couldn't read urandom file");
    exit(EXIT_FAILURE);
  }
  srandom(seedVal);
  fclose(urandom);
}


x86 assembly (clang, -O0):
<seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a4 <seed+0x44>
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
jne    11df <seed+0x7f>
lea    0xe5e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
call   1030 <srandom@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seed>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b2 <seed+0x52>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11bb <seed+0x5b>
mov    0xc(%rsp),%edi
call   1030 <srandom@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1050 <fclose@plt>
lea    0xe56(%rip),%rdi
jmp    11c2 <seed+0x62>
lea    0xe68(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Couldn't open urandom file\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [27 x i8] c"Couldn't read urandom 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 ([27 x i8], [27 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 i64 @fread(i32* %2, i32 4, i32 1, i32* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 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)
%21 = load i32*, i32** %1
%22 = call i32 @fclose(i32* %21)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Couldn't open urandom file\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [27 x i8] c"Couldn't read urandom 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 ([27 x i8], [27 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 i64 @fread(i32* %1, i32 4, i32 1, i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 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)
%19 = tail call i32 @fclose(i32* %2)
ret void
}