#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 */
struct timeval {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ __ecm_outputf(int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned long *, int, int, int /*<<< orphan*/ *);
scalar_t__ getpid();
scalar_t__ time(int /*<<< orphan*/ *);
unsigned long __ecm_get_random_ul(void) {
  FILE *rndfd;
  struct timeval tv;
  unsigned long t;
  rndfd = fopen("/dev/urandom", "r");
  if (rndfd != NULL) {
    if (fread(&t, sizeof(unsigned long), 1, rndfd) == 1) {
      __ecm_outputf(4, "Got seed for RNG from /dev/urandom\n");
      fclose(rndfd);
      return t;
    }
    fclose(rndfd);
  }
  __ecm_outputf(4, "Got seed for RNG from time()+getpid()\n");
  return (unsigned long)time(NULL) + (unsigned long)getpid() * 2147483629UL;
}


x86 assembly (clang, -O0):
<__ecm_get_random_ul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11da <__ecm_get_random_ul+0x7a>
mov    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11d1 <__ecm_get_random_ul+0x71>
mov    $0x4,%edi
lea    0xe59(%rip),%rsi
call   1070 <__ecm_outputf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1214 <__ecm_get_random_ul+0xb4>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x4,%edi
lea    0xe4d(%rip),%rsi
call   1070 <__ecm_outputf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
imul   $0x7fffffed,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__ecm_get_random_ul>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c4 <__ecm_get_random_ul+0x64>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11bc <__ecm_get_random_ul+0x5c>
lea    0xe6c(%rip),%rsi
mov    $0x4,%edi
call   1070 <__ecm_outputf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x8(%rsp),%rax
jmp    11f0 <__ecm_get_random_ul+0x90>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe68(%rip),%rsi
mov    $0x4,%edi
call   1070 <__ecm_outputf@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
imul   $0x7fffffed,%rax,%rax
add    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"Got seed for RNG from /dev/urandom\0A\00"
@.str.3 = [39 x i8] c"Got seed for RNG from time()+getpid()\0A\00"
define i64 @__ecm_get_random_ul() {
%1 = alloca i64
%2 = alloca i32*
%3 = alloca %struct.timeval
%4 = alloca i64
%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 ne i32* %6, null
br i1 %7, label %8, label %20
8: ; preds = %0
%9 = load i32*, i32** %2
%10 = call i32 @fread(i64* %4, i32 8, i32 1, i32* %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = call i32 @__ecm_outputf(i32 4, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32*, i32** %2
%15 = call i32 @fclose(i32* %14)
%16 = load i64, i64* %4
store i64 %16, i64* %1
br label %26
17: ; preds = %8
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %17, %0
%21 = call i32 @__ecm_outputf(i32 4, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%22 = call i64 @time(i32* null)
%23 = call i64 (...) @getpid()
%24 = mul i64 %23, 2147483629
%25 = add i64 %22, %24
store i64 %25, i64* %1
br label %26
26: ; preds = %20, %12
%27 = load i64, i64* %1
ret i64 %27
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"Got seed for RNG from /dev/urandom\0A\00"
@.str.3 = [39 x i8] c"Got seed for RNG from time()+getpid()\0A\00"
define i64 @__ecm_get_random_ul() {
%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 %14, label %5
5: ; preds = %0
%6 = call i32 @fread(i64* %1, i32 8, i32 1, i32* %3)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = tail call i32 @__ecm_outputf(i32 4, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @fclose(i32* %3)
%11 = load i64, i64* %1
br label %20
12: ; preds = %5
%13 = tail call i32 @fclose(i32* %3)
br label %14
14: ; preds = %12, %0
%15 = tail call i32 @__ecm_outputf(i32 4, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i64 @time(i32* null)
%17 = tail call i64 (...) @getpid()
%18 = mul i64 %17, 2147483629
%19 = add i64 %18, %16
br label %20
20: ; preds = %14, %8
%21 = phi i64 [ %11, %8 ], [ %19, %14 ]
ret i64 %21
}