#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 fermat(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randinit_default(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randseed_ui(int /*<<< orphan*/, long);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_divisible_ui_p(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_get_str(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ mpz_urandomm(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/ *);
int get_rand_prime(char **r, char **n) {
  mpz_t alea;
  mpz_t limit;
  gmp_randstate_t init;
  int res = 0;
  long seed;
  mpz_init(alea);
  mpz_init(limit);
  gmp_randinit_default(init);
  mpz_set_str(limit, *n, 10);
  seed = (long)time(NULL);
  while (res == 0) {
    seed++;
    gmp_randseed_ui(init, seed);
    mpz_urandomm(alea, init, limit);
    if (mpz_divisible_ui_p(alea, 2)) {
      mpz_add_ui(alea, alea, 1);
    }
    res = fermat(alea);
    if (res > 0) {
      break;
    }
  }
  mpz_get_str(*r, 10, alea);
  mpz_clear(alea);
  return 0;
}


x86 assembly (clang, -O0):
<get_rand_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x18(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x1c(%rbp),%edi
call   10c0 <gmp_randinit_default@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0xa,%edx
call   1080 <mpz_set_str@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1276 <get_rand_prime+0xc6>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   10b0 <gmp_randseed_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   10d0 <mpz_urandomm@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1030 <mpz_divisible_ui_p@plt>
cmp    $0x0,%rax
je     1257 <get_rand_prime+0xa7>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
mov    -0x14(%rbp),%edi
call   10a0 <fermat@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1271 <get_rand_prime+0xc1>
jmp    1276 <get_rand_prime+0xc6>
jmp    1200 <get_rand_prime+0x50>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%edx
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
mov    -0x14(%rbp),%edi
call   1090 <mpz_clear@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rand_prime>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <mpz_init@plt>
call   1050 <mpz_init@plt>
call   10c0 <gmp_randinit_default@plt>
mov    (%rbx),%rsi
mov    $0xa,%edx
call   1080 <mpz_set_str@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %rax,%rbx
add    $0x1,%rbx
jmp    11fd <get_rand_prime+0x4d>
cs nopw 0x0(%rax,%rax,1)
call   10a0 <fermat@plt>
add    $0x1,%rbx
test   %eax,%eax
jne    1225 <get_rand_prime+0x75>
mov    %rbx,%rsi
call   10b0 <gmp_randseed_ui@plt>
call   10d0 <mpz_urandomm@plt>
mov    $0x2,%esi
call   1030 <mpz_divisible_ui_p@plt>
test   %rax,%rax
je     11f0 <get_rand_prime+0x40>
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
jmp    11f0 <get_rand_prime+0x40>
mov    (%r14),%rdi
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
call   1090 <mpz_clear@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @get_rand_prime(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i8** %0, i8*** %3
store i8** %1, i8*** %4
store i32 0, i32* %8
%10 = load i32, i32* %5
%11 = call i32 @mpz_init(i32 %10)
%12 = load i32, i32* %6
%13 = call i32 @mpz_init(i32 %12)
%14 = load i32, i32* %7
%15 = call i32 @gmp_randinit_default(i32 %14)
%16 = load i32, i32* %6
%17 = load i8**, i8*** %4
%18 = load i8*, i8** %17
%19 = call i32 @mpz_set_str(i32 %16, i8* %18, i32 10)
%20 = call i64 @time(i32* null)
store i64 %20, i64* %9
br label %21
21: ; preds = %47, %2
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %48
24: ; preds = %21
%25 = load i64, i64* %9
%26 = add nsw i64 %25, 1
store i64 %26, i64* %9
%27 = load i32, i32* %7
%28 = load i64, i64* %9
%29 = call i32 @gmp_randseed_ui(i32 %27, i64 %28)
%30 = load i32, i32* %5
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = call i32 @mpz_urandomm(i32 %30, i32 %31, i32 %32)
%34 = load i32, i32* %5
%35 = call i64 @mpz_divisible_ui_p(i32 %34, i32 2)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %24
%38 = load i32, i32* %5
%39 = load i32, i32* %5
%40 = call i32 @mpz_add_ui(i32 %38, i32 %39, i32 1)
br label %41
41: ; preds = %37, %24
%42 = load i32, i32* %5
%43 = call i32 @fermat(i32 %42)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
br label %48
47: ; preds = %41
br label %21
48: ; preds = %46, %21
%49 = load i8**, i8*** %3
%50 = load i8*, i8** %49
%51 = load i32, i32* %5
%52 = call i32 @mpz_get_str(i8* %50, i32 10, i32 %51)
%53 = load i32, i32* %5
%54 = call i32 @mpz_clear(i32 %53)
ret i32 0
}

LLVM IR (-O2):
define i32 @get_rand_prime(i8** nocapture %0, i8** nocapture %1) {
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_init(i32 undef)
%5 = tail call i32 @gmp_randinit_default(i32 undef)
%6 = load i8*, i8** %1
%7 = tail call i32 @mpz_set_str(i32 undef, i8* %6, i32 10)
%8 = tail call i64 @time(i32* null)
br label %9
9: ; preds = %2, %18
%10 = phi i64 [ %8, %2 ], [ %11, %18 ]
%11 = add nsw i64 %10, 1
%12 = tail call i32 @gmp_randseed_ui(i32 undef, i64 %11)
%13 = tail call i32 @mpz_urandomm(i32 undef, i32 undef, i32 undef)
%14 = tail call i64 @mpz_divisible_ui_p(i32 undef, i32 2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %9
%17 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 1)
br label %18
18: ; preds = %16, %9
%19 = tail call i32 @fermat(i32 undef)
%20 = icmp eq i32 %19, 0
br i1 %20, label %9, label %21
21: ; preds = %18
%22 = load i8*, i8** %0
%23 = tail call i32 @mpz_get_str(i8* %22, i32 10, i32 undef)
%24 = tail call i32 @mpz_clear(i32 undef)
ret i32 0
}