#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;
    }
  }
  printf("The seed is %d.\n", willekeurig);
  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    120a <set_seed+0xba>
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ae <set_seed+0x5e>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x29a,-0x10(%rbp)
jmp    11e6 <set_seed+0x96>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     11e1 <set_seed+0x91>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x29a,-0x10(%rbp)
jmp    11e6 <set_seed+0x96>
mov    -0x10(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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     1169 <set_seed+0x9>
jmp    1070 <srand@plt>
push   %rbp
push   %rbx
push   %rax
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11a2 <set_seed+0x42>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11ab <set_seed+0x4b>
mov    0x4(%rsp),%ebp
jmp    11bc <set_seed+0x5c>
lea    0xea0(%rip),%rdi
jmp    11b2 <set_seed+0x52>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x29a,%ebp
lea    0xe4a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1070 <srand@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <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"
@.str.3 = [17 x i8] c"The seed is %d.\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 %33
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 (i8*, ...) @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 (i8*, ...) @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 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %5
%30 = call i32 @srand(i32 %29)
%31 = load i32, i32* %3
%32 = call i32 @close(i32 %31)
store i32 %32, i32* %4
br label %33
33: ; preds = %26, %8
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.3 = [17 x i8] c"The seed is %d.\0A\00"
@str = [43 x i8] c"Failure reading /dev/urandom. So Seed=666.\00"
@str.4 = [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 %25
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.4, 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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = tail call i32 @srand(i32 %21)
%24 = tail call i32 @close(i32 %9)
br label %25
25: ; preds = %20, %5
ret void
}