#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 */

/* Variables and functions */
int errno;
int fill_rand(unsigned char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int, char *);
int /*<<< orphan*/ memcpy(double *, unsigned char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
double getrandom_double(void) {
  double d;
  int rv, save_errno;
  unsigned char buf[sizeof(double)];
  rv = fill_rand(buf, sizeof(double));
  if (rv != sizeof(double)) {
    save_errno = errno;
    fprintf(stderr, "getrandom returned %d not %d (err: %d, %s)\n", rv,
            (int)sizeof(double), save_errno, strerror(save_errno));
  }
  memcpy(&d, buf, sizeof(double));
  return d;
}


x86 assembly (clang, -O0):
<getrandom_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1050 <fill_rand@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x8,%rax
je     11b1 <getrandom_double+0x71>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%r8d
mov    %rax,%r9
lea    0xe59(%rip),%rsi
mov    $0x8,%ecx
call   1030 <fprintf@plt>
lea    -0x18(%rbp),%rsi
lea    -0x8(%rbp),%rdi
mov    $0x8,%edx
call   1040 <memcpy@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrandom_double>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1050 <fill_rand@plt>
cmp    $0x8,%eax
je     1194 <getrandom_double+0x54>
mov    %eax,%ebx
mov    0x2e73(%rip),%rax
mov    (%rax),%ebp
mov    0x2e72(%rip),%rax
mov    (%rax),%r14d
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xe81(%rip),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
mov    $0x8,%ecx
mov    %ebp,%r8d
mov    %rax,%r9
call   1030 <fprintf@plt>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"getrandom returned %d not %d (err: %d, %s)\0A\00"
define double @getrandom_double() {
%1 = alloca double
%2 = alloca i32
%3 = alloca i32
%4 = alloca [8 x i8]
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%6 = call i32 @fill_rand(i8* %5, i32 8)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = icmp ne i64 %8, 8
br i1 %9, label %10, label %18
10: ; preds = %0
%11 = load i32, i32* @errno
store i32 %11, i32* %3
%12 = load i32, i32* @stderr
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = load i32, i32* %3
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %13, i32 8, i32 %14, i8* %16)
br label %18
18: ; preds = %10, %0
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%20 = call i32 @memcpy(double* %1, i8* %19, i32 8)
%21 = load double, double* %1
ret double %21
}

LLVM IR (-O2):
@errno = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"getrandom returned %d not %d (err: %d, %s)\0A\00"
define double @getrandom_double() {
%1 = alloca double
%2 = alloca [8 x i8]
%3 = bitcast double* %1 to i8*
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%5 = call i32 @fill_rand(i8* %4, i32 8)
%6 = icmp eq i32 %5, 8
br i1 %6, label %12, label %7
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = load i32, i32* @stderr
%10 = call i8* @strerror(i32 %8)
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %5, i32 8, i32 %8, i8* %10)
br label %12
12: ; preds = %7, %0
%13 = call i32 @memcpy(double* %1, i8* %4, i32 8)
%14 = load double, double* %1
ret double %14
}