#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_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_cdiv_q_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clears(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/ *);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_powm(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_powm_ui(int /*<<< orphan*/, int /*<<< orphan*/, int,
                               int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_urandomm(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
void gen_generator(mpz_t g, mpz_t p, gmp_randstate_t r_state) {
  int done = 0;
  mpz_t temp;
  mpz_init(temp);
  mpz_t q;
  mpz_init_set(q, p);
  mpz_t max;
  mpz_init(max);
  mpz_sub_ui(max, p, 2);
  mpz_sub_ui(q, q, 1);
  mpz_cdiv_q_ui(q, q, 2);
  while (!done) {
    mpz_urandomm(g, r_state, max);
    mpz_add_ui(g, g, 2);
    mpz_powm_ui(temp, g, 1, p);
    if (mpz_cmp_ui(temp, 1) == 0) {
      done = 0;
      continue;
    } else {
      done = 1;
    }
    mpz_powm_ui(temp, g, 2, p);
    if (mpz_cmp_ui(temp, 1) == 0) {
      done = 0;
      continue;
    } else {
      done = 1;
    }
    mpz_powm(temp, g, q, p);
    if (mpz_cmp_ui(temp, 1) == 0) {
      done = 0;
      continue;
    } else {
      done = 1;
    }
  }
  mpz_clears(temp, q, NULL);
}


x86 assembly (clang, -O0):
<gen_generator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10b0 <mpz_init_set@plt>
mov    -0x1c(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x2,%edx
call   1070 <mpz_sub_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1070 <mpz_sub_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x2,%edx
call   1090 <mpz_cdiv_q_ui@plt>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1219 <gen_generator+0x79>
jmp    12f1 <gen_generator+0x151>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   10c0 <mpz_urandomm@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x2,%edx
call   1040 <mpz_add_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
call   10a0 <mpz_powm_ui@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1080 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    126d <gen_generator+0xcd>
movl   $0x0,-0x10(%rbp)
jmp    1203 <gen_generator+0x63>
movl   $0x1,-0x10(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%ecx
mov    $0x2,%edx
call   10a0 <mpz_powm_ui@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1080 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    12aa <gen_generator+0x10a>
movl   $0x0,-0x10(%rbp)
jmp    1203 <gen_generator+0x63>
movl   $0x1,-0x10(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%ecx
call   1030 <mpz_powm@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1080 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    12e5 <gen_generator+0x145>
movl   $0x0,-0x10(%rbp)
jmp    1203 <gen_generator+0x63>
movl   $0x1,-0x10(%rbp)
jmp    1203 <gen_generator+0x63>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <mpz_clears@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_generator>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
call   1060 <mpz_init@plt>
mov    %ebp,%esi
call   10b0 <mpz_init_set@plt>
call   1060 <mpz_init@plt>
mov    %ebp,%esi
mov    $0x2,%edx
call   1070 <mpz_sub_ui@plt>
mov    $0x1,%edx
call   1070 <mpz_sub_ui@plt>
mov    $0x2,%edx
call   1090 <mpz_cdiv_q_ui@plt>
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14d,%esi
call   10c0 <mpz_urandomm@plt>
mov    %ebx,%edi
mov    %ebx,%esi
mov    $0x2,%edx
call   1040 <mpz_add_ui@plt>
mov    %ebx,%esi
mov    $0x1,%edx
mov    %ebp,%ecx
call   10a0 <mpz_powm_ui@plt>
mov    $0x1,%esi
call   1080 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11e0 <gen_generator+0x40>
mov    %ebx,%esi
mov    $0x2,%edx
mov    %ebp,%ecx
call   10a0 <mpz_powm_ui@plt>
mov    $0x1,%esi
call   1080 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11e0 <gen_generator+0x40>
mov    %ebx,%esi
mov    %ebp,%ecx
call   1030 <mpz_powm@plt>
mov    $0x1,%esi
call   1080 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11e0 <gen_generator+0x40>
xor    %edx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <mpz_clears@plt>

LLVM IR (-O0):
define void @gen_generator(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %8
%12 = call i32 @mpz_init(i32 %11)
%13 = load i32, i32* %9
%14 = load i32, i32* %5
%15 = call i32 @mpz_init_set(i32 %13, i32 %14)
%16 = load i32, i32* %10
%17 = call i32 @mpz_init(i32 %16)
%18 = load i32, i32* %10
%19 = load i32, i32* %5
%20 = call i32 @mpz_sub_ui(i32 %18, i32 %19, i32 2)
%21 = load i32, i32* %9
%22 = load i32, i32* %9
%23 = call i32 @mpz_sub_ui(i32 %21, i32 %22, i32 1)
%24 = load i32, i32* %9
%25 = load i32, i32* %9
%26 = call i32 @mpz_cdiv_q_ui(i32 %24, i32 %25, i32 2)
br label %27
27: ; preds = %69, %67, %56, %46, %3
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %70
31: ; preds = %27
%32 = load i32, i32* %4
%33 = load i32, i32* %6
%34 = load i32, i32* %10
%35 = call i32 @mpz_urandomm(i32 %32, i32 %33, i32 %34)
%36 = load i32, i32* %4
%37 = load i32, i32* %4
%38 = call i32 @mpz_add_ui(i32 %36, i32 %37, i32 2)
%39 = load i32, i32* %8
%40 = load i32, i32* %4
%41 = load i32, i32* %5
%42 = call i32 @mpz_powm_ui(i32 %39, i32 %40, i32 1, i32 %41)
%43 = load i32, i32* %8
%44 = call i64 @mpz_cmp_ui(i32 %43, i32 1)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %31
store i32 0, i32* %7
br label %27
47: ; preds = %31
store i32 1, i32* %7
br label %48
48: ; preds = %47
%49 = load i32, i32* %8
%50 = load i32, i32* %4
%51 = load i32, i32* %5
%52 = call i32 @mpz_powm_ui(i32 %49, i32 %50, i32 2, i32 %51)
%53 = load i32, i32* %8
%54 = call i64 @mpz_cmp_ui(i32 %53, i32 1)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %48
store i32 0, i32* %7
br label %27
57: ; preds = %48
store i32 1, i32* %7
br label %58
58: ; preds = %57
%59 = load i32, i32* %8
%60 = load i32, i32* %4
%61 = load i32, i32* %9
%62 = load i32, i32* %5
%63 = call i32 @mpz_powm(i32 %59, i32 %60, i32 %61, i32 %62)
%64 = load i32, i32* %8
%65 = call i64 @mpz_cmp_ui(i32 %64, i32 1)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %58
store i32 0, i32* %7
br label %27
68: ; preds = %58
store i32 1, i32* %7
br label %69
69: ; preds = %68
br label %27
70: ; preds = %27
%71 = load i32, i32* %8
%72 = load i32, i32* %9
%73 = call i32 @mpz_clears(i32 %71, i32 %72, i32* null)
ret void
}

LLVM IR (-O2):
define void @gen_generator(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mpz_init(i32 undef)
%5 = tail call i32 @mpz_init_set(i32 undef, i32 %1)
%6 = tail call i32 @mpz_init(i32 undef)
%7 = tail call i32 @mpz_sub_ui(i32 undef, i32 %1, i32 2)
%8 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 1)
%9 = tail call i32 @mpz_cdiv_q_ui(i32 undef, i32 undef, i32 2)
br label %10
10: ; preds = %16, %3
%11 = tail call i32 @mpz_urandomm(i32 %0, i32 %2, i32 undef)
%12 = tail call i32 @mpz_add_ui(i32 %0, i32 %0, i32 2)
%13 = tail call i32 @mpz_powm_ui(i32 undef, i32 %0, i32 1, i32 %1)
%14 = tail call i64 @mpz_cmp_ui(i32 undef, i32 1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10, %17, %21
br label %10
17: ; preds = %10
%18 = tail call i32 @mpz_powm_ui(i32 undef, i32 %0, i32 2, i32 %1)
%19 = tail call i64 @mpz_cmp_ui(i32 undef, i32 1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %16, label %21
21: ; preds = %17
%22 = tail call i32 @mpz_powm(i32 undef, i32 %0, i32 undef, i32 %1)
%23 = tail call i64 @mpz_cmp_ui(i32 undef, i32 1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %16, label %25
25: ; preds = %21
%26 = tail call i32 @mpz_clears(i32 undef, i32 undef, i32* null)
ret void
}