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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned int *, int, int, int /*<<< orphan*/ *);
int fwrite(long *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
long random();
int /*<<< orphan*/ srandom(unsigned int);
int /*<<< orphan*/ stdout;
int main() {
  long int value;
  unsigned int seed;
  FILE *fp;
  fp = fopen("/dev/urandom", "r");
  if (fp == NULL) {
    perror("fopen");
    exit(1);
  }
  if (fread(&seed, sizeof(seed), 1, fp) != 1) {
    perror("fread");
    exit(2);
  }
  fclose(fp);
  srandom(seed);
  for (;;) {
    value = random();
    if (fwrite(&value, sizeof(value), 1, stdout) != 1) {
      perror("fwrite");
      exit(3);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c7 <main+0x47>
lea    0xe57(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     11fd <main+0x7d>
lea    0xe27(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x14(%rbp),%edi
call   1030 <srandom@plt>
mov    $0x0,%al
call   1060 <random@plt>
mov    %rax,-0x10(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%ecx
lea    -0x10(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
je     1254 <main+0xd4>
lea    0xdd6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
jmp    120e <main+0x8e>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe72(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11b5 <main+0x35>
lea    0xe69(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    123c <main+0xbc>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0xc(%rsp),%edi
call   1030 <srandom@plt>
mov    0x2df4(%rip),%r14
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <random@plt>
mov    %rax,0x10(%rsp)
mov    (%r14),%ecx
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
je     1200 <main+0x80>
lea    0xdee(%rip),%rdi
call   1080 <perror@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
lea    0xdd2(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [6 x i8] c"fread\00"
@stdout = global i32 0
@.str.4 = [7 x i8] c"fwrite\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32*
store i32 0, 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** %4
%6 = load i32*, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32*, i32** %4
%13 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %12)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %11
%19 = load i32*, i32** %4
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %3
%22 = call i32 @srandom(i32 %21)
br label %23
23: ; preds = %31, %18
%24 = call i64 (...) @random()
store i64 %24, i64* %2
%25 = load i32, i32* @stdout
%26 = call i32 @fwrite(i64* %2, i32 8, i32 1, i32 %25)
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @exit(i32 3)
unreachable
31: ; preds = %23
br label %23
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [6 x i8] c"fread\00"
@stdout = global i32 0
@.str.4 = [7 x i8] c"fwrite\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i32
%3 = bitcast i64* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = 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))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %5)
%12 = icmp eq i32 %11, 1
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %10
%17 = tail call i32 @fclose(i32* %5)
%18 = load i32, i32* %2
%19 = tail call i32 @srandom(i32 %18)
br label %20
20: ; preds = %20, %16
%21 = call i64 (...) @random()
store i64 %21, i64* %1
%22 = load i32, i32* @stdout
%23 = call i32 @fwrite(i64* %1, i32 8, i32 1, i32 %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %20, label %25
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @exit(i32 3)
unreachable
}