#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*/ mpz_t;
typedef int /*<<< orphan*/ gmp_randstate_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_pow_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_urandomm(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
void gen_number(mpz_t p, int bitlength, gmp_randstate_t r_state) {
  mpz_t min_value, max_value, two;
  mpz_init(min_value);
  mpz_init(max_value);
  mpz_init(two);
  mpz_set_ui(two, 2);
  mpz_pow_ui(min_value, two, bitlength - 1);
  mpz_pow_ui(max_value, two, bitlength);
  mpz_sub(max_value, max_value, min_value);
  mpz_urandomm(p, r_state, max_value);
  mpz_add(p, p, min_value);
  mpz_clear(min_value);
  mpz_clear(max_value);
  mpz_clear(two);
}


x86 assembly (clang, -O0):
<gen_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x14(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x18(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x18(%rbp),%edi
mov    $0x2,%esi
call   1070 <mpz_set_ui@plt>
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
call   1060 <mpz_pow_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1060 <mpz_pow_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <mpz_sub@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1090 <mpz_urandomm@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <mpz_add@plt>
mov    -0x10(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x14(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x18(%rbp),%edi
call   1080 <mpz_clear@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_number>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
call   1040 <mpz_init@plt>
call   1040 <mpz_init@plt>
call   1040 <mpz_init@plt>
mov    $0x2,%esi
call   1070 <mpz_set_ui@plt>
lea    -0x1(%rbp),%edx
call   1060 <mpz_pow_ui@plt>
mov    %ebp,%edx
call   1060 <mpz_pow_ui@plt>
call   1030 <mpz_sub@plt>
mov    %ebx,%edi
mov    %r14d,%esi
call   1090 <mpz_urandomm@plt>
mov    %ebx,%edi
mov    %ebx,%esi
call   1050 <mpz_add@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <mpz_clear@plt>

LLVM IR (-O0):
define void @gen_number(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %7
%11 = call i32 @mpz_init(i32 %10)
%12 = load i32, i32* %8
%13 = call i32 @mpz_init(i32 %12)
%14 = load i32, i32* %9
%15 = call i32 @mpz_init(i32 %14)
%16 = load i32, i32* %9
%17 = call i32 @mpz_set_ui(i32 %16, i32 2)
%18 = load i32, i32* %7
%19 = load i32, i32* %9
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 1
%22 = call i32 @mpz_pow_ui(i32 %18, i32 %19, i32 %21)
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = load i32, i32* %5
%26 = call i32 @mpz_pow_ui(i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* %8
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = call i32 @mpz_sub(i32 %27, i32 %28, i32 %29)
%31 = load i32, i32* %4
%32 = load i32, i32* %6
%33 = load i32, i32* %8
%34 = call i32 @mpz_urandomm(i32 %31, i32 %32, i32 %33)
%35 = load i32, i32* %4
%36 = load i32, i32* %4
%37 = load i32, i32* %7
%38 = call i32 @mpz_add(i32 %35, i32 %36, i32 %37)
%39 = load i32, i32* %7
%40 = call i32 @mpz_clear(i32 %39)
%41 = load i32, i32* %8
%42 = call i32 @mpz_clear(i32 %41)
%43 = load i32, i32* %9
%44 = call i32 @mpz_clear(i32 %43)
ret void
}

LLVM IR (-O2):
define void @gen_number(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mpz_init(i32 undef)
%5 = tail call i32 @mpz_init(i32 undef)
%6 = tail call i32 @mpz_init(i32 undef)
%7 = tail call i32 @mpz_set_ui(i32 undef, i32 2)
%8 = add nsw i32 %1, -1
%9 = tail call i32 @mpz_pow_ui(i32 undef, i32 undef, i32 %8)
%10 = tail call i32 @mpz_pow_ui(i32 undef, i32 undef, i32 %1)
%11 = tail call i32 @mpz_sub(i32 undef, i32 undef, i32 undef)
%12 = tail call i32 @mpz_urandomm(i32 %0, i32 %2, i32 undef)
%13 = tail call i32 @mpz_add(i32 %0, i32 %0, i32 undef)
%14 = tail call i32 @mpz_clear(i32 undef)
%15 = tail call i32 @mpz_clear(i32 undef)
%16 = tail call i32 @mpz_clear(i32 undef)
ret void
}