#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 /*<<< orphan*/ mpfr_t;

/* Variables and functions */
long const MPFR_PREC_MAX;
int /*<<< orphan*/ MPFR_RNDN;
int /*<<< orphan*/ m_clear(int /*<<< orphan*/);
int /*<<< orphan*/ m_init2(int /*<<< orphan*/, long const);
int /*<<< orphan*/ m_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_setsign(int /*<<< orphan*/, int /*<<< orphan*/,
                                int const, int /*<<< orphan*/);
int /*<<< orphan*/ setRandomValue(int /*<<< orphan*/ *);
int generateRandomValueInPrecisionRange(mpfr_t *randomValue,
                                        const long int precision,
                                        const mpfr_t maxValueInRange,
                                        const int flagSign) {
  mpfr_t tmpRnd;
  if (precision * 2 < MPFR_PREC_MAX) {
    m_init2(tmpRnd, precision * 2);
  } else {
    m_init2(tmpRnd, MPFR_PREC_MAX - 1);
  }
  setRandomValue(&tmpRnd);
  m_mul(*randomValue, tmpRnd, maxValueInRange, MPFR_RNDN);
  mpfr_setsign(*randomValue, *randomValue, flagSign, MPFR_RNDN);
  m_clear(tmpRnd);
  return 0;
}


x86 assembly (clang, -O0):
<generateRandomValueInPrecisionRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%rax
jge    1193 <generateRandomValueInPrecisionRange+0x43>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
shl    $0x1,%rsi
call   1070 <m_init2@plt>
jmp    11a9 <generateRandomValueInPrecisionRange+0x59>
mov    -0x1c(%rbp),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%rsi
sub    $0x1,%rsi
call   1070 <m_init2@plt>
lea    -0x1c(%rbp),%rdi
call   1040 <setRandomValue@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    0x2e23(%rip),%rax
mov    (%rax),%ecx
call   1030 <m_mul@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
mov    0x2e06(%rip),%rax
mov    (%rax),%ecx
call   1050 <mpfr_setsign@plt>
mov    -0x1c(%rbp),%edi
call   1060 <m_clear@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateRandomValueInPrecisionRange>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rdi,%rbx
lea    (%rsi,%rsi,1),%rax
test   %rsi,%rsi
mov    $0xffffffffffffffff,%rsi
cmovs  %rax,%rsi
call   1070 <m_init2@plt>
lea    0x4(%rsp),%rdi
call   1040 <setRandomValue@plt>
mov    (%rbx),%edi
mov    0x4(%rsp),%esi
mov    0x2e5a(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    %r15d,%edx
call   1030 <m_mul@plt>
mov    (%rbx),%edi
mov    0x0(%rbp),%ecx
mov    %edi,%esi
mov    %r14d,%edx
call   1050 <mpfr_setsign@plt>
mov    0x4(%rsp),%edi
call   1060 <m_clear@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MPFR_PREC_MAX = constant i64 0
@MPFR_RNDN = global i32 0
define i32 @generateRandomValueInPrecisionRange(i32* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i64, i64* %6
%11 = mul nsw i64 %10, 2
%12 = load i64, i64* @MPFR_PREC_MAX
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %4
%15 = load i32, i32* %9
%16 = load i64, i64* %6
%17 = mul nsw i64 %16, 2
%18 = call i32 @m_init2(i32 %15, i64 %17)
br label %24
19: ; preds = %4
%20 = load i32, i32* %9
%21 = load i64, i64* @MPFR_PREC_MAX
%22 = sub nsw i64 %21, 1
%23 = call i32 @m_init2(i32 %20, i64 %22)
br label %24
24: ; preds = %19, %14
%25 = call i32 @setRandomValue(i32* %9)
%26 = load i32*, i32** %5
%27 = load i32, i32* %26
%28 = load i32, i32* %9
%29 = load i32, i32* %7
%30 = load i32, i32* @MPFR_RNDN
%31 = call i32 @m_mul(i32 %27, i32 %28, i32 %29, i32 %30)
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = load i32*, i32** %5
%35 = load i32, i32* %34
%36 = load i32, i32* %8
%37 = load i32, i32* @MPFR_RNDN
%38 = call i32 @mpfr_setsign(i32 %33, i32 %35, i32 %36, i32 %37)
%39 = load i32, i32* %9
%40 = call i32 @m_clear(i32 %39)
ret i32 0
}

LLVM IR (-O2):
@MPFR_PREC_MAX = constant i64 0
@MPFR_RNDN = global i32 0
define i32 @generateRandomValueInPrecisionRange(i32* nocapture %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = shl nsw i64 %1, 1
%8 = icmp sgt i64 %1, -1
%9 = select i1 %8, i64 -1, i64 %7
%10 = tail call i32 @m_init2(i32 undef, i64 %9)
%11 = call i32 @setRandomValue(i32* %5)
%12 = load i32, i32* %0
%13 = load i32, i32* %5
%14 = load i32, i32* @MPFR_RNDN
%15 = call i32 @m_mul(i32 %12, i32 %13, i32 %2, i32 %14)
%16 = load i32, i32* %0
%17 = load i32, i32* @MPFR_RNDN
%18 = call i32 @mpfr_setsign(i32 %16, i32 %16, i32 %3, i32 %17)
%19 = load i32, i32* %5
%20 = call i32 @m_clear(i32 %19)
ret i32 0
}