#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*/ willekeurig;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, unsigned int *, int);
int /*<<< orphan*/ srand(unsigned int);
void set_seed(unsigned int zaadje) {
  int fd, uit;
  unsigned int willekeurig;
  if (zaadje) {
    srand(zaadje);
    return;
  }
  fd = open("/dev/urandom", O_RDONLY);
  if (fd < 0) {
    printf("Unable to open /dev/urandom. So seed=666.\n");
    willekeurig = 666;
  } else {
    uit = read(fd, &willekeurig, sizeof(willekeurig));
    if (uit <= 0) {
      printf("Failure reading /dev/urandom. So Seed=666.\n");
      willekeurig = 666;
    }
  }
  srand(willekeurig);
  uit = close(fd);
  return;
}


x86 assembly (clang, -O0):
<set_seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1172 <set_seed+0x22>
mov    -0x4(%rbp),%edi
call   1060 <srand@plt>
jmp    11f5 <set_seed+0xa5>
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ac <set_seed+0x5c>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movl   $0x29a,-0x10(%rbp)
jmp    11e2 <set_seed+0x92>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     11dd <set_seed+0x8d>
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
movl   $0x29a,-0x10(%rbp)
jmp    11e2 <set_seed+0x92>
mov    -0x10(%rbp),%edi
call   1060 <srand@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0xc(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_seed>:
test   %edi,%edi
je     1159 <set_seed+0x9>
jmp    1060 <srand@plt>
push   %rbx
sub    $0x10,%rsp
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1194 <set_seed+0x44>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    119d <set_seed+0x4d>
mov    0xc(%rsp),%edi
jmp    11ae <set_seed+0x5e>
lea    0xe9d(%rip),%rdi
jmp    11a4 <set_seed+0x54>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
mov    $0x29a,%edi
call   1060 <srand@plt>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <close@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.1 = [43 x i8] c"Unable to open /dev/urandom. So seed=666.\0A\00"
@.str.2 = [44 x i8] c"Failure reading /dev/urandom. So Seed=666.\0A\00"
define void @set_seed(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i32 @srand(i32 %9)
br label %31
11: ; preds = %1
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 666, i32* %5
br label %26
18: ; preds = %11
%19 = load i32, i32* %3
%20 = call i32 @read(i32 %19, i32* %5, i32 4)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 666, i32* %5
br label %25
25: ; preds = %23, %18
br label %26
26: ; preds = %25, %16
%27 = load i32, i32* %5
%28 = call i32 @srand(i32 %27)
%29 = load i32, i32* %3
%30 = call i32 @close(i32 %29)
store i32 %30, i32* %4
br label %31
31: ; preds = %26, %8
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@str = [43 x i8] c"Failure reading /dev/urandom. So Seed=666.\00"
@str.3 = [42 x i8] c"Unable to open /dev/urandom. So seed=666.\00"
define void @set_seed(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i32 %0, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @srand(i32 %0)
br label %24
7: ; preds = %1
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.3, i64 0, i64 0))
br label %20
13: ; preds = %7
%14 = call i32 @read(i32 %9, i32* %2, i32 4)
%15 = icmp slt i32 %14, 1
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = load i32, i32* %2
br label %20
18: ; preds = %13
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %16, %18, %11
%21 = phi i32 [ %17, %16 ], [ 666, %18 ], [ 666, %11 ]
%22 = tail call i32 @srand(i32 %21)
%23 = tail call i32 @close(i32 %9)
br label %24
24: ; preds = %20, %5
ret void
}