double dshrandom(long input) {
  static long seed = 3125;
  static long a = 16807;
  static long m = 2147483647;
  static long q = 127773;
  static long r = 2836;
  long lo, hi, test;
  if (input > 0)
    seed = input;
  hi = seed / q;
  lo = seed - (hi * q);
  test = a * lo - r * hi;
  if (test > 0)
    seed = test;
  else
    seed = test + m;
  return (((double)seed) / (double)m);
}


x86 assembly (clang, -O0):
<dshrandom>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jle    111e <dshrandom+0x1e>
mov    -0x8(%rbp),%rax
mov    %rax,0x2f02(%rip)
mov    0x2efb(%rip),%rax
cqto
idivq  0x2f0a(%rip)
mov    %rax,-0x18(%rbp)
mov    0x2ee7(%rip),%rax
mov    -0x18(%rbp),%rcx
imul   0x2ef3(%rip),%rcx
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    0x2ed5(%rip),%rax
imul   -0x10(%rbp),%rax
mov    0x2ee1(%rip),%rcx
imul   -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    1186 <dshrandom+0x86>
mov    -0x20(%rbp),%rax
mov    %rax,0x2e9f(%rip)
jmp    1198 <dshrandom+0x98>
mov    -0x20(%rbp),%rax
add    0x2e9f(%rip),%rax
mov    %rax,0x2e88(%rip)
cvtsi2sdq 0x2e7f(%rip),%xmm0
cvtsi2sdq 0x2e86(%rip),%xmm1
divsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<dshrandom>:
test   %rdi,%rdi
jg     110c <dshrandom+0xc>
mov    0x2f14(%rip),%rdi
movabs $0x41a705af1fe3fb79,%rcx
05 a7 41
mov    %rdi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xf,%rdx
add    %rax,%rdx
imul   $0xfffffffffffe0ce3,%rdx,%rax
add    %rdi,%rax
imul   $0x41a7,%rax,%rax
imul   $0xfffffffffffff4ec,%rdx,%rcx
lea    (%rax,%rcx,1),%rdx
test   %rdx,%rdx
lea    0x7fffffff(%rax,%rcx,1),%rax
7f
cmovg  %rdx,%rax
mov    %rax,0x2ec4(%rip)
cvtsi2sd %rax,%xmm0
divsd  0xe97(%rip),%xmm0
ret

LLVM IR (-O0):
@dshrandom.seed = internal global i64 3125
@dshrandom.a = internal global i64 16807
@dshrandom.m = internal global i64 2147483647
@dshrandom.q = internal global i64 127773
@dshrandom.r = internal global i64 2836
define double @dshrandom(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i64, i64* %2
store i64 %9, i64* @dshrandom.seed
br label %10
10: ; preds = %8, %1
%11 = load i64, i64* @dshrandom.seed
%12 = load i64, i64* @dshrandom.q
%13 = sdiv i64 %11, %12
store i64 %13, i64* %4
%14 = load i64, i64* @dshrandom.seed
%15 = load i64, i64* %4
%16 = load i64, i64* @dshrandom.q
%17 = mul nsw i64 %15, %16
%18 = sub nsw i64 %14, %17
store i64 %18, i64* %3
%19 = load i64, i64* @dshrandom.a
%20 = load i64, i64* %3
%21 = mul nsw i64 %19, %20
%22 = load i64, i64* @dshrandom.r
%23 = load i64, i64* %4
%24 = mul nsw i64 %22, %23
%25 = sub nsw i64 %21, %24
store i64 %25, i64* %5
%26 = load i64, i64* %5
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %10
%29 = load i64, i64* %5
store i64 %29, i64* @dshrandom.seed
br label %34
30: ; preds = %10
%31 = load i64, i64* %5
%32 = load i64, i64* @dshrandom.m
%33 = add nsw i64 %31, %32
store i64 %33, i64* @dshrandom.seed
br label %34
34: ; preds = %30, %28
%35 = load i64, i64* @dshrandom.seed
%36 = sitofp i64 %35 to double
%37 = load i64, i64* @dshrandom.m
%38 = sitofp i64 %37 to double
%39 = fdiv double %36, %38
ret double %39
}

LLVM IR (-O2):
@dshrandom.seed = internal unnamed_addr global i64 3125
define double @dshrandom(i64 %0) {
%2 = icmp sgt i64 %0, 0
%3 = load i64, i64* @dshrandom.seed
%4 = select i1 %2, i64 %0, i64 %3
%5 = sdiv i64 %4, 127773
%6 = mul nsw i64 %5, -127773
%7 = add i64 %6, %4
%8 = mul nsw i64 %7, 16807
%9 = mul nsw i64 %5, -2836
%10 = add i64 %8, %9
%11 = icmp sgt i64 %10, 0
%12 = add nsw i64 %10, 2147483647
%13 = select i1 %11, i64 %10, i64 %12
store i64 %13, i64* @dshrandom.seed
%14 = sitofp i64 %13 to double
%15 = fdiv double %14, 0x41DFFFFFFFC00000
ret double %15
}