# distutils: libraries = flint
# distutils: depends = flint/ulong_extras.h

################################################################################
# This file is auto-generated by the script
#   SAGE_ROOT/src/sage_setup/autogen/flint_autogen.py.
# From the commit 3e2c3a3e091106a25ca9c6fba28e02f2cbcd654a
# Do not modify by hand! Fix and rerun the script instead.
################################################################################

from libc.stdio cimport FILE
from sage.libs.gmp.types cimport *
from sage.libs.mpfr.types cimport *
from sage.libs.flint.types cimport *

cdef extern from "flint_wrap.h":
    ulong n_randlimb(flint_rand_t state) noexcept
    ulong n_randbits(flint_rand_t state, unsigned int bits) noexcept
    ulong n_randtest_bits(flint_rand_t state, int bits) noexcept
    ulong n_randint(flint_rand_t state, ulong limit) noexcept
    ulong n_urandint(flint_rand_t state, ulong limit) noexcept
    ulong n_randtest(flint_rand_t state) noexcept
    ulong n_randtest_not_zero(flint_rand_t state) noexcept
    ulong n_randprime(flint_rand_t state, ulong bits, int proved) noexcept
    ulong n_randtest_prime(flint_rand_t state, int proved) noexcept
    ulong n_pow(ulong n, ulong exp) noexcept
    ulong n_flog(ulong n, ulong b) noexcept
    ulong n_clog(ulong n, ulong b) noexcept
    ulong n_clog_2exp(ulong n, ulong b) noexcept
    ulong n_revbin(ulong n, ulong b) noexcept
    int n_sizeinbase(ulong n, int base) noexcept
    ulong n_preinvert_limb_prenorm(ulong n) noexcept
    ulong n_preinvert_limb(ulong n) noexcept
    double n_precompute_inverse(ulong n) noexcept
    ulong n_mod_precomp(ulong a, ulong n, double ninv) noexcept
    ulong n_mod2_precomp(ulong a, ulong n, double ninv) noexcept
    ulong n_divrem2_preinv(ulong * q, ulong a, ulong n, ulong ninv) noexcept
    ulong n_div2_preinv(ulong a, ulong n, ulong ninv) noexcept
    ulong n_mod2_preinv(ulong a, ulong n, ulong ninv) noexcept
    ulong n_divrem2_precomp(ulong * q, ulong a, ulong n, double npre) noexcept
    ulong n_ll_mod_preinv(ulong a_hi, ulong a_lo, ulong n, ulong ninv) noexcept
    ulong n_lll_mod_preinv(ulong a_hi, ulong a_mi, ulong a_lo, ulong n, ulong ninv) noexcept
    ulong n_mulmod_precomp(ulong a, ulong b, ulong n, double ninv) noexcept
    ulong n_mulmod2_preinv(ulong a, ulong b, ulong n, ulong ninv) noexcept
    ulong n_mulmod2(ulong a, ulong b, ulong n) noexcept
    ulong n_mulmod_preinv(ulong a, ulong b, ulong n, ulong ninv, ulong norm) noexcept
    ulong n_gcd(ulong x, ulong y) noexcept
    ulong n_gcdinv(ulong * a, ulong x, ulong y) noexcept
    ulong n_xgcd(ulong * a, ulong * b, ulong x, ulong y) noexcept
    int n_jacobi(mp_limb_signed_t x, ulong y) noexcept
    int n_jacobi_unsigned(ulong x, ulong y) noexcept
    ulong n_addmod(ulong a, ulong b, ulong n) noexcept
    ulong n_submod(ulong a, ulong b, ulong n) noexcept
    ulong n_invmod(ulong x, ulong y) noexcept
    ulong n_powmod_precomp(ulong a, mp_limb_signed_t exp, ulong n, double npre) noexcept
    ulong n_powmod_ui_precomp(ulong a, ulong exp, ulong n, double npre) noexcept
    ulong n_powmod(ulong a, mp_limb_signed_t exp, ulong n) noexcept
    ulong n_powmod2_preinv(ulong a, mp_limb_signed_t exp, ulong n, ulong ninv) noexcept
    ulong n_powmod2(ulong a, mp_limb_signed_t exp, ulong n) noexcept
    ulong n_powmod2_ui_preinv(ulong a, ulong exp, ulong n, ulong ninv) noexcept
    ulong n_powmod2_fmpz_preinv(ulong a, const fmpz_t exp, ulong n, ulong ninv) noexcept
    ulong n_sqrtmod(ulong a, ulong p) noexcept
    slong n_sqrtmod_2pow(ulong ** sqrt, ulong a, slong exp) noexcept
    slong n_sqrtmod_primepow(ulong ** sqrt, ulong a, ulong p, slong exp) noexcept
    slong n_sqrtmodn(ulong ** sqrt, ulong a, n_factor_t * fac) noexcept
    mp_limb_t n_mulmod_shoup(mp_limb_t w, mp_limb_t t, mp_limb_t w_precomp, mp_limb_t p) noexcept
    mp_limb_t n_mulmod_precomp_shoup(mp_limb_t w, mp_limb_t p) noexcept
    int n_divides(mp_limb_t * q, mp_limb_t n, mp_limb_t p) noexcept
    void n_primes_init(n_primes_t it) noexcept
    void n_primes_clear(n_primes_t it) noexcept
    ulong n_primes_next(n_primes_t it) noexcept
    void n_primes_jump_after(n_primes_t it, ulong n) noexcept
    void n_primes_extend_small(n_primes_t it, ulong bound) noexcept
    void n_primes_sieve_range(n_primes_t it, ulong a, ulong b) noexcept
    void n_compute_primes(ulong num_primes) noexcept
    const ulong * n_primes_arr_readonly(ulong num_primes) noexcept
    const double * n_prime_inverses_arr_readonly(ulong n) noexcept
    void n_cleanup_primes() noexcept
    ulong n_nextprime(ulong n, int proved) noexcept
    ulong n_prime_pi(ulong n) noexcept
    void n_prime_pi_bounds(ulong * lo, ulong * hi, ulong n) noexcept
    ulong n_nth_prime(ulong n) noexcept
    void n_nth_prime_bounds(ulong * lo, ulong * hi, ulong n) noexcept
    bint n_is_oddprime_small(ulong n) noexcept
    bint n_is_oddprime_binary(ulong n) noexcept
    bint n_is_prime_pocklington(ulong n, ulong iterations) noexcept
    bint n_is_prime_pseudosquare(ulong n) noexcept
    bint n_is_prime(ulong n) noexcept
    bint n_is_strong_probabprime_precomp(ulong n, double npre, ulong a, ulong d) noexcept
    bint n_is_strong_probabprime2_preinv(ulong n, ulong ninv, ulong a, ulong d) noexcept
    bint n_is_probabprime_fermat(ulong n, ulong i) noexcept
    bint n_is_probabprime_fibonacci(ulong n) noexcept
    bint n_is_probabprime_BPSW(ulong n) noexcept
    bint n_is_probabprime_lucas(ulong n) noexcept
    bint n_is_probabprime(ulong n) noexcept
    ulong n_CRT(ulong r1, ulong m1, ulong r2, ulong m2) noexcept
    ulong n_sqrt(ulong a) noexcept
    ulong n_sqrtrem(ulong * r, ulong a) noexcept
    bint n_is_square(ulong x) noexcept
    bint n_is_perfect_power235(ulong n) noexcept
    bint n_is_perfect_power(ulong * root, ulong n) noexcept
    ulong n_rootrem(ulong * remainder, ulong n, ulong root) noexcept
    ulong n_cbrt(ulong n) noexcept
    ulong n_cbrt_newton_iteration(ulong n) noexcept
    ulong n_cbrt_binary_search(ulong n) noexcept
    ulong n_cbrt_chebyshev_approx(ulong n) noexcept
    ulong n_cbrtrem(ulong * remainder, ulong n) noexcept
    void n_factor_init(n_factor_t * factors) noexcept
    int n_remove(ulong * n, ulong p) noexcept
    int n_remove2_precomp(ulong * n, ulong p, double ppre) noexcept
    void n_factor_insert(n_factor_t * factors, ulong p, ulong exp) noexcept
    ulong n_factor_trial_range(n_factor_t * factors, ulong n, ulong start, ulong num_primes) noexcept
    ulong n_factor_trial(n_factor_t * factors, ulong n, ulong num_primes) noexcept
    ulong n_factor_power235(ulong * exp, ulong n) noexcept
    ulong n_factor_one_line(ulong n, ulong iters) noexcept
    ulong n_factor_lehman(ulong n) noexcept
    ulong n_factor_SQUFOF(ulong n, ulong iters) noexcept
    void n_factor(n_factor_t * factors, ulong n, int proved) noexcept
    ulong n_factor_trial_partial(n_factor_t * factors, ulong n, ulong * prod, ulong num_primes, ulong limit) noexcept
    ulong n_factor_partial(n_factor_t * factors, ulong n, ulong limit, int proved) noexcept
    ulong n_factor_pp1(ulong n, ulong B1, ulong c) noexcept
    ulong n_factor_pp1_wrapper(ulong n) noexcept
    int n_factor_pollard_brent_single(mp_limb_t * factor, mp_limb_t n, mp_limb_t ninv, mp_limb_t ai, mp_limb_t xi, mp_limb_t normbits, mp_limb_t max_iters) noexcept
    int n_factor_pollard_brent(mp_limb_t * factor, flint_rand_t state, mp_limb_t n_in, mp_limb_t max_tries, mp_limb_t max_iters) noexcept
    int n_moebius_mu(ulong n) noexcept
    void n_moebius_mu_vec(int * mu, ulong len) noexcept
    bint n_is_squarefree(ulong n) noexcept
    ulong n_euler_phi(ulong n) noexcept
    ulong n_factorial_fast_mod2_preinv(ulong n, ulong p, ulong pinv) noexcept
    ulong n_factorial_mod2_preinv(ulong n, ulong p, ulong pinv) noexcept
    ulong n_primitive_root_prime_prefactor(ulong p, n_factor_t * factors) noexcept
    ulong n_primitive_root_prime(ulong p) noexcept
    ulong n_discrete_log_bsgs(ulong b, ulong a, ulong n) noexcept
    void n_factor_ecm_double(mp_limb_t * x, mp_limb_t * z, mp_limb_t x0, mp_limb_t z0, mp_limb_t n, n_ecm_t n_ecm_inf) noexcept
    void n_factor_ecm_add(mp_limb_t * x, mp_limb_t * z, mp_limb_t x1, mp_limb_t z1, mp_limb_t x2, mp_limb_t z2, mp_limb_t x0, mp_limb_t z0, mp_limb_t n, n_ecm_t n_ecm_inf) noexcept
    void n_factor_ecm_mul_montgomery_ladder(mp_limb_t * x, mp_limb_t * z, mp_limb_t x0, mp_limb_t z0, mp_limb_t k, mp_limb_t n, n_ecm_t n_ecm_inf) noexcept
    int n_factor_ecm_select_curve(mp_limb_t * f, mp_limb_t sigma, mp_limb_t n, n_ecm_t n_ecm_inf) noexcept
    int n_factor_ecm_stage_I(mp_limb_t * f, const mp_limb_t * prime_array, mp_limb_t num, mp_limb_t B1, mp_limb_t n, n_ecm_t n_ecm_inf) noexcept
    int n_factor_ecm_stage_II(mp_limb_t * f, mp_limb_t B1, mp_limb_t B2, mp_limb_t P, mp_limb_t n, n_ecm_t n_ecm_inf) noexcept
    int n_factor_ecm(mp_limb_t * f, mp_limb_t curves, mp_limb_t B1, mp_limb_t B2, flint_rand_t state, mp_limb_t n) noexcept
