#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 long uint8_t;
typedef long uint32_t;
typedef long int32_t;

/* Variables and functions */
scalar_t__ UINT8_MAX;
uint8_t do_random(uint32_t *ctx) {
  int32_t hi, lo, x;
  x = *ctx;
  if (x == 0)
    x = 123459876L;
  hi = x / 127773L;
  lo = x % 127773L;
  x = 16807L * lo - 2836L * hi;
  if (x < 0)
    x += 0x7fffffffL;
  return ((*ctx = x) % ((uint8_t)UINT8_MAX + 1));
}


x86 assembly (clang, -O0):
<do_random>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1126 <do_random+0x26>
movq   $0x75bd924,-0x20(%rbp)
07
mov    -0x20(%rbp),%rax
mov    $0x1f31d,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x1f31d,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x18(%rbp)
imul   $0x41a7,-0x18(%rbp),%rax
imul   $0xb14,-0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    117a <do_random+0x7a>
mov    -0x20(%rbp),%rax
add    $0x7fffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    %rax,(%rcx)
mov    0x2e54(%rip),%rcx
mov    (%rcx),%rcx
add    $0x1,%rcx
cqto
idiv   %rcx
mov    %rdx,%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_random>:
mov    (%rdi),%rax
test   %rax,%rax
mov    $0x75bd924,%ecx
cmovne %rax,%rcx
movabs $0x41a705af1fe3fb79,%rdx
05 a7 41
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xf,%rdx
add    %rax,%rdx
imul   $0x1f31d,%rdx,%rax
sub    %rax,%rcx
imul   $0x41a7,%rcx,%rcx
imul   $0xfffffffffffff4ec,%rdx,%rdx
lea    (%rdx,%rcx,1),%rax
add    $0x7fffffff,%rax
add    %rcx,%rdx
cmovns %rdx,%rax
mov    %rax,(%rdi)
mov    0x2e80(%rip),%rcx
mov    (%rcx),%rcx
add    $0x1,%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     117c <do_random+0x7c>
cqto
idiv   %rcx
mov    %rdx,%rax
ret
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
ret

LLVM IR (-O0):
@UINT8_MAX = global i64 0
define i64 @do_random(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 = load i64, i64* %6
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i64 123459876, i64* %5
br label %11
11: ; preds = %10, %1
%12 = load i64, i64* %5
%13 = sdiv i64 %12, 127773
store i64 %13, i64* %3
%14 = load i64, i64* %5
%15 = srem i64 %14, 127773
store i64 %15, i64* %4
%16 = load i64, i64* %4
%17 = mul nsw i64 16807, %16
%18 = load i64, i64* %3
%19 = mul nsw i64 2836, %18
%20 = sub nsw i64 %17, %19
store i64 %20, i64* %5
%21 = load i64, i64* %5
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %11
%24 = load i64, i64* %5
%25 = add nsw i64 %24, 2147483647
store i64 %25, i64* %5
br label %26
26: ; preds = %23, %11
%27 = load i64, i64* %5
%28 = load i64*, i64** %2
store i64 %27, i64* %28
%29 = load i64, i64* @UINT8_MAX
%30 = add nsw i64 %29, 1
%31 = srem i64 %27, %30
ret i64 %31
}

LLVM IR (-O2):
@UINT8_MAX = global i64 0
define i64 @do_random(i64* nocapture %0) {
%2 = load i64, i64* %0
%3 = icmp eq i64 %2, 0
%4 = select i1 %3, i64 123459876, i64 %2
%5 = sdiv i64 %4, 127773
%6 = srem i64 %4, 127773
%7 = mul nsw i64 %6, 16807
%8 = mul nsw i64 %5, -2836
%9 = add nsw i64 %8, %7
%10 = icmp slt i64 %9, 0
%11 = add nsw i64 %9, 2147483647
%12 = select i1 %10, i64 %11, i64 %9
store i64 %12, i64* %0
%13 = load i64, i64* @UINT8_MAX
%14 = add nsw i64 %13, 1
%15 = srem i64 %12, %14
ret i64 %15
}