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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(unsigned long *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ mt_init_genrand(unsigned long);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ time(int /*<<< orphan*/);
void mtrandom_init() {
  FILE *f;
  uint32_t seed;
  unsigned int n;
  if (!(f = fopen("/dev/urandom", "r"))) {
    printf("No %s, initializing PRNG from system time\n", "/dev/urandom");
    seed = (unsigned long)time(0);
  } else {
    printf("%s detected, will use for PRNG initialization\n", "/dev/urandom");
    n = 0;
    while (n < sizeof(seed))
      n += fread(&seed + n, 1, sizeof(seed) - n, f);
    fclose(f);
  }
  mt_init_genrand(seed);
}


x86 assembly (clang, -O0):
<mtrandom_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11ac <mtrandom_init+0x4c>
lea    0xe7f(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,-0x10(%rbp)
jmp    1218 <mtrandom_init+0xb8>
lea    0xe87(%rip),%rdi
lea    0xe46(%rip),%rsi
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    $0x8,%rax
jae    120f <mtrandom_init+0xaf>
mov    -0x14(%rbp),%eax
lea    -0x10(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
mov    $0x8,%eax
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,%rcx
mov    -0x14(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    11c6 <mtrandom_init+0x66>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1080 <mt_init_genrand@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mtrandom_init>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d1 <mtrandom_init+0x71>
mov    %rax,%r14
lea    0xeb4(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1050 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
lea    (%rsp,%rbx,8),%rdi
mov    $0x8,%edx
sub    %eax,%edx
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
add    %rbx,%rax
mov    %eax,%ebx
cmp    $0x8,%rbx
jb     11a0 <mtrandom_init+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rdi
jmp    11ee <mtrandom_init+0x8e>
lea    0xe37(%rip),%rdi
lea    0xe21(%rip),%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <mt_init_genrand@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"No %s, initializing PRNG from system time\0A\00"
@.str.3 = [47 x i8] c"%s detected, will use for PRNG initialization\0A\00"
define void @mtrandom_init() {
%1 = alloca i32*
%2 = alloca i64
%3 = alloca i32
%4 = 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* %4, i32** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @time(i32 0)
store i64 %8, i64* %2
br label %32
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %11
11: ; preds = %15, %9
%12 = load i32, i32* %3
%13 = zext i32 %12 to i64
%14 = icmp ult i64 %13, 8
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load i32, i32* %3
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i64, i64* %2, i64 %17
%19 = load i32, i32* %3
%20 = zext i32 %19 to i64
%21 = sub i64 8, %20
%22 = trunc i64 %21 to i32
%23 = load i32*, i32** %1
%24 = call i64 @fread(i64* %18, i32 1, i32 %22, i32* %23)
%25 = load i32, i32* %3
%26 = zext i32 %25 to i64
%27 = add nsw i64 %26, %24
%28 = trunc i64 %27 to i32
store i32 %28, i32* %3
br label %11
29: ; preds = %11
%30 = load i32*, i32** %1
%31 = call i32 @fclose(i32* %30)
br label %32
32: ; preds = %29, %6
%33 = load i64, i64* %2
%34 = call i32 @mt_init_genrand(i64 %33)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"No %s, initializing PRNG from system time\0A\00"
@.str.3 = [47 x i8] c"%s detected, will use for PRNG initialization\0A\00"
define void @mtrandom_init() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = tail call i64 @time(i32 0)
br label %23
8: ; preds = %0
%9 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %18, %10 ]
%12 = phi i64 [ 0, %8 ], [ %17, %10 ]
%13 = getelementptr inbounds i64, i64* %1, i64 %11
%14 = trunc i64 %12 to i32
%15 = sub i32 8, %14
%16 = call i64 @fread(i64* %13, i32 1, i32 %15, i32* %3)
%17 = add nsw i64 %16, %11
%18 = and i64 %17, 4294967295
%19 = icmp ult i64 %18, 8
br i1 %19, label %10, label %20
20: ; preds = %10
%21 = tail call i32 @fclose(i32* %3)
%22 = load i64, i64* %1
br label %23
23: ; preds = %20, %5
%24 = phi i64 [ %22, %20 ], [ %7, %5 ]
%25 = tail call i32 @mt_init_genrand(i64 %24)
ret void
}