#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 int uint64_t;

/* Variables and functions */
extern uint64_t fast_random64(uint64_t *pmseed) {
  uint64_t hi, lo;
  uint64_t v = 0;
  for (int i = 0; i < 4; ++i) {
    lo = 16807 * (*pmseed & 0xffff);
    hi = 16807 * (*pmseed >> 16);
    lo += (hi & 0x7fff) << 16;
    lo += hi >> 15;
    *pmseed = (lo & 0x7fffffff) + (lo >> 31);
    v <<= 16;
    v |= *pmseed & 0xffff;
  }
  return v;
}


x86 assembly (clang, -O0):
<fast_random64>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    11a2 <fast_random64+0xa2>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
and    $0xffff,%eax
imul   $0x41a7,%eax,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sar    $0x10,%eax
imul   $0x41a7,%eax,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7fff,%eax
shl    $0x10,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sar    $0xf,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
and    $0x7fffffff,%ecx
mov    -0x10(%rbp),%eax
sar    $0x1f,%eax
add    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
shl    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
and    $0xffff,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1116 <fast_random64+0x16>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fast_random64>:
mov    (%rdi),%eax
movzwl %ax,%ecx
imul   $0x41a7,%ecx,%ecx
sar    $0x10,%eax
imul   $0x41a7,%eax,%edx
imul   $0x41a70000,%eax,%eax
and    $0x7fff0000,%eax
add    %ecx,%eax
sar    $0xf,%edx
add    %eax,%edx
mov    %edx,%eax
and    $0x7fffffff,%eax
sar    $0x1f,%edx
add    %eax,%edx
movzwl %dx,%eax
imul   $0x41a7,%eax,%eax
sar    $0x10,%edx
imul   $0x41a7,%edx,%esi
imul   $0x41a70000,%edx,%ecx
and    $0x7fff0000,%ecx
add    %eax,%ecx
sar    $0xf,%esi
add    %ecx,%esi
mov    %esi,%eax
and    $0x7fffffff,%eax
sar    $0x1f,%esi
add    %eax,%esi
movzwl %si,%eax
imul   $0x41a7,%eax,%eax
sar    $0x10,%esi
imul   $0x41a7,%esi,%ecx
imul   $0x41a70000,%esi,%edx
and    $0x7fff0000,%edx
add    %eax,%edx
sar    $0xf,%ecx
add    %edx,%ecx
mov    %ecx,%eax
and    $0x7fffffff,%eax
sar    $0x1f,%ecx
add    %eax,%ecx
movzwl %cx,%eax
imul   $0x41a7,%eax,%eax
mov    %ecx,%edx
sar    $0x10,%edx
imul   $0x41a7,%edx,%esi
imul   $0x41a70000,%edx,%edx
and    $0x7fff0000,%edx
add    %eax,%edx
sar    $0xf,%esi
add    %edx,%esi
mov    %esi,%eax
and    $0x7fffffff,%eax
sar    $0x1f,%esi
add    %eax,%esi
shl    $0x10,%ecx
movzwl %si,%eax
or     %ecx,%eax
mov    %esi,(%rdi)
ret

LLVM IR (-O0):
define i32 @fast_random64(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %41, %1
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %44
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = load i32, i32* %11
%13 = and i32 %12, 65535
%14 = mul nsw i32 16807, %13
store i32 %14, i32* %4
%15 = load i32*, i32** %2
%16 = load i32, i32* %15
%17 = ashr i32 %16, 16
%18 = mul nsw i32 16807, %17
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = and i32 %19, 32767
%21 = shl i32 %20, 16
%22 = load i32, i32* %4
%23 = add nsw i32 %22, %21
store i32 %23, i32* %4
%24 = load i32, i32* %3
%25 = ashr i32 %24, 15
%26 = load i32, i32* %4
%27 = add nsw i32 %26, %25
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = and i32 %28, 2147483647
%30 = load i32, i32* %4
%31 = ashr i32 %30, 31
%32 = add nsw i32 %29, %31
%33 = load i32*, i32** %2
store i32 %32, i32* %33
%34 = load i32, i32* %5
%35 = shl i32 %34, 16
store i32 %35, i32* %5
%36 = load i32*, i32** %2
%37 = load i32, i32* %36
%38 = and i32 %37, 65535
%39 = load i32, i32* %5
%40 = or i32 %39, %38
store i32 %40, i32* %5
br label %41
41: ; preds = %10
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %7
44: ; preds = %7
%45 = load i32, i32* %5
ret i32 %45
}

LLVM IR (-O2):
define i32 @fast_random64(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = and i32 %2, 65535
%4 = mul nuw nsw i32 %3, 16807
%5 = ashr i32 %2, 16
%6 = mul nsw i32 %5, 16807
%7 = mul i32 %5, 1101463552
%8 = and i32 %7, 2147418112
%9 = add nuw nsw i32 %8, %4
%10 = ashr i32 %6, 15
%11 = add nsw i32 %9, %10
%12 = and i32 %11, 2147483647
%13 = ashr i32 %11, 31
%14 = add nsw i32 %12, %13
%15 = and i32 %14, 65535
%16 = mul nuw nsw i32 %15, 16807
%17 = ashr i32 %14, 16
%18 = mul nsw i32 %17, 16807
%19 = mul i32 %17, 1101463552
%20 = and i32 %19, 2147418112
%21 = add nuw nsw i32 %20, %16
%22 = ashr i32 %18, 15
%23 = add nsw i32 %21, %22
%24 = and i32 %23, 2147483647
%25 = ashr i32 %23, 31
%26 = add nsw i32 %24, %25
%27 = and i32 %26, 65535
%28 = mul nuw nsw i32 %27, 16807
%29 = ashr i32 %26, 16
%30 = mul nsw i32 %29, 16807
%31 = mul i32 %29, 1101463552
%32 = and i32 %31, 2147418112
%33 = add nuw nsw i32 %32, %28
%34 = ashr i32 %30, 15
%35 = add nsw i32 %33, %34
%36 = and i32 %35, 2147483647
%37 = ashr i32 %35, 31
%38 = add nsw i32 %36, %37
%39 = and i32 %38, 65535
%40 = mul nuw nsw i32 %39, 16807
%41 = ashr i32 %38, 16
%42 = mul nsw i32 %41, 16807
%43 = mul i32 %41, 1101463552
%44 = and i32 %43, 2147418112
%45 = add nuw nsw i32 %44, %40
%46 = ashr i32 %42, 15
%47 = add nsw i32 %45, %46
%48 = and i32 %47, 2147483647
%49 = ashr i32 %47, 31
%50 = add nsw i32 %48, %49
%51 = shl i32 %38, 16
%52 = and i32 %50, 65535
%53 = or i32 %52, %51
store i32 %50, i32* %0
ret i32 %53
}