#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  unsigned short mantissa0;
  unsigned short mantissa1;
  int /*<<< orphan*/ exponent;
  scalar_t__ negative;
};
union ieee754_double {
  double d;
  TYPE_1__ ieee;
};
struct drand48_data {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ IEEE754_DOUBLE_BIAS;
scalar_t__ __drand48_iterate(unsigned short *, struct drand48_data *);
int erand48_r(unsigned short int xsubi[3], struct drand48_data *buffer,
              double *result) {
  union ieee754_double temp;
  if (__drand48_iterate(xsubi, buffer) < 0)
    return -1;
  temp.ieee.negative = 0;
  temp.ieee.exponent = IEEE754_DOUBLE_BIAS;
  temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12);
  temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4);
  *result = temp.d - 1.0;
  return 0;
}


x86 assembly (clang, -O0):
<erand48_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <__drand48_iterate@plt>
cmp    $0x0,%rax
jge    1147 <erand48_r+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <erand48_r+0xa7>
movq   $0x0,-0x28(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movzwl 0x4(%rax),%eax
shl    $0x4,%eax
mov    -0x10(%rbp),%rcx
movzwl 0x2(%rcx),%ecx
sar    $0xc,%ecx
or     %ecx,%eax
mov    %ax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movzwl 0x2(%rax),%eax
and    $0xfff,%eax
shl    $0x14,%eax
mov    -0x10(%rbp),%rcx
movzwl (%rcx),%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    %ax,-0x2e(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<erand48_r>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
call   1030 <__drand48_iterate@plt>
test   %rax,%rax
js     116a <erand48_r+0x5a>
mov    0x2ebd(%rip),%rax
mov    (%rax),%eax
shl    $0x20,%rax
movzwl 0x2(%rbx),%ecx
movzwl 0x4(%rbx),%edx
shld   $0x4,%cx,%dx
movzwl %dx,%ecx
or     %rax,%rcx
movzwl (%rbx),%eax
shl    $0x4,%eax
movzwl %ax,%eax
shl    $0x10,%rax
or     %rcx,%rax
movq   %rax,%xmm0
addsd  0xe9f(%rip),%xmm0
movsd  %xmm0,(%r14)
xor    %eax,%eax
jmp    116f <erand48_r+0x5f>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.drand48_data = type { i32 }
%union.ieee754_double = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i16, i16, i32, i64 }
@IEEE754_DOUBLE_BIAS = global i32 0
define i32 @erand48_r(i16* %0, %struct.drand48_data* %1, double* %2) {
%4 = alloca i32
%5 = alloca i16*
%6 = alloca %struct.drand48_data*
%7 = alloca double*
%8 = alloca %union.ieee754_double
store i16* %0, i16** %5
store %struct.drand48_data* %1, %struct.drand48_data** %6
store double* %2, double** %7
%9 = load i16*, i16** %5
%10 = load %struct.drand48_data*, %struct.drand48_data** %6
%11 = call i64 @__drand48_iterate(i16* %9, %struct.drand48_data* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %53
14: ; preds = %3
%15 = bitcast %union.ieee754_double* %8 to %struct.TYPE_2__*
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 3
store i64 0, i64* %16
%17 = load i32, i32* @IEEE754_DOUBLE_BIAS
%18 = bitcast %union.ieee754_double* %8 to %struct.TYPE_2__*
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 2
store i32 %17, i32* %19
%20 = load i16*, i16** %5
%21 = getelementptr inbounds i16, i16* %20, i64 2
%22 = load i16, i16* %21
%23 = zext i16 %22 to i32
%24 = shl i32 %23, 4
%25 = load i16*, i16** %5
%26 = getelementptr inbounds i16, i16* %25, i64 1
%27 = load i16, i16* %26
%28 = zext i16 %27 to i32
%29 = ashr i32 %28, 12
%30 = or i32 %24, %29
%31 = trunc i32 %30 to i16
%32 = bitcast %union.ieee754_double* %8 to %struct.TYPE_2__*
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
store i16 %31, i16* %33
%34 = load i16*, i16** %5
%35 = getelementptr inbounds i16, i16* %34, i64 1
%36 = load i16, i16* %35
%37 = zext i16 %36 to i32
%38 = and i32 %37, 4095
%39 = shl i32 %38, 20
%40 = load i16*, i16** %5
%41 = getelementptr inbounds i16, i16* %40, i64 0
%42 = load i16, i16* %41
%43 = zext i16 %42 to i32
%44 = shl i32 %43, 4
%45 = or i32 %39, %44
%46 = trunc i32 %45 to i16
%47 = bitcast %union.ieee754_double* %8 to %struct.TYPE_2__*
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 1
store i16 %46, i16* %48
%49 = bitcast %union.ieee754_double* %8 to double*
%50 = load double, double* %49
%51 = fsub double %50, 1.000000e+00
%52 = load double*, double** %7
store double %51, double* %52
store i32 0, i32* %4
br label %53
53: ; preds = %14, %13
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
%struct.drand48_data = type { i32 }
@IEEE754_DOUBLE_BIAS = global i32 0
define i32 @erand48_r(i16* %0, %struct.drand48_data* %1, double* nocapture writeonly %2) {
%4 = tail call i64 @__drand48_iterate(i16* %0, %struct.drand48_data* %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = load i32, i32* @IEEE754_DOUBLE_BIAS
%8 = zext i32 %7 to i64
%9 = shl nuw i64 %8, 32
%10 = getelementptr inbounds i16, i16* %0, i64 2
%11 = load i16, i16* %10
%12 = getelementptr inbounds i16, i16* %0, i64 1
%13 = load i16, i16* %12
%14 = tail call i16 @llvm.fshl.i16(i16 %11, i16 %13, i16 4)
%15 = zext i16 %14 to i64
%16 = or i64 %9, %15
%17 = load i16, i16* %0
%18 = shl i16 %17, 4
%19 = zext i16 %18 to i64
%20 = shl nuw nsw i64 %19, 16
%21 = or i64 %20, %16
%22 = bitcast i64 %21 to double
%23 = fadd double %22, -1.000000e+00
store double %23, double* %2
br label %24
24: ; preds = %3, %6
%25 = phi i32 [ 0, %6 ], [ -1, %3 ]
ret i32 %25
}