#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 /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, unsigned int *, int);
int /*<<< orphan*/ srand(unsigned int);
void init_random() {
  int fd = open("/dev/urandom", O_RDONLY);
  if (fd < 0)
    goto perror;
  unsigned int seed;
  if (read(fd, &seed, sizeof(seed)) != sizeof(seed))
    goto perror;
  srand(seed);
  close(fd);
  return;
perror:
  perror("init_random");
  exit(1);
}


x86 assembly (clang, -O0):
<init_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    118f <init_random+0x2f>
jmp    11c7 <init_random+0x67>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cltq
cmp    $0x4,%rax
je     11b1 <init_random+0x51>
jmp    11c7 <init_random+0x67>
mov    -0x8(%rbp),%edi
call   1050 <srand@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret
lea    0xe3f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<init_random>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11ab <init_random+0x4b>
mov    %eax,%ebx
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    11ab <init_random+0x4b>
mov    0xc(%rsp),%edi
call   1050 <srand@plt>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <close@plt>
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.1 = [12 x i8] c"init_random\00"
define void @init_random() {
%1 = alloca i32
%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 = icmp slt i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = call i32 @read(i32 %3, i32* %1, i32 4)
%7 = icmp eq i32 %6, 4
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i32, i32* %1
%10 = tail call i32 @srand(i32 %9)
%11 = tail call i32 @close(i32 %3)
ret void
12: ; preds = %5, %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
}