#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, long *, int);
unsigned long longdevrandomseed() {
  int randomData = open("/dev/random", O_RDONLY);
  long sjhRandomInteger;
  ssize_t rs;
  rs = read(randomData, &sjhRandomInteger, sizeof sjhRandomInteger);
  if (rs < 0)
    printf("Error reading randomData in longdevrandomseed\n");
  close(randomData);
  printf("in devrandomseed, seed is %ld (%lu)\n", sjhRandomInteger,
         (unsigned long int)sjhRandomInteger);
  return sjhRandomInteger;
}


x86 assembly (clang, -O0):
<longdevrandomseed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    118e <longdevrandomseed+0x4e>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longdevrandomseed>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1060 <read@plt>
test   %rax,%rax
jns    118e <longdevrandomseed+0x3e>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%rbx
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@.str.1 = [47 x i8] c"Error reading randomData in longdevrandomseed\0A\00"
@.str.2 = [37 x i8] c"in devrandomseed, seed is %ld (%lu)\0A\00"
define i64 @longdevrandomseed() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = call i64 @read(i32 %6, i64* %2, i32 8)
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = load i32, i32* %1
%14 = call i32 @close(i32 %13)
%15 = load i64, i64* %2
%16 = load i64, i64* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %15, i64 %16)
%18 = load i64, i64* %2
ret i64 %18
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@.str.2 = [37 x i8] c"in devrandomseed, seed is %ld (%lu)\0A\00"
@str = [46 x i8] c"Error reading randomData in longdevrandomseed\00"
define i64 @longdevrandomseed() {
%1 = alloca i64
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = bitcast i64* %1 to i8*
%5 = call i64 @read(i32 %3, i64* %1, i32 8)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = tail call i32 @close(i32 %3)
%11 = load i64, i64* %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %11, i64 %11)
ret i64 %11
}