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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fread(unsigned int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ stderr;
int my_seed_random(void) {
  int iRC = EXIT_SUCCESS;
  FILE *urandom;
  unsigned int seed;
  urandom = fopen("/dev/urandom", "r");
  if (NULL == urandom) {
    fprintf(stderr, "error opening /dev/urandom\n");
    iRC = EXIT_FAILURE;
  }
  if (0 == fread(&seed, sizeof(seed), 1, urandom)) {
    iRC = EXIT_FAILURE;
  }
  srand(seed);
  return (iRC);
}


x86 assembly (clang, -O0):
<my_seed_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
lea    0xea5(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1198 <my_seed_random+0x58>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11c9 <my_seed_random+0x89>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <srand@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_seed_random>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e86(%rip),%rax
mov    (%rax),%ebp
lea    0xead(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1185 <my_seed_random+0x45>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%ebp
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    11aa <my_seed_random+0x6a>
mov    0x2e30(%rip),%rax
mov    (%rax),%ebp
mov    0x4(%rsp),%edi
call   1040 <srand@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"error opening /dev/urandom\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @my_seed_random() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = load i32, i32* @EXIT_SUCCESS
store i32 %4, i32* %1
%5 = 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* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* null, %6
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
store i32 %11, i32* %1
br label %12
12: ; preds = %8, %0
%13 = load i32*, i32** %2
%14 = call i64 @fread(i32* %3, i32 4, i32 1, i32* %13)
%15 = icmp eq i64 0, %14
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %1
br label %18
18: ; preds = %16, %12
%19 = load i32, i32* %3
%20 = call i32 @srand(i32 %19)
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"error opening /dev/urandom\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @my_seed_random() {
%1 = alloca i32
%2 = load i32, i32* @EXIT_SUCCESS
%3 = bitcast i32* %1 to i8*
%4 = 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))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
br label %10
10: ; preds = %6, %0
%11 = phi i32 [ %9, %6 ], [ %2, %0 ]
%12 = call i64 @fread(i32* %1, i32 4, i32 1, i32* %4)
%13 = icmp eq i64 %12, 0
%14 = load i32, i32* @EXIT_FAILURE
%15 = select i1 %13, i32 %14, i32 %11
%16 = load i32, i32* %1
%17 = tail call i32 @srand(i32 %16)
ret i32 %15
}