#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*/ gmp_randclear(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randinit_mt(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randseed_ui(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_nextprime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_rrandomb(int /*<<< orphan*/, int /*<<< orphan*/,
                                unsigned long);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void getRandomPrime(mpz_t prime, unsigned long n, int coeff) {
  unsigned long seed;
  mpz_t random;
  gmp_randstate_t state;
  srand(time(NULL));
  seed = rand() * coeff;
  mpz_init(random);
  gmp_randinit_mt(state);
  gmp_randseed_ui(state, seed);
  mpz_rrandomb(random, state, n);
  mpz_nextprime(prime, random);
  gmp_randclear(state);
  mpz_clear(random);
}


x86 assembly (clang, -O0):
<getRandomPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
imul   -0x14(%rbp),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x28(%rbp),%edi
call   10a0 <gmp_randinit_mt@plt>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1090 <gmp_randseed_ui@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   10b0 <mpz_rrandomb@plt>
mov    -0x4(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1070 <mpz_nextprime@plt>
mov    -0x28(%rbp),%edi
call   1030 <gmp_randclear@plt>
mov    -0x24(%rbp),%edi
call   1080 <mpz_clear@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRandomPrime>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   10c0 <rand@plt>
imul   %ebp,%eax
movslq %eax,%rbp
call   1050 <mpz_init@plt>
call   10a0 <gmp_randinit_mt@plt>
mov    %rbp,%rsi
call   1090 <gmp_randseed_ui@plt>
mov    %rbx,%rdx
call   10b0 <mpz_rrandomb@plt>
mov    %r14d,%edi
call   1070 <mpz_nextprime@plt>
call   1030 <gmp_randclear@plt>
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <mpz_clear@plt>

LLVM IR (-O0):
define void @getRandomPrime(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
%12 = call i32 (...) @rand()
%13 = load i32, i32* %6
%14 = mul nsw i32 %12, %13
%15 = sext i32 %14 to i64
store i64 %15, i64* %7
%16 = load i32, i32* %8
%17 = call i32 @mpz_init(i32 %16)
%18 = load i32, i32* %9
%19 = call i32 @gmp_randinit_mt(i32 %18)
%20 = load i32, i32* %9
%21 = load i64, i64* %7
%22 = call i32 @gmp_randseed_ui(i32 %20, i64 %21)
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = load i64, i64* %5
%26 = call i32 @mpz_rrandomb(i32 %23, i32 %24, i64 %25)
%27 = load i32, i32* %4
%28 = load i32, i32* %8
%29 = call i32 @mpz_nextprime(i32 %27, i32 %28)
%30 = load i32, i32* %9
%31 = call i32 @gmp_randclear(i32 %30)
%32 = load i32, i32* %8
%33 = call i32 @mpz_clear(i32 %32)
ret void
}

LLVM IR (-O2):
define void @getRandomPrime(i32 %0, i64 %1, i32 %2) {
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 (...) @rand()
%7 = mul nsw i32 %6, %2
%8 = sext i32 %7 to i64
%9 = tail call i32 @mpz_init(i32 undef)
%10 = tail call i32 @gmp_randinit_mt(i32 undef)
%11 = tail call i32 @gmp_randseed_ui(i32 undef, i64 %8)
%12 = tail call i32 @mpz_rrandomb(i32 undef, i32 undef, i64 %1)
%13 = tail call i32 @mpz_nextprime(i32 %0, i32 undef)
%14 = tail call i32 @gmp_randclear(i32 undef)
%15 = tail call i32 @mpz_clear(i32 undef)
ret void
}