#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*/ gen_prime(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
scalar_t__ mpz_probab_prime_p(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
void gen_safe_prime(mpz_t p, int bitlength, gmp_randstate_t r_state) {
  mpz_t q;
  mpz_init(q);
  mpz_set_ui(p, 4);
  while (mpz_probab_prime_p(p, 25) == 0) {
    gen_prime(q, bitlength - 1, r_state);
    mpz_mul_ui(p, q, 2);
    mpz_add_ui(p, p, 1);
  }
  mpz_clear(q);
}


x86 assembly (clang, -O0):
<gen_safe_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
call   1060 <mpz_set_ui@plt>
mov    -0x4(%rbp),%edi
mov    $0x19,%esi
call   1030 <mpz_probab_prime_p@plt>
cmp    $0x0,%rax
jne    11e3 <gen_safe_prime+0x73>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
mov    -0xc(%rbp),%edx
call   1080 <gen_prime@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x2,%edx
call   1090 <mpz_mul_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
jmp    1196 <gen_safe_prime+0x26>
mov    -0x10(%rbp),%edi
call   1070 <mpz_clear@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_safe_prime>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
call   1050 <mpz_init@plt>
mov    %ebx,%edi
mov    $0x4,%esi
call   1060 <mpz_set_ui@plt>
mov    %ebx,%edi
mov    $0x19,%esi
call   1030 <mpz_probab_prime_p@plt>
test   %rax,%rax
jne    11d5 <gen_safe_prime+0x65>
add    $0xffffffff,%ebp
mov    %ebp,%esi
mov    %r14d,%edx
call   1080 <gen_prime@plt>
mov    %ebx,%edi
mov    $0x2,%edx
call   1090 <mpz_mul_ui@plt>
mov    %ebx,%edi
mov    %ebx,%esi
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
mov    %ebx,%edi
mov    $0x19,%esi
call   1030 <mpz_probab_prime_p@plt>
test   %rax,%rax
je     11a0 <gen_safe_prime+0x30>
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <mpz_clear@plt>

LLVM IR (-O0):
define void @gen_safe_prime(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %7
%9 = call i32 @mpz_init(i32 %8)
%10 = load i32, i32* %4
%11 = call i32 @mpz_set_ui(i32 %10, i32 4)
br label %12
12: ; preds = %16, %3
%13 = load i32, i32* %4
%14 = call i64 @mpz_probab_prime_p(i32 %13, i32 25)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i32, i32* %7
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 1
%20 = load i32, i32* %6
%21 = call i32 @gen_prime(i32 %17, i32 %19, i32 %20)
%22 = load i32, i32* %4
%23 = load i32, i32* %7
%24 = call i32 @mpz_mul_ui(i32 %22, i32 %23, i32 2)
%25 = load i32, i32* %4
%26 = load i32, i32* %4
%27 = call i32 @mpz_add_ui(i32 %25, i32 %26, i32 1)
br label %12
28: ; preds = %12
%29 = load i32, i32* %7
%30 = call i32 @mpz_clear(i32 %29)
ret void
}

LLVM IR (-O2):
define void @gen_safe_prime(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mpz_init(i32 undef)
%5 = tail call i32 @mpz_set_ui(i32 %0, i32 4)
%6 = tail call i64 @mpz_probab_prime_p(i32 %0, i32 25)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = add nsw i32 %1, -1
br label %10
10: ; preds = %8, %10
%11 = tail call i32 @gen_prime(i32 undef, i32 %9, i32 %2)
%12 = tail call i32 @mpz_mul_ui(i32 %0, i32 undef, i32 2)
%13 = tail call i32 @mpz_add_ui(i32 %0, i32 %0, i32 1)
%14 = tail call i64 @mpz_probab_prime_p(i32 %0, i32 25)
%15 = icmp eq i64 %14, 0
br i1 %15, label %10, label %16
16: ; preds = %10, %3
%17 = tail call i32 @mpz_clear(i32 undef)
ret void
}