#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*/ mpf_t;

/* Variables and functions */
unsigned long ULONG_MAX;
scalar_t__ floor(double);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_mul_2exp(int /*<<< orphan*/, int /*<<< orphan*/ const,
                                int);
int /*<<< orphan*/ mpf_set_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_ui_div(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
unsigned long mpz_scan0(int /*<<< orphan*/, unsigned long);
unsigned long mpz_scan1(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ mpz_set_f(int /*<<< orphan*/, int /*<<< orphan*/);
void question_inverse(mpf_t qinv, const mpf_t x, unsigned int prec) {
  int i, istart, n;
  unsigned long idx, last_idx;
  mpf_t mantissa;
  mpz_t bits;
  mpf_init(mantissa);
  mpz_init(bits);
  int nbits = (int)floor(3.321 * prec);
  nbits -= 3;
  int *bitcnt = (int *)malloc((nbits + 1) * sizeof(int));
  memset(bitcnt, 0, (nbits + 1) * sizeof(int));
  mpf_mul_2exp(mantissa, x, nbits);
  mpz_set_f(bits, mantissa);
  idx = 0;
  last_idx = 0;
  n = 0;
  while (n <= nbits) {
    if (n % 2 == 0) {
      idx = mpz_scan0(bits, idx);
    } else {
      idx = mpz_scan1(bits, idx);
    }
    if (ULONG_MAX == idx) {
      bitcnt[n] = nbits - last_idx;
      n++;
      break;
    }
    bitcnt[n] = idx - last_idx;
    last_idx = idx;
    n++;
  }
  mpf_set_ui(qinv, 0);
  istart = 2;
  if (0 != bitcnt[0]) {
    istart = 0;
  }
  for (i = istart; i < n; i++) {
    if (n - 1 == i)
      mpf_add_ui(qinv, qinv, bitcnt[i] + 1);
    else
      mpf_add_ui(qinv, qinv, bitcnt[i]);
    mpf_ui_div(qinv, 1, qinv);
  }
  free(bitcnt);
  mpf_clear(mantissa);
  mpz_clear(bits);
}


x86 assembly (clang, -O0):
<question_inverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x2c(%rbp),%edi
call   1090 <mpf_init@plt>
mov    -0x30(%rbp),%edi
call   1080 <mpz_init@plt>
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xddf(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1110 <floor@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1040 <mpf_mul_2exp@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   10d0 <mpz_set_f@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x34(%rbp),%eax
jg     133d <question_inverse+0x14d>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12cb <question_inverse+0xdb>
mov    -0x30(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <mpz_scan0@plt>
mov    %rax,-0x20(%rbp)
jmp    12db <question_inverse+0xeb>
mov    -0x30(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1100 <mpz_scan1@plt>
mov    %rax,-0x20(%rbp)
mov    0x2cf6(%rip),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
jne    1312 <question_inverse+0x122>
movslq -0x34(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %eax,%edx
mov    -0x40(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    133d <question_inverse+0x14d>
mov    -0x20(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %eax,%edx
mov    -0x40(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1296 <question_inverse+0xa6>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   10b0 <mpf_set_ui@plt>
movl   $0x2,-0x14(%rbp)
mov    -0x40(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%eax
je     1363 <question_inverse+0x173>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13d6 <question_inverse+0x1e6>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cmp    -0x10(%rbp),%eax
jne    13a2 <question_inverse+0x1b2>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x40(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
call   10f0 <mpf_add_ui@plt>
jmp    13b8 <question_inverse+0x1c8>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x40(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   10f0 <mpf_add_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%edx
mov    $0x1,%esi
call   1050 <mpf_ui_div@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1369 <question_inverse+0x179>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%edi
call   10a0 <mpf_clear@plt>
mov    -0x30(%rbp),%edi
call   10e0 <mpz_clear@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<question_inverse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,0x4(%rsp)
mov    %edi,%r12d
call   1090 <mpf_init@plt>
call   1080 <mpz_init@plt>
mov    %ebp,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xde3(%rip),%xmm0
call   1110 <floor@plt>
mov    %rax,%r13
lea    -0x3(%rax),%ebx
shl    $0x20,%rax
movabs $0x3ffffffe00000000,%rbp
ff ff 3f
add    %rax,%rbp
shr    $0x1e,%rbp
mov    %ebp,%edi
call   10c0 <malloc@plt>
mov    %rax,%r14
xor    %r15d,%r15d
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1070 <memset@plt>
mov    0x4(%rsp),%esi
mov    %ebx,0x4(%rsp)
mov    %ebx,%edx
call   1040 <mpf_mul_2exp@plt>
call   10d0 <mpz_set_f@plt>
cmp    $0x3,%r13d
jl     12d3 <question_inverse+0xe3>
lea    -0x2(%r13),%r15d
xor    %ebx,%ebx
mov    0x2d5b(%rip),%r13
xor    %ebp,%ebp
nop
mov    %rbp,%rsi
test   $0x1,%bl
jne    12a0 <question_inverse+0xb0>
call   1060 <mpz_scan0@plt>
cmp    %rax,0x0(%r13)
jne    12ab <question_inverse+0xbb>
jmp    12c1 <question_inverse+0xd1>
cs nopw 0x0(%rax,%rax,1)
nop
call   1100 <mpz_scan1@plt>
cmp    %rax,0x0(%r13)
je     12c1 <question_inverse+0xd1>
mov    %eax,%ecx
sub    %ebp,%ecx
mov    %ecx,(%r14,%rbx,4)
add    $0x1,%rbx
mov    %rax,%rbp
cmp    %rbx,%r15
jne    1280 <question_inverse+0x90>
jmp    12d3 <question_inverse+0xe3>
mov    0x4(%rsp),%ecx
sub    %ebp,%ecx
mov    %ebx,%eax
mov    %ecx,(%r14,%rax,4)
add    $0x1,%ebx
mov    %ebx,%r15d
mov    %r12d,%edi
xor    %esi,%esi
call   10b0 <mpf_set_ui@plt>
xor    %eax,%eax
cmpl   $0x0,(%r14)
sete   %al
add    %eax,%eax
cmp    %r15d,%eax
jge    1336 <question_inverse+0x146>
lea    -0x1(%r15),%ebx
mov    %eax,%ebp
mov    %r15d,%r15d
jmp    1328 <question_inverse+0x138>
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbp,4),%edx
mov    %r12d,%edi
mov    %r12d,%esi
call   10f0 <mpf_add_ui@plt>
mov    %r12d,%edi
mov    $0x1,%esi
mov    %r12d,%edx
call   1050 <mpf_ui_div@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
je     1336 <question_inverse+0x146>
cmp    %rbp,%rbx
jne    1300 <question_inverse+0x110>
mov    (%r14,%rbx,4),%edx
add    $0x1,%edx
jmp    1304 <question_inverse+0x114>
mov    %r14,%rdi
call   1030 <free@plt>
call   10a0 <mpf_clear@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10e0 <mpz_clear@plt>

LLVM IR (-O0):
@ULONG_MAX = global i64 0
define void @question_inverse(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 i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%16 = load i32, i32* %12
%17 = call i32 @mpf_init(i32 %16)
%18 = load i32, i32* %13
%19 = call i32 @mpz_init(i32 %18)
%20 = load i32, i32* %6
%21 = uitofp i32 %20 to double
%22 = fmul double 3.321000e+00, %21
%23 = call i64 @floor(double %22)
%24 = trunc i64 %23 to i32
store i32 %24, i32* %14
%25 = load i32, i32* %14
%26 = sub nsw i32 %25, 3
store i32 %26, i32* %14
%27 = load i32, i32* %14
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 4
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to i32*
store i32* %33, i32** %15
%34 = load i32*, i32** %15
%35 = load i32, i32* %14
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 4
%39 = trunc i64 %38 to i32
%40 = call i32 @memset(i32* %34, i32 0, i32 %39)
%41 = load i32, i32* %12
%42 = load i32, i32* %5
%43 = load i32, i32* %14
%44 = call i32 @mpf_mul_2exp(i32 %41, i32 %42, i32 %43)
%45 = load i32, i32* %13
%46 = load i32, i32* %12
%47 = call i32 @mpz_set_f(i32 %45, i32 %46)
store i64 0, i64* %10
store i64 0, i64* %11
store i32 0, i32* %9
br label %48
48: ; preds = %80, %3
%49 = load i32, i32* %9
%50 = load i32, i32* %14
%51 = icmp sle i32 %49, %50
br i1 %51, label %52, label %92
52: ; preds = %48
%53 = load i32, i32* %9
%54 = srem i32 %53, 2
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = load i32, i32* %13
%58 = load i64, i64* %10
%59 = call i64 @mpz_scan0(i32 %57, i64 %58)
store i64 %59, i64* %10
br label %64
60: ; preds = %52
%61 = load i32, i32* %13
%62 = load i64, i64* %10
%63 = call i64 @mpz_scan1(i32 %61, i64 %62)
store i64 %63, i64* %10
br label %64
64: ; preds = %60, %56
%65 = load i64, i64* @ULONG_MAX
%66 = load i64, i64* %10
%67 = icmp eq i64 %65, %66
br i1 %67, label %68, label %80
68: ; preds = %64
%69 = load i32, i32* %14
%70 = sext i32 %69 to i64
%71 = load i64, i64* %11
%72 = sub i64 %70, %71
%73 = trunc i64 %72 to i32
%74 = load i32*, i32** %15
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %74, i64 %76
store i32 %73, i32* %77
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
store i32 %79, i32* %9
br label %92
80: ; preds = %64
%81 = load i64, i64* %10
%82 = load i64, i64* %11
%83 = sub i64 %81, %82
%84 = trunc i64 %83 to i32
%85 = load i32*, i32** %15
%86 = load i32, i32* %9
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %85, i64 %87
store i32 %84, i32* %88
%89 = load i64, i64* %10
store i64 %89, i64* %11
%90 = load i32, i32* %9
%91 = add nsw i32 %90, 1
store i32 %91, i32* %9
br label %48
92: ; preds = %68, %48
%93 = load i32, i32* %4
%94 = call i32 @mpf_set_ui(i32 %93, i32 0)
store i32 2, i32* %8
%95 = load i32*, i32** %15
%96 = getelementptr inbounds i32, i32* %95, i64 0
%97 = load i32, i32* %96
%98 = icmp ne i32 0, %97
br i1 %98, label %99, label %100
99: ; preds = %92
store i32 0, i32* %8
br label %100
100: ; preds = %99, %92
%101 = load i32, i32* %8
store i32 %101, i32* %7
br label %102
102: ; preds = %134, %100
%103 = load i32, i32* %7
%104 = load i32, i32* %9
%105 = icmp slt i32 %103, %104
br i1 %105, label %106, label %137
106: ; preds = %102
%107 = load i32, i32* %9
%108 = sub nsw i32 %107, 1
%109 = load i32, i32* %7
%110 = icmp eq i32 %108, %109
br i1 %110, label %111, label %121
111: ; preds = %106
%112 = load i32, i32* %4
%113 = load i32, i32* %4
%114 = load i32*, i32** %15
%115 = load i32, i32* %7
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %114, i64 %116
%118 = load i32, i32* %117
%119 = add nsw i32 %118, 1
%120 = call i32 @mpf_add_ui(i32 %112, i32 %113, i32 %119)
br label %130
121: ; preds = %106
%122 = load i32, i32* %4
%123 = load i32, i32* %4
%124 = load i32*, i32** %15
%125 = load i32, i32* %7
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i32, i32* %124, i64 %126
%128 = load i32, i32* %127
%129 = call i32 @mpf_add_ui(i32 %122, i32 %123, i32 %128)
br label %130
130: ; preds = %121, %111
%131 = load i32, i32* %4
%132 = load i32, i32* %4
%133 = call i32 @mpf_ui_div(i32 %131, i32 1, i32 %132)
br label %134
134: ; preds = %130
%135 = load i32, i32* %7
%136 = add nsw i32 %135, 1
store i32 %136, i32* %7
br label %102
137: ; preds = %102
%138 = load i32*, i32** %15
%139 = call i32 @free(i32* %138)
%140 = load i32, i32* %12
%141 = call i32 @mpf_clear(i32 %140)
%142 = load i32, i32* %13
%143 = call i32 @mpz_clear(i32 %142)
ret void
}

LLVM IR (-O2):
@ULONG_MAX = global i64 0
define void @question_inverse(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mpf_init(i32 undef)
%5 = tail call i32 @mpz_init(i32 undef)
%6 = uitofp i32 %2 to double
%7 = fmul double %6, 3.321000e+00
%8 = tail call i64 @floor(double %7)
%9 = trunc i64 %8 to i32
%10 = add nsw i32 %9, -3
%11 = shl i64 %8, 32
%12 = add i64 %11, 4611686009837453312
%13 = lshr exact i64 %12, 30
%14 = trunc i64 %13 to i32
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
%17 = tail call i32 @memset(i32* %16, i32 0, i32 %14)
%18 = tail call i32 @mpf_mul_2exp(i32 undef, i32 %1, i32 %10)
%19 = tail call i32 @mpz_set_f(i32 undef, i32 undef)
%20 = icmp slt i32 %9, 3
br i1 %20, label %50, label %21
21: ; preds = %3
%22 = add nsw i32 %9, -2
%23 = zext i32 %22 to i64
br label %24
24: ; preds = %21, %44
%25 = phi i64 [ 0, %21 ], [ %48, %44 ]
%26 = phi i64 [ 0, %21 ], [ %34, %44 ]
%27 = and i64 %25, 1
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i64 @mpz_scan0(i32 undef, i64 %26)
br label %33
31: ; preds = %24
%32 = tail call i64 @mpz_scan1(i32 undef, i64 %26)
br label %33
33: ; preds = %31, %29
%34 = phi i64 [ %30, %29 ], [ %32, %31 ]
%35 = load i64, i64* @ULONG_MAX
%36 = icmp eq i64 %35, %34
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = trunc i64 %25 to i32
%39 = trunc i64 %26 to i32
%40 = sub i32 %10, %39
%41 = and i64 %25, 4294967295
%42 = getelementptr inbounds i32, i32* %16, i64 %41
store i32 %40, i32* %42
%43 = add nuw nsw i32 %38, 1
br label %50
44: ; preds = %33
%45 = sub i64 %34, %26
%46 = trunc i64 %45 to i32
%47 = getelementptr inbounds i32, i32* %16, i64 %25
store i32 %46, i32* %47
%48 = add nuw nsw i64 %25, 1
%49 = icmp eq i64 %48, %23
br i1 %49, label %50, label %24
50: ; preds = %44, %3, %37
%51 = phi i32 [ %43, %37 ], [ 0, %3 ], [ %22, %44 ]
%52 = tail call i32 @mpf_set_ui(i32 %0, i32 0)
%53 = load i32, i32* %16
%54 = icmp eq i32 %53, 0
%55 = select i1 %54, i32 2, i32 0
%56 = icmp slt i32 %55, %51
br i1 %56, label %57, label %78
57: ; preds = %50
%58 = add nsw i32 %51, -1
%59 = zext i32 %55 to i64
%60 = zext i32 %58 to i64
%61 = zext i32 %51 to i64
%62 = getelementptr inbounds i32, i32* %16, i64 %60
br label %63
63: ; preds = %57, %72
%64 = phi i64 [ %59, %57 ], [ %76, %72 ]
%65 = icmp eq i64 %64, %60
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load i32, i32* %62
%68 = add nsw i32 %67, 1
br label %72
69: ; preds = %63
%70 = getelementptr inbounds i32, i32* %16, i64 %64
%71 = load i32, i32* %70
br label %72
72: ; preds = %69, %66
%73 = phi i32 [ %71, %69 ], [ %68, %66 ]
%74 = tail call i32 @mpf_add_ui(i32 %0, i32 %0, i32 %73)
%75 = tail call i32 @mpf_ui_div(i32 %0, i32 1, i32 %0)
%76 = add nuw nsw i64 %64, 1
%77 = icmp eq i64 %76, %61
br i1 %77, label %78, label %63
78: ; preds = %72, %50
%79 = tail call i32 @free(i32* %16)
%80 = tail call i32 @mpf_clear(i32 undef)
%81 = tail call i32 @mpz_clear(i32 undef)
ret void
}