#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_urandomb(int /*<<< orphan*/, int /*<<< orphan*/, int);
scalar_t__ time(int /*<<< orphan*/ *);
int get_prime(char **r, int bit_size) {
  mpz_t alea;
  gmp_randstate_t init;
  mpz_init(alea);
  gmp_randinit_default(init);
  int res = 1;
  long seed;
  seed = (long)time(NULL);
  while (res == 1) {
    seed++;
    gmp_randseed_ui(init, seed);
    mpz_urandomb(alea, init, bit_size);
    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_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x14(%rbp),%edi
call   10c0 <gmp_randinit_default@plt>
movl   $0x1,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    1249 <get_prime+0xa9>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   10b0 <gmp_randseed_ui@plt>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <mpz_urandomb@plt>
mov    -0x10(%rbp),%edi
mov    $0x2,%esi
call   1030 <mpz_divisible_ui_p@plt>
cmp    $0x0,%rax
je     122a <get_prime+0x8a>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
mov    -0x10(%rbp),%edi
call   10a0 <fermat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1244 <get_prime+0xa4>
jmp    1249 <get_prime+0xa9>
jmp    11d3 <get_prime+0x33>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%edx
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
mov    -0x10(%rbp),%edi
call   1090 <mpz_clear@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_prime>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1050 <mpz_init@plt>
call   10c0 <gmp_randinit_default@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %rax,%rbx
add    $0x1,%rbx
jmp    11de <get_prime+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   10a0 <fermat@plt>
add    $0x1,%rbx
cmp    $0x1,%eax
jne    1208 <get_prime+0x68>
mov    %rbx,%rsi
call   10b0 <gmp_randseed_ui@plt>
mov    %ebp,%edx
call   1070 <mpz_urandomb@plt>
mov    $0x2,%esi
call   1030 <mpz_divisible_ui_p@plt>
test   %rax,%rax
je     11d0 <get_prime+0x30>
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
jmp    11d0 <get_prime+0x30>
mov    (%r14),%rdi
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
call   1090 <mpz_clear@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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