1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
/* automatically generated by rust-bindgen 0.61.0 */

pub const MP_MIN_RADIX: u32 = 2;
pub const MP_MAX_RADIX: u32 = 36;
pub type mp_sign = ::core::ffi::c_uchar;
pub type mp_size = ::core::ffi::c_uint;
pub type mp_result = ::core::ffi::c_int;
pub type mp_small = ::core::ffi::c_long;
pub type mp_usmall = ::core::ffi::c_ulong;
pub type mp_digit = u32;
pub type mp_word = u64;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct mpz_t {
    pub single: mp_digit,
    pub digits: *mut mp_digit,
    pub alloc: mp_size,
    pub used: mp_size,
    pub sign: mp_sign,
}
#[test]
fn bindgen_test_layout_mpz_t() {
    const UNINIT: ::core::mem::MaybeUninit<mpz_t> = ::core::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::core::mem::size_of::<mpz_t>(),
        32usize,
        concat!("Size of: ", stringify!(mpz_t))
    );
    assert_eq!(
        ::core::mem::align_of::<mpz_t>(),
        8usize,
        concat!("Alignment of ", stringify!(mpz_t))
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).single) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(mpz_t),
            "::",
            stringify!(single)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).digits) as usize - ptr as usize },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(mpz_t),
            "::",
            stringify!(digits)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize },
        16usize,
        concat!(
            "Offset of field: ",
            stringify!(mpz_t),
            "::",
            stringify!(alloc)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).used) as usize - ptr as usize },
        20usize,
        concat!(
            "Offset of field: ",
            stringify!(mpz_t),
            "::",
            stringify!(used)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).sign) as usize - ptr as usize },
        24usize,
        concat!(
            "Offset of field: ",
            stringify!(mpz_t),
            "::",
            stringify!(sign)
        )
    );
}
pub type mp_int = *mut mpz_t;
extern "C" {
    pub static MP_OK: mp_result;
}
extern "C" {
    pub static MP_FALSE: mp_result;
}
extern "C" {
    pub static MP_TRUE: mp_result;
}
extern "C" {
    pub static MP_MEMORY: mp_result;
}
extern "C" {
    pub static MP_RANGE: mp_result;
}
extern "C" {
    pub static MP_UNDEF: mp_result;
}
extern "C" {
    pub static MP_TRUNC: mp_result;
}
extern "C" {
    pub static MP_BADARG: mp_result;
}
extern "C" {
    pub static MP_MINERR: mp_result;
}
extern "C" {
    #[doc = " Sets the default number of digits allocated to an `mp_int` constructed by"]
    #[doc = "`mp_int_init_size()` with `prec == 0`. Allocations are rounded up to"]
    #[doc = "multiples of this value. `MP_DEFAULT_PREC` is the default value. Requires"]
    #[doc = "`ndigits > 0`."]
    pub fn mp_int_default_precision(ndigits: mp_size);
}
extern "C" {
    #[doc = " Sets the number of digits below which multiplication will use the standard"]
    #[doc = "quadratic \"schoolbook\" multiplication algorithm rather than Karatsuba-Ofman."]
    #[doc = "Requires `ndigits >= sizeof(mp_word)`."]
    pub fn mp_int_multiply_threshold(ndigits: mp_size);
}
extern "C" {
    #[doc = " A sign indicating a (strictly) negative value."]
    pub static MP_NEG: mp_sign;
}
extern "C" {
    #[doc = " A sign indicating a zero or positive value."]
    pub static MP_ZPOS: mp_sign;
}
extern "C" {
    #[doc = " Initializes `z` with 1-digit precision and sets it to zero.  This function"]
    #[doc = "cannot fail unless `z == NULL`."]
    pub fn mp_int_init(z: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Allocates a fresh zero-valued `mpz_t` on the heap, returning NULL in case"]
    #[doc = "of error. The only possible error is out-of-memory."]
    pub fn mp_int_alloc() -> mp_int;
}
extern "C" {
    #[doc = " Initializes `z` with at least `prec` digits of storage, and sets it to"]
    #[doc = "zero. If `prec` is zero, the default precision is used. In either case the"]
    #[doc = "size is rounded up to the nearest multiple of the word size."]
    pub fn mp_int_init_size(z: mp_int, prec: mp_size) -> mp_result;
}
extern "C" {
    #[doc = " Initializes `z` to be a copy of an already-initialized value in `old`. The"]
    #[doc = "new copy does not share storage with the original."]
    pub fn mp_int_init_copy(z: mp_int, old: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Initializes `z` to the specified signed `value` at default precision."]
    pub fn mp_int_init_value(z: mp_int, value: mp_small) -> mp_result;
}
extern "C" {
    #[doc = " Initializes `z` to the specified unsigned `value` at default precision."]
    pub fn mp_int_init_uvalue(z: mp_int, uvalue: mp_usmall) -> mp_result;
}
extern "C" {
    #[doc = " Sets `z` to the value of the specified signed `value`."]
    pub fn mp_int_set_value(z: mp_int, value: mp_small) -> mp_result;
}
extern "C" {
    #[doc = " Sets `z` to the value of the specified unsigned `value`."]
    pub fn mp_int_set_uvalue(z: mp_int, uvalue: mp_usmall) -> mp_result;
}
extern "C" {
    #[doc = " Releases the storage used by `z`."]
    pub fn mp_int_clear(z: mp_int);
}
extern "C" {
    #[doc = " Releases the storage used by `z` and also `z` itself."]
    #[doc = "This should only be used for `z` allocated by `mp_int_alloc()`."]
    pub fn mp_int_free(z: mp_int);
}
extern "C" {
    #[doc = " Replaces the value of `c` with a copy of the value of `a`. No new memory is"]
    #[doc = "allocated unless `a` has more significant digits than `c` has allocated."]
    pub fn mp_int_copy(a: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Swaps the values and storage between `a` and `c`."]
    pub fn mp_int_swap(a: mp_int, c: mp_int);
}
extern "C" {
    #[doc = " Sets `z` to zero. The allocated storage of `z` is not changed."]
    pub fn mp_int_zero(z: mp_int);
}
extern "C" {
    #[doc = " Sets `c` to the absolute value of `a`."]
    pub fn mp_int_abs(a: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the additive inverse (negation) of `a`."]
    pub fn mp_int_neg(a: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the sum of `a` and `b`."]
    pub fn mp_int_add(a: mp_int, b: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the sum of `a` and `value`."]
    pub fn mp_int_add_value(a: mp_int, value: mp_small, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the difference of `a` less `b`."]
    pub fn mp_int_sub(a: mp_int, b: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the difference of `a` less `value`."]
    pub fn mp_int_sub_value(a: mp_int, value: mp_small, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the product of `a` and `b`."]
    pub fn mp_int_mul(a: mp_int, b: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the product of `a` and `value`."]
    pub fn mp_int_mul_value(a: mp_int, value: mp_small, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the product of `a` and `2^p2`. Requires `p2 >= 0`."]
    pub fn mp_int_mul_pow2(a: mp_int, p2: mp_small, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the square of `a`."]
    pub fn mp_int_sqr(a: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `q` and `r` to the quotent and remainder of `a / b`. Division by"]
    #[doc = "powers of 2 is detected and handled efficiently.  The remainder is pinned"]
    #[doc = "to `0 <= r < b`."]
    #[doc = ""]
    #[doc = "Either of `q` or `r` may be NULL, but not both, and `q` and `r` may not"]
    #[doc = "point to the same value."]
    pub fn mp_int_div(a: mp_int, b: mp_int, q: mp_int, r: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `q` and `*r` to the quotent and remainder of `a / value`. Division by"]
    #[doc = "powers of 2 is detected and handled efficiently. The remainder is pinned to"]
    #[doc = "`0 <= *r < b`. Either of `q` or `r` may be NULL."]
    pub fn mp_int_div_value(a: mp_int, value: mp_small, q: mp_int, r: *mut mp_small) -> mp_result;
}
extern "C" {
    #[doc = " Sets `q` and `r` to the quotient and remainder of `a / 2^p2`. This is a"]
    #[doc = "special case for division by powers of two that is more efficient than"]
    #[doc = "using ordinary division. Note that `mp_int_div()` will automatically handle"]
    #[doc = "this case, this function is for cases where you have only the exponent."]
    pub fn mp_int_div_pow2(a: mp_int, p2: mp_small, q: mp_int, r: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the remainder of `a / m`."]
    #[doc = "The remainder is pinned to `0 <= c < m`."]
    pub fn mp_int_mod(a: mp_int, m: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the value of `a` raised to the `b` power."]
    #[doc = "It returns `MP_RANGE` if `b < 0`."]
    pub fn mp_int_expt(a: mp_int, b: mp_small, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the value of `a` raised to the `b` power."]
    #[doc = "It returns `MP_RANGE` if `b < 0`."]
    pub fn mp_int_expt_value(a: mp_small, b: mp_small, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the value of `a` raised to the `b` power."]
    #[doc = "It returns `MP_RANGE`) if `b < 0`."]
    pub fn mp_int_expt_full(a: mp_int, b: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Returns the comparator of `a` and `b`."]
    pub fn mp_int_compare(a: mp_int, b: mp_int) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Returns the comparator of the magnitudes of `a` and `b`, disregarding their"]
    #[doc = "signs. Neither `a` nor `b` is modified by the comparison."]
    pub fn mp_int_compare_unsigned(a: mp_int, b: mp_int) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Returns the comparator of `z` and zero."]
    pub fn mp_int_compare_zero(z: mp_int) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Returns the comparator of `z` and the signed value `v`."]
    pub fn mp_int_compare_value(z: mp_int, v: mp_small) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Returns the comparator of `z` and the unsigned value `uv`."]
    pub fn mp_int_compare_uvalue(z: mp_int, uv: mp_usmall) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Reports whether `a` is divisible by `v`."]
    pub fn mp_int_divisible_value(a: mp_int, v: mp_small) -> bool;
}
extern "C" {
    #[doc = " Returns `k >= 0` such that `z` is `2^k`, if such a `k` exists. If no such"]
    #[doc = "`k` exists, the function returns -1."]
    pub fn mp_int_is_pow2(z: mp_int) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Sets `c` to the value of `a` raised to the `b` power, reduced modulo `m`."]
    #[doc = "It returns `MP_RANGE` if `b < 0` or `MP_UNDEF` if `m == 0`."]
    pub fn mp_int_exptmod(a: mp_int, b: mp_int, m: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the value of `a` raised to the `value` power, modulo `m`."]
    #[doc = "It returns `MP_RANGE` if `value < 0` or `MP_UNDEF` if `m == 0`."]
    pub fn mp_int_exptmod_evalue(a: mp_int, value: mp_small, m: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the value of `value` raised to the `b` power, modulo `m`."]
    #[doc = "It returns `MP_RANGE` if `b < 0` or `MP_UNDEF` if `m == 0`."]
    pub fn mp_int_exptmod_bvalue(value: mp_small, b: mp_int, m: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the value of `a` raised to the `b` power, reduced modulo `m`,"]
    #[doc = "given a precomputed reduction constant `mu` defined for Barrett's modular"]
    #[doc = "reduction algorithm."]
    #[doc = ""]
    #[doc = "It returns `MP_RANGE` if `b < 0` or `MP_UNDEF` if `m == 0`."]
    pub fn mp_int_exptmod_known(
        a: mp_int,
        b: mp_int,
        m: mp_int,
        mu: mp_int,
        c: mp_int,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the reduction constant for Barrett reduction by modulus `m`."]
    #[doc = "Requires that `c` and `m` point to distinct locations."]
    pub fn mp_int_redux_const(m: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the multiplicative inverse of `a` modulo `m`, if it exists."]
    #[doc = "The least non-negative representative of the congruence class is computed."]
    #[doc = ""]
    #[doc = "It returns `MP_UNDEF` if the inverse does not exist, or `MP_RANGE` if `a =="]
    #[doc = "0` or `m <= 0`."]
    pub fn mp_int_invmod(a: mp_int, m: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the greatest common divisor of `a` and `b`."]
    #[doc = ""]
    #[doc = "It returns `MP_UNDEF` if the GCD is undefined, such as for example if `a`"]
    #[doc = "and `b` are both zero."]
    pub fn mp_int_gcd(a: mp_int, b: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the greatest common divisor of `a` and `b`, and sets `x` and"]
    #[doc = "`y` to values satisfying Bezout's identity `gcd(a, b) = ax + by`."]
    #[doc = ""]
    #[doc = "It returns `MP_UNDEF` if the GCD is undefined, such as for example if `a`"]
    #[doc = "and `b` are both zero."]
    pub fn mp_int_egcd(a: mp_int, b: mp_int, c: mp_int, x: mp_int, y: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the least common multiple of `a` and `b`."]
    #[doc = ""]
    #[doc = "It returns `MP_UNDEF` if the LCM is undefined, such as for example if `a`"]
    #[doc = "and `b` are both zero."]
    pub fn mp_int_lcm(a: mp_int, b: mp_int, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the greatest integer not less than the `b`th root of `a`,"]
    #[doc = "using Newton's root-finding algorithm."]
    #[doc = "It returns `MP_UNDEF` if `a < 0` and `b` is even."]
    pub fn mp_int_root(a: mp_int, b: mp_small, c: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Returns `MP_OK` if `z` is representable as `mp_small`, else `MP_RANGE`."]
    #[doc = "If `out` is not NULL, `*out` is set to the value of `z` when `MP_OK`."]
    pub fn mp_int_to_int(z: mp_int, out: *mut mp_small) -> mp_result;
}
extern "C" {
    #[doc = " Returns `MP_OK` if `z` is representable as `mp_usmall`, or `MP_RANGE`."]
    #[doc = "If `out` is not NULL, `*out` is set to the value of `z` when `MP_OK`."]
    pub fn mp_int_to_uint(z: mp_int, out: *mut mp_usmall) -> mp_result;
}
extern "C" {
    #[doc = " Converts `z` to a zero-terminated string of characters in the specified"]
    #[doc = "`radix`, writing at most `limit` characters to `str` including the"]
    #[doc = "terminating NUL value. A leading `-` is used to indicate a negative value."]
    #[doc = ""]
    #[doc = "Returns `MP_TRUNC` if `limit` was to small to write all of `z`."]
    #[doc = "Requires `MP_MIN_RADIX <= radix <= MP_MAX_RADIX`."]
    pub fn mp_int_to_string(
        z: mp_int,
        radix: mp_size,
        str_: *mut ::core::ffi::c_char,
        limit: ::core::ffi::c_int,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Reports the minimum number of characters required to represent `z` as a"]
    #[doc = "zero-terminated string in the given `radix`."]
    #[doc = "Requires `MP_MIN_RADIX <= radix <= MP_MAX_RADIX`."]
    pub fn mp_int_string_len(z: mp_int, radix: mp_size) -> mp_result;
}
extern "C" {
    #[doc = " Reads a string of ASCII digits in the specified `radix` from the zero"]
    #[doc = "terminated `str` provided into `z`. For values of `radix > 10`, the letters"]
    #[doc = "`A`..`Z` or `a`..`z` are accepted. Letters are interpreted without respect"]
    #[doc = "to case."]
    #[doc = ""]
    #[doc = "Leading whitespace is ignored, and a leading `+` or `-` is interpreted as a"]
    #[doc = "sign flag. Processing stops when a NUL or any other character out of range"]
    #[doc = "for a digit in the given radix is encountered."]
    #[doc = ""]
    #[doc = "If the whole string was consumed, `MP_OK` is returned; otherwise"]
    #[doc = "`MP_TRUNC`. is returned."]
    #[doc = ""]
    #[doc = "Requires `MP_MIN_RADIX <= radix <= MP_MAX_RADIX`."]
    pub fn mp_int_read_string(
        z: mp_int,
        radix: mp_size,
        str_: *const ::core::ffi::c_char,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Reads a string of ASCII digits in the specified `radix` from the zero"]
    #[doc = "terminated `str` provided into `z`. For values of `radix > 10`, the letters"]
    #[doc = "`A`..`Z` or `a`..`z` are accepted. Letters are interpreted without respect"]
    #[doc = "to case."]
    #[doc = ""]
    #[doc = "Leading whitespace is ignored, and a leading `+` or `-` is interpreted as a"]
    #[doc = "sign flag. Processing stops when a NUL or any other character out of range"]
    #[doc = "for a digit in the given radix is encountered."]
    #[doc = ""]
    #[doc = "If the whole string was consumed, `MP_OK` is returned; otherwise"]
    #[doc = "`MP_TRUNC`. is returned. If `end` is not NULL, `*end` is set to point to"]
    #[doc = "the first unconsumed byte of the input string (the NUL byte if the whole"]
    #[doc = "string was consumed). This emulates the behavior of the standard C"]
    #[doc = "`strtol()` function."]
    #[doc = ""]
    #[doc = "Requires `MP_MIN_RADIX <= radix <= MP_MAX_RADIX`."]
    pub fn mp_int_read_cstring(
        z: mp_int,
        radix: mp_size,
        str_: *const ::core::ffi::c_char,
        end: *mut *mut ::core::ffi::c_char,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Returns the number of significant bits in `z`."]
    pub fn mp_int_count_bits(z: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Converts `z` to 2's complement binary, writing at most `limit` bytes into"]
    #[doc = "the given `buf`.  Returns `MP_TRUNC` if the buffer limit was too small to"]
    #[doc = "contain the whole value.  If this occurs, the contents of buf will be"]
    #[doc = "effectively garbage, as the function uses the buffer as scratch space."]
    #[doc = ""]
    #[doc = "The binary representation of `z` is in base-256 with digits ordered from"]
    #[doc = "most significant to least significant (network byte ordering).  The"]
    #[doc = "high-order bit of the first byte is set for negative values, clear for"]
    #[doc = "non-negative values."]
    #[doc = ""]
    #[doc = "As a result, non-negative values will be padded with a leading zero byte if"]
    #[doc = "the high-order byte of the base-256 magnitude is set.  This extra byte is"]
    #[doc = "accounted for by the `mp_int_binary_len()` function."]
    pub fn mp_int_to_binary(
        z: mp_int,
        buf: *mut ::core::ffi::c_uchar,
        limit: ::core::ffi::c_int,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Reads a 2's complement binary value from `buf` into `z`, where `len` is the"]
    #[doc = "length of the buffer.  The contents of `buf` may be overwritten during"]
    #[doc = "processing, although they will be restored when the function returns."]
    pub fn mp_int_read_binary(
        z: mp_int,
        buf: *mut ::core::ffi::c_uchar,
        len: ::core::ffi::c_int,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Returns the number of bytes to represent `z` in 2's complement binary."]
    pub fn mp_int_binary_len(z: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Converts the magnitude of `z` to unsigned binary, writing at most `limit`"]
    #[doc = "bytes into the given `buf`.  The sign of `z` is ignored, but `z` is not"]
    #[doc = "modified.  Returns `MP_TRUNC` if the buffer limit was too small to contain"]
    #[doc = "the whole value.  If this occurs, the contents of `buf` will be effectively"]
    #[doc = "garbage, as the function uses the buffer as scratch space during"]
    #[doc = "conversion."]
    #[doc = ""]
    #[doc = "The binary representation of `z` is in base-256 with digits ordered from"]
    #[doc = "most significant to least significant (network byte ordering)."]
    pub fn mp_int_to_unsigned(
        z: mp_int,
        buf: *mut ::core::ffi::c_uchar,
        limit: ::core::ffi::c_int,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Reads an unsigned binary value from `buf` into `z`, where `len` is the"]
    #[doc = "length of the buffer. The contents of `buf` are not modified during"]
    #[doc = "processing."]
    pub fn mp_int_read_unsigned(
        z: mp_int,
        buf: *mut ::core::ffi::c_uchar,
        len: ::core::ffi::c_int,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Returns the number of bytes required to represent `z` as an unsigned binary"]
    #[doc = "value in base 256."]
    pub fn mp_int_unsigned_len(z: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Returns a pointer to a brief, human-readable, zero-terminated string"]
    #[doc = "describing `res`. The returned string is statically allocated and must not"]
    #[doc = "be freed by the caller."]
    pub fn mp_error_string(res: mp_result) -> *const ::core::ffi::c_char;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct mpq_t {
    pub num: mpz_t,
    pub den: mpz_t,
}
#[test]
fn bindgen_test_layout_mpq_t() {
    const UNINIT: ::core::mem::MaybeUninit<mpq_t> = ::core::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::core::mem::size_of::<mpq_t>(),
        64usize,
        concat!("Size of: ", stringify!(mpq_t))
    );
    assert_eq!(
        ::core::mem::align_of::<mpq_t>(),
        8usize,
        concat!("Alignment of ", stringify!(mpq_t))
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).num) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(mpq_t),
            "::",
            stringify!(num)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).den) as usize - ptr as usize },
        32usize,
        concat!(
            "Offset of field: ",
            stringify!(mpq_t),
            "::",
            stringify!(den)
        )
    );
}
pub type mp_rat = *mut mpq_t;
pub const mp_round_mode_MP_ROUND_DOWN: mp_round_mode = 0;
pub const mp_round_mode_MP_ROUND_HALF_UP: mp_round_mode = 1;
pub const mp_round_mode_MP_ROUND_UP: mp_round_mode = 2;
pub const mp_round_mode_MP_ROUND_HALF_DOWN: mp_round_mode = 3;
pub type mp_round_mode = ::core::ffi::c_uint;
extern "C" {
    #[doc = " Initializes `r` with 1-digit precision and sets it to zero. This function"]
    #[doc = "cannot fail unless `r` is NULL."]
    pub fn mp_rat_init(r: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Allocates a fresh zero-valued `mpq_t` on the heap, returning NULL in case"]
    #[doc = "of error. The only possible error is out-of-memory."]
    pub fn mp_rat_alloc() -> mp_rat;
}
extern "C" {
    #[doc = " Reduces `r` in-place to lowest terms and canonical form."]
    #[doc = ""]
    #[doc = "Zero is represented as 0/1, one as 1/1, and signs are adjusted so that the"]
    #[doc = "sign of the value is carried by the numerator."]
    pub fn mp_rat_reduce(r: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Initializes `r` with at least `n_prec` digits of storage for the numerator"]
    #[doc = "and `d_prec` digits of storage for the denominator, and value zero."]
    #[doc = ""]
    #[doc = "If either precision is zero, the default precision is used, rounded up to"]
    #[doc = "the nearest word size."]
    pub fn mp_rat_init_size(r: mp_rat, n_prec: mp_size, d_prec: mp_size) -> mp_result;
}
extern "C" {
    #[doc = " Initializes `r` to be a copy of an already-initialized value in `old`. The"]
    #[doc = "new copy does not share storage with the original."]
    pub fn mp_rat_init_copy(r: mp_rat, old: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets the value of `r` to the ratio of signed `numer` to signed `denom`.  It"]
    #[doc = "returns `MP_UNDEF` if `denom` is zero."]
    pub fn mp_rat_set_value(r: mp_rat, numer: mp_small, denom: mp_small) -> mp_result;
}
extern "C" {
    #[doc = " Sets the value of `r` to the ratio of unsigned `numer` to unsigned"]
    #[doc = "`denom`. It returns `MP_UNDEF` if `denom` is zero."]
    pub fn mp_rat_set_uvalue(r: mp_rat, numer: mp_usmall, denom: mp_usmall) -> mp_result;
}
extern "C" {
    #[doc = " Releases the storage used by `r`."]
    pub fn mp_rat_clear(r: mp_rat);
}
extern "C" {
    #[doc = " Releases the storage used by `r` and also `r` itself."]
    #[doc = "This should only be used for `r` allocated by `mp_rat_alloc()`."]
    pub fn mp_rat_free(r: mp_rat);
}
extern "C" {
    #[doc = " Sets `z` to a copy of the numerator of `r`."]
    pub fn mp_rat_numer(r: mp_rat, z: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Returns a pointer to the numerator of `r`."]
    pub fn mp_rat_numer_ref(r: mp_rat) -> mp_int;
}
extern "C" {
    #[doc = " Sets `z` to a copy of the denominator of `r`."]
    pub fn mp_rat_denom(r: mp_rat, z: mp_int) -> mp_result;
}
extern "C" {
    #[doc = " Returns a pointer to the denominator of `r`."]
    pub fn mp_rat_denom_ref(r: mp_rat) -> mp_int;
}
extern "C" {
    #[doc = " Reports the sign of `r`."]
    pub fn mp_rat_sign(r: mp_rat) -> mp_sign;
}
extern "C" {
    #[doc = " Sets `c` to a copy of the value of `a`. No new memory is allocated unless a"]
    #[doc = "term of `a` has more significant digits than the corresponding term of `c`"]
    #[doc = "has allocated."]
    pub fn mp_rat_copy(a: mp_rat, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `r` to zero. The allocated storage of `r` is not changed."]
    pub fn mp_rat_zero(r: mp_rat);
}
extern "C" {
    #[doc = " Sets `c` to the absolute value of `a`."]
    pub fn mp_rat_abs(a: mp_rat, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the absolute value of `a`."]
    pub fn mp_rat_neg(a: mp_rat, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the reciprocal of `a` if the reciprocal is defined."]
    #[doc = "It returns `MP_UNDEF` if `a` is zero."]
    pub fn mp_rat_recip(a: mp_rat, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the sum of `a` and `b`."]
    pub fn mp_rat_add(a: mp_rat, b: mp_rat, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the difference of `a` less `b`."]
    pub fn mp_rat_sub(a: mp_rat, b: mp_rat, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the product of `a` and `b`."]
    pub fn mp_rat_mul(a: mp_rat, b: mp_rat, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the ratio `a / b` if that ratio is defined."]
    #[doc = "It returns `MP_UNDEF` if `b` is zero."]
    pub fn mp_rat_div(a: mp_rat, b: mp_rat, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the sum of `a` and integer `b`."]
    pub fn mp_rat_add_int(a: mp_rat, b: mp_int, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the difference of `a` less integer `b`."]
    pub fn mp_rat_sub_int(a: mp_rat, b: mp_int, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the product of `a` and integer `b`."]
    pub fn mp_rat_mul_int(a: mp_rat, b: mp_int, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the ratio `a / b` if that ratio is defined."]
    #[doc = "It returns `MP_UNDEF` if `b` is zero."]
    pub fn mp_rat_div_int(a: mp_rat, b: mp_int, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Sets `c` to the value of `a` raised to the `b` power."]
    #[doc = "It returns `MP_RANGE` if `b < 0`."]
    pub fn mp_rat_expt(a: mp_rat, b: mp_small, c: mp_rat) -> mp_result;
}
extern "C" {
    #[doc = " Returns the comparator of `a` and `b`."]
    pub fn mp_rat_compare(a: mp_rat, b: mp_rat) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Returns the comparator of the magnitudes of `a` and `b`, disregarding their"]
    #[doc = "signs. Neither `a` nor `b` is modified by the comparison."]
    pub fn mp_rat_compare_unsigned(a: mp_rat, b: mp_rat) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Returns the comparator of `r` and zero."]
    pub fn mp_rat_compare_zero(r: mp_rat) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Returns the comparator of `r` and the signed ratio `n / d`."]
    #[doc = "It returns `MP_UNDEF` if `d` is zero."]
    pub fn mp_rat_compare_value(r: mp_rat, n: mp_small, d: mp_small) -> ::core::ffi::c_int;
}
extern "C" {
    #[doc = " Reports whether `r` is an integer, having canonical denominator 1."]
    pub fn mp_rat_is_integer(r: mp_rat) -> bool;
}
extern "C" {
    #[doc = " Reports whether the numerator and denominator of `r` can be represented as"]
    #[doc = "small signed integers, and if so stores the corresponding values to `num`"]
    #[doc = "and `den`. It returns `MP_RANGE` if either cannot be so represented."]
    pub fn mp_rat_to_ints(r: mp_rat, num: *mut mp_small, den: *mut mp_small) -> mp_result;
}
extern "C" {
    #[doc = " Converts `r` to a zero-terminated string of the format `\"n/d\"` with `n` and"]
    #[doc = "`d` in the specified radix and writing no more than `limit` bytes to the"]
    #[doc = "given output buffer `str`. The output of the numerator includes a sign flag"]
    #[doc = "if `r` is negative.  Requires `MP_MIN_RADIX <= radix <= MP_MAX_RADIX`."]
    pub fn mp_rat_to_string(
        r: mp_rat,
        radix: mp_size,
        str_: *mut ::core::ffi::c_char,
        limit: ::core::ffi::c_int,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Converts the value of `r` to a string in decimal-point notation with the"]
    #[doc = "specified radix, writing no more than `limit` bytes of data to the given"]
    #[doc = "output buffer.  It generates `prec` digits of precision, and requires"]
    #[doc = "`MP_MIN_RADIX <= radix <= MP_MAX_RADIX`."]
    #[doc = ""]
    #[doc = "Ratios usually must be rounded when they are being converted for output as"]
    #[doc = "a decimal value.  There are four rounding modes currently supported:"]
    #[doc = ""]
    #[doc = "MP_ROUND_DOWN"]
    #[doc = "Truncates the value toward zero."]
    #[doc = "Example:  12.009 to 2dp becomes 12.00"]
    #[doc = ""]
    #[doc = "MP_ROUND_UP"]
    #[doc = "Rounds the value away from zero:"]
    #[doc = "Example:  12.001 to 2dp becomes 12.01, but"]
    #[doc = "12.000 to 2dp remains 12.00"]
    #[doc = ""]
    #[doc = "MP_ROUND_HALF_DOWN"]
    #[doc = "Rounds the value to nearest digit, half goes toward zero."]
    #[doc = "Example:  12.005 to 2dp becomes 12.00, but"]
    #[doc = "12.006 to 2dp becomes 12.01"]
    #[doc = ""]
    #[doc = "MP_ROUND_HALF_UP"]
    #[doc = "Rounds the value to nearest digit, half rounds upward."]
    #[doc = "Example:  12.005 to 2dp becomes 12.01, but"]
    #[doc = "12.004 to 2dp becomes 12.00"]
    pub fn mp_rat_to_decimal(
        r: mp_rat,
        radix: mp_size,
        prec: mp_size,
        round: mp_round_mode,
        str_: *mut ::core::ffi::c_char,
        limit: ::core::ffi::c_int,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Reports the minimum number of characters required to represent `r` as a"]
    #[doc = "zero-terminated string in the given `radix`."]
    #[doc = "Requires `MP_MIN_RADIX <= radix <= MP_MAX_RADIX`."]
    pub fn mp_rat_string_len(r: mp_rat, radix: mp_size) -> mp_result;
}
extern "C" {
    #[doc = " Reports the length in bytes of the buffer needed to convert `r` using the"]
    #[doc = "`mp_rat_to_decimal()` function with the specified `radix` and `prec`. The"]
    #[doc = "buffer size estimate may slightly exceed the actual required capacity."]
    pub fn mp_rat_decimal_len(r: mp_rat, radix: mp_size, prec: mp_size) -> mp_result;
}
extern "C" {
    #[doc = " Sets `r` to the value represented by a zero-terminated string `str` in the"]
    #[doc = "format `\"n/d\"` including a sign flag. It returns `MP_UNDEF` if the encoded"]
    #[doc = "denominator has value zero."]
    pub fn mp_rat_read_string(
        r: mp_rat,
        radix: mp_size,
        str_: *const ::core::ffi::c_char,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Sets `r` to the value represented by a zero-terminated string `str` in the"]
    #[doc = "format `\"n/d\"` including a sign flag. It returns `MP_UNDEF` if the encoded"]
    #[doc = "denominator has value zero. If `end` is not NULL then `*end` is set to"]
    #[doc = "point to the first unconsumed character in the string, after parsing."]
    pub fn mp_rat_read_cstring(
        r: mp_rat,
        radix: mp_size,
        str_: *const ::core::ffi::c_char,
        end: *mut *mut ::core::ffi::c_char,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Sets `r` to the value represented by a zero-terminated string `str` having"]
    #[doc = "one of the following formats, each with an optional leading sign flag:"]
    #[doc = ""]
    #[doc = "n         : integer format, e.g. \"123\""]
    #[doc = "n/d       : ratio format, e.g., \"-12/5\""]
    #[doc = "z.ffff    : decimal format, e.g., \"1.627\""]
    #[doc = ""]
    #[doc = "It returns `MP_UNDEF` if the effective denominator is zero. If `end` is not"]
    #[doc = "NULL then `*end` is set to point to the first unconsumed character in the"]
    #[doc = "string, after parsing."]
    pub fn mp_rat_read_ustring(
        r: mp_rat,
        radix: mp_size,
        str_: *const ::core::ffi::c_char,
        end: *mut *mut ::core::ffi::c_char,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Sets `r` to the value represented by a zero-terminated string `str` in the"]
    #[doc = "format `\"z.ffff\"` including a sign flag. It returns `MP_UNDEF` if the"]
    #[doc = "effective denominator."]
    pub fn mp_rat_read_decimal(
        r: mp_rat,
        radix: mp_size,
        str_: *const ::core::ffi::c_char,
    ) -> mp_result;
}
extern "C" {
    #[doc = " Sets `r` to the value represented by a zero-terminated string `str` in the"]
    #[doc = "format `\"z.ffff\"` including a sign flag. It returns `MP_UNDEF` if the"]
    #[doc = "effective denominator. If `end` is not NULL then `*end` is set to point to"]
    #[doc = "the first unconsumed character in the string, after parsing."]
    pub fn mp_rat_read_cdecimal(
        r: mp_rat,
        radix: mp_size,
        str_: *const ::core::ffi::c_char,
        end: *mut *mut ::core::ffi::c_char,
    ) -> mp_result;
}
extern "C" {
    pub fn mp_int_is_prime(z: mp_int) -> mp_result;
}
extern "C" {
    pub fn mp_int_find_prime(z: mp_int) -> mp_result;
}