#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 uint32_t;
typedef int uint16_t;

/* Variables and functions */
int randLIB_get_random_in_range(int, int);
uint32_t randLIB_randomise_base(uint32_t base, uint16_t min_factor,
                                uint16_t max_factor) {
  uint16_t random_factor = randLIB_get_random_in_range(min_factor, max_factor);
  uint32_t hi = (base >> 16) * random_factor;
  uint32_t lo = (base & 0xFFFF) * random_factor;
  uint32_t res = hi + (lo >> 16);
  if (res & 0x80000000) {
    res = 0xFFFFFFFF;
  } else {
    res = (res << 1) | ((lo >> 15) & 1);
  }
  return res;
}


x86 assembly (clang, -O0):
<randLIB_randomise_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <randLIB_get_random_in_range@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffff,%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sar    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1176 <randLIB_randomise_base+0x66>
movl   $0xffffffff,-0x1c(%rbp)
jmp    118a <randLIB_randomise_base+0x7a>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    -0x18(%rbp),%ecx
sar    $0xf,%ecx
and    $0x1,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randLIB_randomise_base>:
push   %rbx
mov    %edi,%ebx
mov    %esi,%edi
mov    %edx,%esi
call   1030 <randLIB_get_random_in_range@plt>
mov    %ebx,%ecx
sar    $0x10,%ecx
imul   %eax,%ecx
movzwl %bx,%edx
imul   %eax,%edx
mov    %edx,%eax
sar    $0x10,%eax
add    %ecx,%eax
shr    $0xf,%edx
and    $0x1,%edx
test   %eax,%eax
lea    (%rdx,%rax,2),%ecx
mov    $0xffffffff,%eax
cmovns %ecx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @randLIB_randomise_base(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @randLIB_get_random_in_range(i32 %1, i32 %2)
%5 = ashr i32 %0, 16
%6 = mul nsw i32 %4, %5
%7 = and i32 %0, 65535
%8 = mul nsw i32 %4, %7
%9 = ashr i32 %8, 16
%10 = add nsw i32 %9, %6
%11 = icmp sgt i32 %10, -1
%12 = shl i32 %10, 1
%13 = lshr i32 %8, 15
%14 = and i32 %13, 1
%15 = or i32 %12, %14
%16 = select i1 %11, i32 %15, i32 -1
ret i32 %16
}