#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*/ gmp_randclear(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randinit_default(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_divexact(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int /*<<< orphan*/ mpz_divexact_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mod(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mod_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
unsigned long mpz_scan1(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_ui_pow_ui(int /*<<< orphan*/, int, unsigned long);
int /*<<< orphan*/ mpz_urandomm(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int /*<<< orphan*/ number_theory_exp_modp(int /*<<< orphan*/,
                                          int /*<<< orphan*/,
                                          int /*<<< orphan*/,
                                          int /*<<< orphan*/);
int /*<<< orphan*/ number_theory_exp_modp_ui(int /*<<< orphan*/,
                                             int /*<<< orphan*/, int,
                                             int /*<<< orphan*/);
int /*<<< orphan*/ number_theory_inverse(int /*<<< orphan*/, int /*<<< orphan*/,
                                         int /*<<< orphan*/);
int number_theory_legendre(int /*<<< orphan*/, int /*<<< orphan*/);
void number_theory_squareroot_modp(mpz_t R, mpz_t a, mpz_t P) {
  int legendre = number_theory_legendre(a, P);
  mpz_t t1;
  mpz_init(t1);
  mpz_t t2;
  mpz_init(t2);
  mpz_t t3;
  mpz_init(t3);
  mpz_t t4;
  mpz_init(t4);
  mpz_t t5;
  mpz_init(t5);
  if (legendre == -1) {
    mpz_set_ui(R, 0);
  } else {
    mpz_mod_ui(t1, P, 4);
    if (mpz_cmp_ui(t1, 3) == 0) {
      mpz_add_ui(t1, P, 1);
      mpz_divexact_ui(t3, t1, 4);
      number_theory_exp_modp(R, a, t3, P);
    } else {
      mpz_mod_ui(t1, P, 8);
      if (mpz_cmp_ui(t1, 5) == 0) {
        mpz_t d;
        mpz_init(d);
        mpz_sub_ui(t1, P, 1);
        mpz_divexact_ui(t3, t1, 4);
        number_theory_exp_modp(d, a, t3, P);
        if (mpz_cmp_ui(d, 1) == 0) {
          mpz_add_ui(t1, P, 3);
          mpz_divexact_ui(t3, t1, 8);
          number_theory_exp_modp(R, a, t3, P);
        } else {
          mpz_sub_ui(t1, P, 1);
          if (mpz_cmp(d, t1) == 0) {
            mpz_mul_ui(t1, a, 4);
            mpz_mod(t4, t1, P);
            mpz_sub_ui(t1, P, 5);
            mpz_divexact_ui(t3, t1, 8);
            number_theory_exp_modp(t1, t4, t3, P);
            mpz_mul_ui(t2, a, 2);
            mpz_mod(t3, t2, P);
            mpz_mul(t2, t1, t3);
            mpz_mod(R, t2, P);
          }
        }
        mpz_clear(d);
      } else {
        mpz_t b;
        mpz_init(b);
        gmp_randstate_t rstate;
        gmp_randinit_default(rstate);
        do
          mpz_urandomm(b, rstate, P);
        while (number_theory_legendre(b, P) != -1);
        gmp_randclear(rstate);
        mpz_sub_ui(t1, P, 1);
        unsigned long int s = mpz_scan1(t1, 0);
        mpz_ui_pow_ui(t2, 2, s);
        mpz_t t;
        mpz_init(t);
        mpz_divexact(t, t1, t2);
        mpz_t a_inv;
        mpz_init(a_inv);
        number_theory_inverse(a_inv, a, P);
        mpz_t c;
        mpz_init(c);
        mpz_t d;
        mpz_init(d);
        number_theory_exp_modp(c, b, t, P);
        mpz_add_ui(t1, t, 1);
        mpz_divexact_ui(t2, t1, 2);
        number_theory_exp_modp(R, a, t2, P);
        unsigned long int i;
        for (i = 1; i < s; i++) {
          number_theory_exp_modp_ui(t1, R, 2, P);
          mpz_mul(t2, t1, a_inv);
          mpz_mod(t5, t2, P);
          mpz_set_ui(t1, s - i - 1);
          mpz_set_ui(t2, 2);
          number_theory_exp_modp(t3, t2, t1, P);
          number_theory_exp_modp(d, t5, t3, P);
          mpz_sub_ui(t1, P, 1);
          if (mpz_cmp(d, t1) == 0) {
            mpz_mul(t1, R, c);
            mpz_mod(R, t1, P);
          }
          number_theory_exp_modp_ui(t1, c, 2, P);
          mpz_set(c, t1);
        }
        mpz_clear(b);
        mpz_clear(t);
        mpz_clear(a_inv);
        mpz_clear(c);
        mpz_clear(d);
      }
    }
  }
  mpz_clear(t1);
  mpz_clear(t2);
  mpz_clear(t3);
  mpz_clear(t4);
  mpz_clear(t5);
}


x86 assembly (clang, -O0):
<number_theory_squareroot_modp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1080 <number_theory_legendre@plt>
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x18(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x20(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x24(%rbp),%edi
call   10b0 <mpz_init@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    12d0 <number_theory_squareroot_modp+0x60>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1120 <mpz_set_ui@plt>
jmp    16ad <number_theory_squareroot_modp+0x43d>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x4,%edx
call   1090 <mpz_mod_ui@plt>
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
call   10e0 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    132d <number_theory_squareroot_modp+0xbd>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   1070 <mpz_add_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x4,%edx
call   1050 <mpz_divexact_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1100 <number_theory_exp_modp@plt>
jmp    16a8 <number_theory_squareroot_modp+0x438>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x8,%edx
call   1090 <mpz_mod_ui@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10e0 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    149a <number_theory_squareroot_modp+0x22a>
mov    -0x28(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   10d0 <mpz_sub_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x4,%edx
call   1050 <mpz_divexact_ui@plt>
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1100 <number_theory_exp_modp@plt>
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   10e0 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    13da <number_theory_squareroot_modp+0x16a>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x3,%edx
call   1070 <mpz_add_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x8,%edx
call   1050 <mpz_divexact_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1100 <number_theory_exp_modp@plt>
jmp    148d <number_theory_squareroot_modp+0x21d>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   10d0 <mpz_sub_ui@plt>
mov    -0x28(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1110 <mpz_cmp@plt>
cmp    $0x0,%rax
jne    1488 <number_theory_squareroot_modp+0x218>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x4,%edx
call   1160 <mpz_mul_ui@plt>
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1130 <mpz_mod@plt>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x5,%edx
call   10d0 <mpz_sub_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x8,%edx
call   1050 <mpz_divexact_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1100 <number_theory_exp_modp@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x2,%edx
call   1160 <mpz_mul_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1130 <mpz_mod@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   10c0 <mpz_mul@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1130 <mpz_mod@plt>
jmp    148d <number_theory_squareroot_modp+0x21d>
mov    -0x28(%rbp),%edi
call   1140 <mpz_clear@plt>
jmp    16a3 <number_theory_squareroot_modp+0x433>
mov    -0x2c(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x30(%rbp),%edi
call   1170 <gmp_randinit_default@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1190 <mpz_urandomm@plt>
mov    -0x2c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1080 <number_theory_legendre@plt>
cmp    $0xffffffff,%eax
jne    14aa <number_theory_squareroot_modp+0x23a>
mov    -0x30(%rbp),%edi
call   1040 <gmp_randclear@plt>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   10d0 <mpz_sub_ui@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1150 <mpz_scan1@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    $0x2,%esi
call   1180 <mpz_ui_pow_ui@plt>
mov    -0x3c(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x3c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   10f0 <mpz_divexact@plt>
mov    -0x40(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x40(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <number_theory_inverse@plt>
mov    -0x44(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x48(%rbp),%edi
call   10b0 <mpz_init@plt>
mov    -0x44(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1100 <number_theory_exp_modp@plt>
mov    -0x14(%rbp),%edi
mov    -0x3c(%rbp),%esi
mov    $0x1,%edx
call   1070 <mpz_add_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   1050 <mpz_divexact_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1100 <number_theory_exp_modp@plt>
movq   $0x1,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    167b <number_theory_squareroot_modp+0x40b>
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%ecx
mov    $0x2,%edx
call   10a0 <number_theory_exp_modp_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%edx
call   10c0 <mpz_mul@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1130 <mpz_mod@plt>
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rax
sub    -0x50(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%esi
call   1120 <mpz_set_ui@plt>
mov    -0x18(%rbp),%edi
mov    $0x2,%esi
call   1120 <mpz_set_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1100 <number_theory_exp_modp@plt>
mov    -0x48(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1100 <number_theory_exp_modp@plt>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   10d0 <mpz_sub_ui@plt>
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1110 <mpz_cmp@plt>
cmp    $0x0,%rax
jne    164c <number_theory_squareroot_modp+0x3dc>
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x44(%rbp),%edx
call   10c0 <mpz_mul@plt>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1130 <mpz_mod@plt>
mov    -0x14(%rbp),%edi
mov    -0x44(%rbp),%esi
mov    -0xc(%rbp),%ecx
mov    $0x2,%edx
call   10a0 <number_theory_exp_modp_ui@plt>
mov    -0x44(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1060 <mpz_set@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1589 <number_theory_squareroot_modp+0x319>
mov    -0x2c(%rbp),%edi
call   1140 <mpz_clear@plt>
mov    -0x3c(%rbp),%edi
call   1140 <mpz_clear@plt>
mov    -0x40(%rbp),%edi
call   1140 <mpz_clear@plt>
mov    -0x44(%rbp),%edi
call   1140 <mpz_clear@plt>
mov    -0x48(%rbp),%edi
call   1140 <mpz_clear@plt>
jmp    16a8 <number_theory_squareroot_modp+0x438>
jmp    16ad <number_theory_squareroot_modp+0x43d>
mov    -0x14(%rbp),%edi
call   1140 <mpz_clear@plt>
mov    -0x18(%rbp),%edi
call   1140 <mpz_clear@plt>
mov    -0x1c(%rbp),%edi
call   1140 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   1140 <mpz_clear@plt>
mov    -0x24(%rbp),%edi
call   1140 <mpz_clear@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number_theory_squareroot_modp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%r15d
mov    %esi,%edi
mov    %edx,%esi
call   1080 <number_theory_legendre@plt>
mov    %eax,%ebp
call   10b0 <mpz_init@plt>
call   10b0 <mpz_init@plt>
call   10b0 <mpz_init@plt>
call   10b0 <mpz_init@plt>
call   10b0 <mpz_init@plt>
cmp    $0xffffffff,%ebp
je     1430 <number_theory_squareroot_modp+0x1c0>
mov    %ebx,%esi
mov    $0x4,%edx
call   1090 <mpz_mod_ui@plt>
mov    $0x3,%esi
call   10e0 <mpz_cmp_ui@plt>
mov    %ebx,%esi
test   %rax,%rax
je     143c <number_theory_squareroot_modp+0x1cc>
mov    $0x8,%edx
call   1090 <mpz_mod_ui@plt>
mov    $0x5,%esi
call   10e0 <mpz_cmp_ui@plt>
mov    %rax,%rbp
call   10b0 <mpz_init@plt>
test   %rbp,%rbp
je     1480 <number_theory_squareroot_modp+0x210>
call   1170 <gmp_randinit_default@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edx
call   1190 <mpz_urandomm@plt>
mov    %ebx,%esi
call   1080 <number_theory_legendre@plt>
cmp    $0xffffffff,%eax
jne    1300 <number_theory_squareroot_modp+0x90>
call   1040 <gmp_randclear@plt>
mov    %ebx,%esi
mov    $0x1,%edx
call   10d0 <mpz_sub_ui@plt>
xor    %esi,%esi
call   1150 <mpz_scan1@plt>
mov    %rax,%rbp
mov    $0x2,%esi
mov    %rax,%rdx
call   1180 <mpz_ui_pow_ui@plt>
call   10b0 <mpz_init@plt>
call   10f0 <mpz_divexact@plt>
call   10b0 <mpz_init@plt>
mov    %r14d,%esi
mov    %ebx,%edx
call   1030 <number_theory_inverse@plt>
call   10b0 <mpz_init@plt>
call   10b0 <mpz_init@plt>
mov    %ebx,%ecx
call   1100 <number_theory_exp_modp@plt>
mov    $0x1,%edx
call   1070 <mpz_add_ui@plt>
mov    $0x2,%edx
call   1050 <mpz_divexact_ui@plt>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %ebx,%ecx
call   1100 <number_theory_exp_modp@plt>
cmp    $0x2,%rbp
jae    13cb <number_theory_squareroot_modp+0x15b>
call   1140 <mpz_clear@plt>
call   1140 <mpz_clear@plt>
call   1140 <mpz_clear@plt>
call   1140 <mpz_clear@plt>
call   1140 <mpz_clear@plt>
jmp    145d <number_theory_squareroot_modp+0x1ed>
nopw   0x0(%rax,%rax,1)
mov    $0x2,%edx
mov    %ebx,%ecx
call   10a0 <number_theory_exp_modp_ui@plt>
call   1060 <mpz_set@plt>
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
je     138c <number_theory_squareroot_modp+0x11c>
mov    %r15d,%esi
mov    $0x2,%edx
mov    %ebx,%ecx
call   10a0 <number_theory_exp_modp_ui@plt>
call   10c0 <mpz_mul@plt>
mov    %ebx,%edx
call   1130 <mpz_mod@plt>
lea    -0x2(%rbp),%esi
call   1120 <mpz_set_ui@plt>
mov    $0x2,%esi
call   1120 <mpz_set_ui@plt>
mov    %ebx,%ecx
call   1100 <number_theory_exp_modp@plt>
mov    %ebx,%ecx
call   1100 <number_theory_exp_modp@plt>
mov    %ebx,%esi
mov    $0x1,%edx
call   10d0 <mpz_sub_ui@plt>
call   1110 <mpz_cmp@plt>
test   %rax,%rax
jne    13b0 <number_theory_squareroot_modp+0x140>
mov    %r15d,%esi
call   10c0 <mpz_mul@plt>
mov    %r15d,%edi
mov    %ebx,%edx
call   1130 <mpz_mod@plt>
jmp    13b0 <number_theory_squareroot_modp+0x140>
mov    %r15d,%edi
xor    %esi,%esi
call   1120 <mpz_set_ui@plt>
jmp    145d <number_theory_squareroot_modp+0x1ed>
mov    $0x1,%edx
call   1070 <mpz_add_ui@plt>
mov    $0x4,%edx
call   1050 <mpz_divexact_ui@plt>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %ebx,%ecx
call   1100 <number_theory_exp_modp@plt>
call   1140 <mpz_clear@plt>
call   1140 <mpz_clear@plt>
call   1140 <mpz_clear@plt>
call   1140 <mpz_clear@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1140 <mpz_clear@plt>
mov    %ebx,%esi
mov    $0x1,%edx
call   10d0 <mpz_sub_ui@plt>
mov    $0x4,%edx
call   1050 <mpz_divexact_ui@plt>
mov    %r14d,%esi
mov    %ebx,%ecx
call   1100 <number_theory_exp_modp@plt>
mov    $0x1,%esi
call   10e0 <mpz_cmp_ui@plt>
mov    %ebx,%esi
test   %rax,%rax
je     1522 <number_theory_squareroot_modp+0x2b2>
mov    $0x1,%edx
call   10d0 <mpz_sub_ui@plt>
call   1110 <mpz_cmp@plt>
test   %rax,%rax
jne    13a0 <number_theory_squareroot_modp+0x130>
mov    %r14d,%esi
mov    $0x4,%edx
call   1160 <mpz_mul_ui@plt>
mov    %ebx,%edx
call   1130 <mpz_mod@plt>
mov    %ebx,%esi
mov    $0x5,%edx
call   10d0 <mpz_sub_ui@plt>
mov    $0x8,%edx
call   1050 <mpz_divexact_ui@plt>
mov    %ebx,%ecx
call   1100 <number_theory_exp_modp@plt>
mov    %r14d,%esi
mov    $0x2,%edx
call   1160 <mpz_mul_ui@plt>
mov    %ebx,%edx
call   1130 <mpz_mod@plt>
call   10c0 <mpz_mul@plt>
mov    %r15d,%edi
mov    %ebx,%edx
call   1130 <mpz_mod@plt>
jmp    13a0 <number_theory_squareroot_modp+0x130>
mov    $0x3,%edx
call   1070 <mpz_add_ui@plt>
mov    $0x8,%edx
call   1050 <mpz_divexact_ui@plt>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %ebx,%ecx
call   1100 <number_theory_exp_modp@plt>
jmp    13a0 <number_theory_squareroot_modp+0x130>

LLVM IR (-O0):
define void @number_theory_squareroot_modp(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
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = call i32 @number_theory_legendre(i32 %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %8
%26 = call i32 @mpz_init(i32 %25)
%27 = load i32, i32* %9
%28 = call i32 @mpz_init(i32 %27)
%29 = load i32, i32* %10
%30 = call i32 @mpz_init(i32 %29)
%31 = load i32, i32* %11
%32 = call i32 @mpz_init(i32 %31)
%33 = load i32, i32* %12
%34 = call i32 @mpz_init(i32 %33)
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %3
%38 = load i32, i32* %4
%39 = call i32 @mpz_set_ui(i32 %38, i32 0)
br label %275
40: ; preds = %3
%41 = load i32, i32* %8
%42 = load i32, i32* %6
%43 = call i32 @mpz_mod_ui(i32 %41, i32 %42, i32 4)
%44 = load i32, i32* %8
%45 = call i64 @mpz_cmp_ui(i32 %44, i32 3)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %59
47: ; preds = %40
%48 = load i32, i32* %8
%49 = load i32, i32* %6
%50 = call i32 @mpz_add_ui(i32 %48, i32 %49, i32 1)
%51 = load i32, i32* %10
%52 = load i32, i32* %8
%53 = call i32 @mpz_divexact_ui(i32 %51, i32 %52, i32 4)
%54 = load i32, i32* %4
%55 = load i32, i32* %5
%56 = load i32, i32* %10
%57 = load i32, i32* %6
%58 = call i32 @number_theory_exp_modp(i32 %54, i32 %55, i32 %56, i32 %57)
br label %274
59: ; preds = %40
%60 = load i32, i32* %8
%61 = load i32, i32* %6
%62 = call i32 @mpz_mod_ui(i32 %60, i32 %61, i32 8)
%63 = load i32, i32* %8
%64 = call i64 @mpz_cmp_ui(i32 %63, i32 5)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %141
66: ; preds = %59
%67 = load i32, i32* %13
%68 = call i32 @mpz_init(i32 %67)
%69 = load i32, i32* %8
%70 = load i32, i32* %6
%71 = call i32 @mpz_sub_ui(i32 %69, i32 %70, i32 1)
%72 = load i32, i32* %10
%73 = load i32, i32* %8
%74 = call i32 @mpz_divexact_ui(i32 %72, i32 %73, i32 4)
%75 = load i32, i32* %13
%76 = load i32, i32* %5
%77 = load i32, i32* %10
%78 = load i32, i32* %6
%79 = call i32 @number_theory_exp_modp(i32 %75, i32 %76, i32 %77, i32 %78)
%80 = load i32, i32* %13
%81 = call i64 @mpz_cmp_ui(i32 %80, i32 1)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %95
83: ; preds = %66
%84 = load i32, i32* %8
%85 = load i32, i32* %6
%86 = call i32 @mpz_add_ui(i32 %84, i32 %85, i32 3)
%87 = load i32, i32* %10
%88 = load i32, i32* %8
%89 = call i32 @mpz_divexact_ui(i32 %87, i32 %88, i32 8)
%90 = load i32, i32* %4
%91 = load i32, i32* %5
%92 = load i32, i32* %10
%93 = load i32, i32* %6
%94 = call i32 @number_theory_exp_modp(i32 %90, i32 %91, i32 %92, i32 %93)
br label %138
95: ; preds = %66
%96 = load i32, i32* %8
%97 = load i32, i32* %6
%98 = call i32 @mpz_sub_ui(i32 %96, i32 %97, i32 1)
%99 = load i32, i32* %13
%100 = load i32, i32* %8
%101 = call i64 @mpz_cmp(i32 %99, i32 %100)
%102 = icmp eq i64 %101, 0
br i1 %102, label %103, label %137
103: ; preds = %95
%104 = load i32, i32* %8
%105 = load i32, i32* %5
%106 = call i32 @mpz_mul_ui(i32 %104, i32 %105, i32 4)
%107 = load i32, i32* %11
%108 = load i32, i32* %8
%109 = load i32, i32* %6
%110 = call i32 @mpz_mod(i32 %107, i32 %108, i32 %109)
%111 = load i32, i32* %8
%112 = load i32, i32* %6
%113 = call i32 @mpz_sub_ui(i32 %111, i32 %112, i32 5)
%114 = load i32, i32* %10
%115 = load i32, i32* %8
%116 = call i32 @mpz_divexact_ui(i32 %114, i32 %115, i32 8)
%117 = load i32, i32* %8
%118 = load i32, i32* %11
%119 = load i32, i32* %10
%120 = load i32, i32* %6
%121 = call i32 @number_theory_exp_modp(i32 %117, i32 %118, i32 %119, i32 %120)
%122 = load i32, i32* %9
%123 = load i32, i32* %5
%124 = call i32 @mpz_mul_ui(i32 %122, i32 %123, i32 2)
%125 = load i32, i32* %10
%126 = load i32, i32* %9
%127 = load i32, i32* %6
%128 = call i32 @mpz_mod(i32 %125, i32 %126, i32 %127)
%129 = load i32, i32* %9
%130 = load i32, i32* %8
%131 = load i32, i32* %10
%132 = call i32 @mpz_mul(i32 %129, i32 %130, i32 %131)
%133 = load i32, i32* %4
%134 = load i32, i32* %9
%135 = load i32, i32* %6
%136 = call i32 @mpz_mod(i32 %133, i32 %134, i32 %135)
br label %137
137: ; preds = %103, %95
br label %138
138: ; preds = %137, %83
%139 = load i32, i32* %13
%140 = call i32 @mpz_clear(i32 %139)
br label %273
141: ; preds = %59
%142 = load i32, i32* %14
%143 = call i32 @mpz_init(i32 %142)
%144 = load i32, i32* %15
%145 = call i32 @gmp_randinit_default(i32 %144)
br label %146
146: ; preds = %151, %141
%147 = load i32, i32* %14
%148 = load i32, i32* %15
%149 = load i32, i32* %6
%150 = call i32 @mpz_urandomm(i32 %147, i32 %148, i32 %149)
br label %151
151: ; preds = %146
%152 = load i32, i32* %14
%153 = load i32, i32* %6
%154 = call i32 @number_theory_legendre(i32 %152, i32 %153)
%155 = icmp ne i32 %154, -1
br i1 %155, label %146, label %156
156: ; preds = %151
%157 = load i32, i32* %15
%158 = call i32 @gmp_randclear(i32 %157)
%159 = load i32, i32* %8
%160 = load i32, i32* %6
%161 = call i32 @mpz_sub_ui(i32 %159, i32 %160, i32 1)
%162 = load i32, i32* %8
%163 = call i64 @mpz_scan1(i32 %162, i32 0)
store i64 %163, i64* %16
%164 = load i32, i32* %9
%165 = load i64, i64* %16
%166 = call i32 @mpz_ui_pow_ui(i32 %164, i32 2, i64 %165)
%167 = load i32, i32* %17
%168 = call i32 @mpz_init(i32 %167)
%169 = load i32, i32* %17
%170 = load i32, i32* %8
%171 = load i32, i32* %9
%172 = call i32 @mpz_divexact(i32 %169, i32 %170, i32 %171)
%173 = load i32, i32* %18
%174 = call i32 @mpz_init(i32 %173)
%175 = load i32, i32* %18
%176 = load i32, i32* %5
%177 = load i32, i32* %6
%178 = call i32 @number_theory_inverse(i32 %175, i32 %176, i32 %177)
%179 = load i32, i32* %19
%180 = call i32 @mpz_init(i32 %179)
%181 = load i32, i32* %20
%182 = call i32 @mpz_init(i32 %181)
%183 = load i32, i32* %19
%184 = load i32, i32* %14
%185 = load i32, i32* %17
%186 = load i32, i32* %6
%187 = call i32 @number_theory_exp_modp(i32 %183, i32 %184, i32 %185, i32 %186)
%188 = load i32, i32* %8
%189 = load i32, i32* %17
%190 = call i32 @mpz_add_ui(i32 %188, i32 %189, i32 1)
%191 = load i32, i32* %9
%192 = load i32, i32* %8
%193 = call i32 @mpz_divexact_ui(i32 %191, i32 %192, i32 2)
%194 = load i32, i32* %4
%195 = load i32, i32* %5
%196 = load i32, i32* %9
%197 = load i32, i32* %6
%198 = call i32 @number_theory_exp_modp(i32 %194, i32 %195, i32 %196, i32 %197)
store i64 1, i64* %21
br label %199
199: ; preds = %259, %156
%200 = load i64, i64* %21
%201 = load i64, i64* %16
%202 = icmp ult i64 %200, %201
br i1 %202, label %203, label %262
203: ; preds = %199
%204 = load i32, i32* %8
%205 = load i32, i32* %4
%206 = load i32, i32* %6
%207 = call i32 @number_theory_exp_modp_ui(i32 %204, i32 %205, i32 2, i32 %206)
%208 = load i32, i32* %9
%209 = load i32, i32* %8
%210 = load i32, i32* %18
%211 = call i32 @mpz_mul(i32 %208, i32 %209, i32 %210)
%212 = load i32, i32* %12
%213 = load i32, i32* %9
%214 = load i32, i32* %6
%215 = call i32 @mpz_mod(i32 %212, i32 %213, i32 %214)
%216 = load i32, i32* %8
%217 = load i64, i64* %16
%218 = load i64, i64* %21
%219 = sub i64 %217, %218
%220 = sub i64 %219, 1
%221 = trunc i64 %220 to i32
%222 = call i32 @mpz_set_ui(i32 %216, i32 %221)
%223 = load i32, i32* %9
%224 = call i32 @mpz_set_ui(i32 %223, i32 2)
%225 = load i32, i32* %10
%226 = load i32, i32* %9
%227 = load i32, i32* %8
%228 = load i32, i32* %6
%229 = call i32 @number_theory_exp_modp(i32 %225, i32 %226, i32 %227, i32 %228)
%230 = load i32, i32* %20
%231 = load i32, i32* %12
%232 = load i32, i32* %10
%233 = load i32, i32* %6
%234 = call i32 @number_theory_exp_modp(i32 %230, i32 %231, i32 %232, i32 %233)
%235 = load i32, i32* %8
%236 = load i32, i32* %6
%237 = call i32 @mpz_sub_ui(i32 %235, i32 %236, i32 1)
%238 = load i32, i32* %20
%239 = load i32, i32* %8
%240 = call i64 @mpz_cmp(i32 %238, i32 %239)
%241 = icmp eq i64 %240, 0
br i1 %241, label %242, label %251
242: ; preds = %203
%243 = load i32, i32* %8
%244 = load i32, i32* %4
%245 = load i32, i32* %19
%246 = call i32 @mpz_mul(i32 %243, i32 %244, i32 %245)
%247 = load i32, i32* %4
%248 = load i32, i32* %8
%249 = load i32, i32* %6
%250 = call i32 @mpz_mod(i32 %247, i32 %248, i32 %249)
br label %251
251: ; preds = %242, %203
%252 = load i32, i32* %8
%253 = load i32, i32* %19
%254 = load i32, i32* %6
%255 = call i32 @number_theory_exp_modp_ui(i32 %252, i32 %253, i32 2, i32 %254)
%256 = load i32, i32* %19
%257 = load i32, i32* %8
%258 = call i32 @mpz_set(i32 %256, i32 %257)
br label %259
259: ; preds = %251
%260 = load i64, i64* %21
%261 = add i64 %260, 1
store i64 %261, i64* %21
br label %199
262: ; preds = %199
%263 = load i32, i32* %14
%264 = call i32 @mpz_clear(i32 %263)
%265 = load i32, i32* %17
%266 = call i32 @mpz_clear(i32 %265)
%267 = load i32, i32* %18
%268 = call i32 @mpz_clear(i32 %267)
%269 = load i32, i32* %19
%270 = call i32 @mpz_clear(i32 %269)
%271 = load i32, i32* %20
%272 = call i32 @mpz_clear(i32 %271)
br label %273
273: ; preds = %262, %138
br label %274
274: ; preds = %273, %47
br label %275
275: ; preds = %274, %37
%276 = load i32, i32* %8
%277 = call i32 @mpz_clear(i32 %276)
%278 = load i32, i32* %9
%279 = call i32 @mpz_clear(i32 %278)
%280 = load i32, i32* %10
%281 = call i32 @mpz_clear(i32 %280)
%282 = load i32, i32* %11
%283 = call i32 @mpz_clear(i32 %282)
%284 = load i32, i32* %12
%285 = call i32 @mpz_clear(i32 %284)
ret void
}

LLVM IR (-O2):
define void @number_theory_squareroot_modp(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @number_theory_legendre(i32 %1, i32 %2)
%5 = tail call i32 @mpz_init(i32 undef)
%6 = tail call i32 @mpz_init(i32 undef)
%7 = tail call i32 @mpz_init(i32 undef)
%8 = tail call i32 @mpz_init(i32 undef)
%9 = tail call i32 @mpz_init(i32 undef)
%10 = icmp eq i32 %4, -1
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @mpz_set_ui(i32 %0, i32 0)
br label %103
13: ; preds = %3
%14 = tail call i32 @mpz_mod_ui(i32 undef, i32 %2, i32 4)
%15 = tail call i64 @mpz_cmp_ui(i32 undef, i32 3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = tail call i32 @mpz_add_ui(i32 undef, i32 %2, i32 1)
%19 = tail call i32 @mpz_divexact_ui(i32 undef, i32 undef, i32 4)
%20 = tail call i32 @number_theory_exp_modp(i32 %0, i32 %1, i32 undef, i32 %2)
br label %103
21: ; preds = %13
%22 = tail call i32 @mpz_mod_ui(i32 undef, i32 %2, i32 8)
%23 = tail call i64 @mpz_cmp_ui(i32 undef, i32 5)
%24 = icmp eq i64 %23, 0
%25 = tail call i32 @mpz_init(i32 undef)
br i1 %24, label %26, label %52
26: ; preds = %21
%27 = tail call i32 @mpz_sub_ui(i32 undef, i32 %2, i32 1)
%28 = tail call i32 @mpz_divexact_ui(i32 undef, i32 undef, i32 4)
%29 = tail call i32 @number_theory_exp_modp(i32 undef, i32 %1, i32 undef, i32 %2)
%30 = tail call i64 @mpz_cmp_ui(i32 undef, i32 1)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = tail call i32 @mpz_add_ui(i32 undef, i32 %2, i32 3)
%34 = tail call i32 @mpz_divexact_ui(i32 undef, i32 undef, i32 8)
%35 = tail call i32 @number_theory_exp_modp(i32 %0, i32 %1, i32 undef, i32 %2)
br label %50
36: ; preds = %26
%37 = tail call i32 @mpz_sub_ui(i32 undef, i32 %2, i32 1)
%38 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %50
40: ; preds = %36
%41 = tail call i32 @mpz_mul_ui(i32 undef, i32 %1, i32 4)
%42 = tail call i32 @mpz_mod(i32 undef, i32 undef, i32 %2)
%43 = tail call i32 @mpz_sub_ui(i32 undef, i32 %2, i32 5)
%44 = tail call i32 @mpz_divexact_ui(i32 undef, i32 undef, i32 8)
%45 = tail call i32 @number_theory_exp_modp(i32 undef, i32 undef, i32 undef, i32 %2)
%46 = tail call i32 @mpz_mul_ui(i32 undef, i32 %1, i32 2)
%47 = tail call i32 @mpz_mod(i32 undef, i32 undef, i32 %2)
%48 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%49 = tail call i32 @mpz_mod(i32 %0, i32 undef, i32 %2)
br label %50
50: ; preds = %36, %40, %32
%51 = tail call i32 @mpz_clear(i32 undef)
br label %103
52: ; preds = %21
%53 = tail call i32 @gmp_randinit_default(i32 undef)
br label %54
54: ; preds = %54, %52
%55 = tail call i32 @mpz_urandomm(i32 undef, i32 undef, i32 %2)
%56 = tail call i32 @number_theory_legendre(i32 undef, i32 %2)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %54
58: ; preds = %54
%59 = tail call i32 @gmp_randclear(i32 undef)
%60 = tail call i32 @mpz_sub_ui(i32 undef, i32 %2, i32 1)
%61 = tail call i64 @mpz_scan1(i32 undef, i32 0)
%62 = tail call i32 @mpz_ui_pow_ui(i32 undef, i32 2, i64 %61)
%63 = tail call i32 @mpz_init(i32 undef)
%64 = tail call i32 @mpz_divexact(i32 undef, i32 undef, i32 undef)
%65 = tail call i32 @mpz_init(i32 undef)
%66 = tail call i32 @number_theory_inverse(i32 undef, i32 %1, i32 %2)
%67 = tail call i32 @mpz_init(i32 undef)
%68 = tail call i32 @mpz_init(i32 undef)
%69 = tail call i32 @number_theory_exp_modp(i32 undef, i32 undef, i32 undef, i32 %2)
%70 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 1)
%71 = tail call i32 @mpz_divexact_ui(i32 undef, i32 undef, i32 2)
%72 = tail call i32 @number_theory_exp_modp(i32 %0, i32 %1, i32 undef, i32 %2)
%73 = icmp ugt i64 %61, 1
br i1 %73, label %74, label %97
74: ; preds = %58, %92
%75 = phi i64 [ %95, %92 ], [ 1, %58 ]
%76 = tail call i32 @number_theory_exp_modp_ui(i32 undef, i32 %0, i32 2, i32 %2)
%77 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%78 = tail call i32 @mpz_mod(i32 undef, i32 undef, i32 %2)
%79 = xor i64 %75, -1
%80 = add i64 %61, %79
%81 = trunc i64 %80 to i32
%82 = tail call i32 @mpz_set_ui(i32 undef, i32 %81)
%83 = tail call i32 @mpz_set_ui(i32 undef, i32 2)
%84 = tail call i32 @number_theory_exp_modp(i32 undef, i32 undef, i32 undef, i32 %2)
%85 = tail call i32 @number_theory_exp_modp(i32 undef, i32 undef, i32 undef, i32 %2)
%86 = tail call i32 @mpz_sub_ui(i32 undef, i32 %2, i32 1)
%87 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %74
%90 = tail call i32 @mpz_mul(i32 undef, i32 %0, i32 undef)
%91 = tail call i32 @mpz_mod(i32 %0, i32 undef, i32 %2)
br label %92
92: ; preds = %89, %74
%93 = tail call i32 @number_theory_exp_modp_ui(i32 undef, i32 undef, i32 2, i32 %2)
%94 = tail call i32 @mpz_set(i32 undef, i32 undef)
%95 = add nuw i64 %75, 1
%96 = icmp eq i64 %95, %61
br i1 %96, label %97, label %74
97: ; preds = %92, %58
%98 = tail call i32 @mpz_clear(i32 undef)
%99 = tail call i32 @mpz_clear(i32 undef)
%100 = tail call i32 @mpz_clear(i32 undef)
%101 = tail call i32 @mpz_clear(i32 undef)
%102 = tail call i32 @mpz_clear(i32 undef)
br label %103
103: ; preds = %17, %97, %50, %11
%104 = tail call i32 @mpz_clear(i32 undef)
%105 = tail call i32 @mpz_clear(i32 undef)
%106 = tail call i32 @mpz_clear(i32 undef)
%107 = tail call i32 @mpz_clear(i32 undef)
%108 = tail call i32 @mpz_clear(i32 undef)
ret void
}