#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 */
long remainder(long, long);
long rand(long *random_generator, long from, long to) {
  long temp;
  if (from > to) {
    temp = to;
    to = from;
    from = temp;
  }
  *random_generator = 1103515245 * (*random_generator) + 12345;
  *random_generator = remainder(*random_generator, 0x80000000);
  return remainder(*random_generator, to - from + 1) + from;
}


x86 assembly (clang, -O0):
<rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    114a <rand+0x3a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x41c64e6d,(%rax),%rcx
add    $0x3039,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x80000000,%esi
call   1030 <remainder@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
sub    -0x10(%rbp),%rsi
add    $0x1,%rsi
call   1030 <remainder@plt>
add    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
cmp    %rdx,%rsi
mov    %rdx,%rbx
cmovg  %rsi,%rbx
cmovg  %rdx,%r15
imul   $0x41c64e6d,(%rdi),%rdi
add    $0x3039,%rdi
mov    %rdi,(%r14)
mov    $0x80000000,%esi
call   1030 <remainder@plt>
mov    %rax,(%r14)
sub    %r15,%rbx
add    $0x1,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <remainder@plt>
add    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @rand(i64* %0, i64 %1, i64 %2) {
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64* %0, i64** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i64, i64* %5
%9 = load i64, i64* %6
%10 = icmp sgt i64 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i64, i64* %6
store i64 %12, i64* %7
%13 = load i64, i64* %5
store i64 %13, i64* %6
%14 = load i64, i64* %7
store i64 %14, i64* %5
br label %15
15: ; preds = %11, %3
%16 = load i64*, i64** %4
%17 = load i64, i64* %16
%18 = mul nsw i64 1103515245, %17
%19 = add nsw i64 %18, 12345
%20 = load i64*, i64** %4
store i64 %19, i64* %20
%21 = load i64*, i64** %4
%22 = load i64, i64* %21
%23 = call i64 @remainder(i64 %22, i64 2147483648)
%24 = load i64*, i64** %4
store i64 %23, i64* %24
%25 = load i64*, i64** %4
%26 = load i64, i64* %25
%27 = load i64, i64* %6
%28 = load i64, i64* %5
%29 = sub nsw i64 %27, %28
%30 = add nsw i64 %29, 1
%31 = call i64 @remainder(i64 %26, i64 %30)
%32 = load i64, i64* %5
%33 = add nsw i64 %31, %32
ret i64 %33
}

LLVM IR (-O2):
define i64 @rand(i64* nocapture %0, i64 %1, i64 %2) {
%4 = icmp sgt i64 %1, %2
%5 = select i1 %4, i64 %1, i64 %2
%6 = select i1 %4, i64 %2, i64 %1
%7 = load i64, i64* %0
%8 = mul nsw i64 %7, 1103515245
%9 = add nsw i64 %8, 12345
store i64 %9, i64* %0
%10 = tail call i64 @remainder(i64 %9, i64 2147483648)
store i64 %10, i64* %0
%11 = sub i64 1, %6
%12 = add i64 %11, %5
%13 = tail call i64 @remainder(i64 %10, i64 %12)
%14 = add nsw i64 %13, %6
ret i64 %14
}