#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 mpz_jacobi(int /*<<< orphan*/, int /*<<< orphan*/);
int mpz_legendre(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_urandomm(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
void GetU(mpz_t u, mpz_t n, mpz_t p, mpz_t q, gmp_randstate_t r_state) {
  int jacobi_value, legendre_value_p, legendre_value_q;
  do {
    mpz_urandomm(u, r_state, n);
    jacobi_value = mpz_jacobi(u, n);
    legendre_value_p = mpz_legendre(u, p);
    legendre_value_q = mpz_legendre(u, q);
  } while (jacobi_value != 1 || legendre_value_p != -1 ||
           legendre_value_q != -1);
}


x86 assembly (clang, -O0):
<GetU>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1050 <mpz_urandomm@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <mpz_jacobi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <mpz_legendre@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <mpz_legendre@plt>
mov    %eax,-0x20(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x18(%rbp)
mov    %al,-0x21(%rbp)
jne    11a8 <GetU+0x78>
mov    $0x1,%al
cmpl   $0xffffffff,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
jne    11a8 <GetU+0x78>
cmpl   $0xffffffff,-0x20(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1148 <GetU+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetU>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,0x4(%rsp)
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%r13d
mov    %edi,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    0x4(%rsp),%esi
mov    %r13d,%edx
call   1050 <mpz_urandomm@plt>
mov    %ebx,%edi
mov    %r13d,%esi
call   1040 <mpz_jacobi@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %r12d,%esi
call   1030 <mpz_legendre@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r15d,%esi
call   1030 <mpz_legendre@plt>
cmp    $0x1,%r14d
jne    1150 <GetU+0x20>
cmp    $0xffffffff,%ebp
jne    1150 <GetU+0x20>
cmp    $0xffffffff,%eax
jne    1150 <GetU+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @GetU(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
br label %14
14: ; preds = %37, %5
%15 = load i32, i32* %6
%16 = load i32, i32* %10
%17 = load i32, i32* %7
%18 = call i32 @mpz_urandomm(i32 %15, i32 %16, i32 %17)
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = call i32 @mpz_jacobi(i32 %19, i32 %20)
store i32 %21, i32* %11
%22 = load i32, i32* %6
%23 = load i32, i32* %8
%24 = call i32 @mpz_legendre(i32 %22, i32 %23)
store i32 %24, i32* %12
%25 = load i32, i32* %6
%26 = load i32, i32* %9
%27 = call i32 @mpz_legendre(i32 %25, i32 %26)
store i32 %27, i32* %13
br label %28
28: ; preds = %14
%29 = load i32, i32* %11
%30 = icmp ne i32 %29, 1
br i1 %30, label %37, label %31
31: ; preds = %28
%32 = load i32, i32* %12
%33 = icmp ne i32 %32, -1
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %13
%36 = icmp ne i32 %35, -1
br label %37
37: ; preds = %34, %31, %28
%38 = phi i1 [ true, %31 ], [ true, %28 ], [ %36, %34 ]
br i1 %38, label %14, label %39
39: ; preds = %37
ret void
}

LLVM IR (-O2):
define void @GetU(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
br label %6
6: ; preds = %6, %5
%7 = tail call i32 @mpz_urandomm(i32 %0, i32 %4, i32 %1)
%8 = tail call i32 @mpz_jacobi(i32 %0, i32 %1)
%9 = tail call i32 @mpz_legendre(i32 %0, i32 %2)
%10 = tail call i32 @mpz_legendre(i32 %0, i32 %3)
%11 = icmp ne i32 %8, 1
%12 = icmp ne i32 %9, -1
%13 = select i1 %11, i1 true, i1 %12
%14 = icmp ne i32 %10, -1
%15 = select i1 %13, i1 true, i1 %14
br i1 %15, label %6, label %16
16: ; preds = %6
ret void
}