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

/* Variables and functions */
scalar_t__ floor(double);
int /*<<< orphan*/ mpf_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/);
scalar_t__ mpf_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_div_2exp(int /*<<< orphan*/, int /*<<< orphan*/, long);
int /*<<< orphan*/ mpf_floor(int /*<<< orphan*/, int /*<<< orphan*/);
long mpf_get_si(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_set(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_set_ui(int /*<<< orphan*/, int);
scalar_t__ mpf_sgn(int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_ui_div(int /*<<< orphan*/, int, int /*<<< orphan*/);
void question_mark(mpf_t qmark, const mpf_t x, unsigned int prec) {
  mpf_t ox, h, bits, one, low_bound;
  long bitsdone, ibits;
  int place;
  mpf_set_ui(qmark, 0);
  if (0 == mpf_sgn(x))
    return;
  mpf_init(ox);
  mpf_init(h);
  mpf_init(bits);
  mpf_init(one);
  mpf_init(low_bound);
  mpf_set(h, x);
  mpf_set_ui(one, 1);
  long nbits = (long)floor(3.321 * prec);
  mpf_div_2exp(low_bound, one, nbits - 2);
  bitsdone = -1;
  place = 1;
  while (bitsdone < nbits) {
    mpf_ui_div(ox, 1, h);
    mpf_floor(bits, ox);
    mpf_sub(h, ox, bits);
    ibits = mpf_get_si(bits);
    bitsdone += ibits;
    mpf_div_2exp(ox, one, bitsdone);
    if (place % 2 == 1) {
      mpf_add(qmark, qmark, ox);
    } else {
      mpf_sub(qmark, qmark, ox);
    }
    if (mpf_cmp(h, low_bound) < 0)
      break;
    place++;
  }
  mpf_clear(ox);
  mpf_clear(h);
  mpf_clear(bits);
  mpf_clear(one);
  mpf_clear(low_bound);
}


x86 assembly (clang, -O0):
<question_mark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   10b0 <mpf_set_ui@plt>
mov    -0x8(%rbp),%edi
call   10d0 <mpf_sgn@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1206 <question_mark+0x36>
jmp    1368 <question_mark+0x198>
mov    -0x10(%rbp),%edi
call   1080 <mpf_init@plt>
mov    -0x14(%rbp),%edi
call   1080 <mpf_init@plt>
mov    -0x18(%rbp),%edi
call   1080 <mpf_init@plt>
mov    -0x1c(%rbp),%edi
call   1080 <mpf_init@plt>
mov    -0x20(%rbp),%edi
call   1080 <mpf_init@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10a0 <mpf_set@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   10b0 <mpf_set_ui@plt>
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xdaa(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   10f0 <floor@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x40(%rbp),%rdx
sub    $0x2,%rdx
call   1040 <mpf_div_2exp@plt>
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x40(%rbp),%rax
jge    1340 <question_mark+0x170>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   1060 <mpf_ui_div@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <mpf_floor@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%edx
call   10c0 <mpf_sub@plt>
mov    -0x18(%rbp),%edi
call   10e0 <mpf_get_si@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1040 <mpf_div_2exp@plt>
mov    -0x34(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    130a <question_mark+0x13a>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <mpf_add@plt>
jmp    1318 <question_mark+0x148>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10c0 <mpf_sub@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1050 <mpf_cmp@plt>
cmp    $0x0,%rax
jge    1332 <question_mark+0x162>
jmp    1340 <question_mark+0x170>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1285 <question_mark+0xb5>
mov    -0x10(%rbp),%edi
call   1090 <mpf_clear@plt>
mov    -0x14(%rbp),%edi
call   1090 <mpf_clear@plt>
mov    -0x18(%rbp),%edi
call   1090 <mpf_clear@plt>
mov    -0x1c(%rbp),%edi
call   1090 <mpf_clear@plt>
mov    -0x20(%rbp),%edi
call   1090 <mpf_clear@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<question_mark>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%r15d
xor    %esi,%esi
call   10b0 <mpf_set_ui@plt>
mov    %ebx,%edi
call   10d0 <mpf_sgn@plt>
test   %rax,%rax
je     12d8 <question_mark+0x108>
call   1080 <mpf_init@plt>
call   1080 <mpf_init@plt>
call   1080 <mpf_init@plt>
call   1080 <mpf_init@plt>
call   1080 <mpf_init@plt>
mov    %ebx,%esi
call   10a0 <mpf_set@plt>
mov    $0x1,%ebp
mov    $0x1,%esi
call   10b0 <mpf_set_ui@plt>
mov    %r14d,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xdca(%rip),%xmm0
call   10f0 <floor@plt>
mov    %rax,%r14
lea    -0x2(%rax),%rdx
call   1040 <mpf_div_2exp@plt>
test   %r14,%r14
js     12b7 <question_mark+0xe7>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%r12
mov    $0x1,%esi
call   1060 <mpf_ui_div@plt>
call   1030 <mpf_floor@plt>
call   10c0 <mpf_sub@plt>
call   10e0 <mpf_get_si@plt>
mov    %rax,%rbx
add    %r12,%rbx
mov    %rbx,%rdx
call   1040 <mpf_div_2exp@plt>
mov    %r15d,%edi
mov    %r15d,%esi
test   $0x1,%bpl
jne    12a0 <question_mark+0xd0>
call   10c0 <mpf_sub@plt>
jmp    12a5 <question_mark+0xd5>
nopl   (%rax)
call   1070 <mpf_add@plt>
call   1050 <mpf_cmp@plt>
test   %rax,%rax
js     12b7 <question_mark+0xe7>
add    $0x1,%ebp
cmp    %r14,%rbx
jl     1260 <question_mark+0x90>
call   1090 <mpf_clear@plt>
call   1090 <mpf_clear@plt>
call   1090 <mpf_clear@plt>
call   1090 <mpf_clear@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <mpf_clear@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @question_mark(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 i64
%13 = alloca i64
%14 = alloca i32
%15 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%16 = load i32, i32* %4
%17 = call i32 @mpf_set_ui(i32 %16, i32 0)
%18 = load i32, i32* %5
%19 = call i64 @mpf_sgn(i32 %18)
%20 = icmp eq i64 0, %19
br i1 %20, label %21, label %22
21: ; preds = %3
br label %104
22: ; preds = %3
%23 = load i32, i32* %7
%24 = call i32 @mpf_init(i32 %23)
%25 = load i32, i32* %8
%26 = call i32 @mpf_init(i32 %25)
%27 = load i32, i32* %9
%28 = call i32 @mpf_init(i32 %27)
%29 = load i32, i32* %10
%30 = call i32 @mpf_init(i32 %29)
%31 = load i32, i32* %11
%32 = call i32 @mpf_init(i32 %31)
%33 = load i32, i32* %8
%34 = load i32, i32* %5
%35 = call i32 @mpf_set(i32 %33, i32 %34)
%36 = load i32, i32* %10
%37 = call i32 @mpf_set_ui(i32 %36, i32 1)
%38 = load i32, i32* %6
%39 = uitofp i32 %38 to double
%40 = fmul double 3.321000e+00, %39
%41 = call i64 @floor(double %40)
store i64 %41, i64* %15
%42 = load i32, i32* %11
%43 = load i32, i32* %10
%44 = load i64, i64* %15
%45 = sub nsw i64 %44, 2
%46 = call i32 @mpf_div_2exp(i32 %42, i32 %43, i64 %45)
store i64 -1, i64* %12
store i32 1, i32* %14
br label %47
47: ; preds = %90, %22
%48 = load i64, i64* %12
%49 = load i64, i64* %15
%50 = icmp slt i64 %48, %49
br i1 %50, label %51, label %93
51: ; preds = %47
%52 = load i32, i32* %7
%53 = load i32, i32* %8
%54 = call i32 @mpf_ui_div(i32 %52, i32 1, i32 %53)
%55 = load i32, i32* %9
%56 = load i32, i32* %7
%57 = call i32 @mpf_floor(i32 %55, i32 %56)
%58 = load i32, i32* %8
%59 = load i32, i32* %7
%60 = load i32, i32* %9
%61 = call i32 @mpf_sub(i32 %58, i32 %59, i32 %60)
%62 = load i32, i32* %9
%63 = call i64 @mpf_get_si(i32 %62)
store i64 %63, i64* %13
%64 = load i64, i64* %13
%65 = load i64, i64* %12
%66 = add nsw i64 %65, %64
store i64 %66, i64* %12
%67 = load i32, i32* %7
%68 = load i32, i32* %10
%69 = load i64, i64* %12
%70 = call i32 @mpf_div_2exp(i32 %67, i32 %68, i64 %69)
%71 = load i32, i32* %14
%72 = srem i32 %71, 2
%73 = icmp eq i32 %72, 1
br i1 %73, label %74, label %79
74: ; preds = %51
%75 = load i32, i32* %4
%76 = load i32, i32* %4
%77 = load i32, i32* %7
%78 = call i32 @mpf_add(i32 %75, i32 %76, i32 %77)
br label %84
79: ; preds = %51
%80 = load i32, i32* %4
%81 = load i32, i32* %4
%82 = load i32, i32* %7
%83 = call i32 @mpf_sub(i32 %80, i32 %81, i32 %82)
br label %84
84: ; preds = %79, %74
%85 = load i32, i32* %8
%86 = load i32, i32* %11
%87 = call i64 @mpf_cmp(i32 %85, i32 %86)
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %84
br label %93
90: ; preds = %84
%91 = load i32, i32* %14
%92 = add nsw i32 %91, 1
store i32 %92, i32* %14
br label %47
93: ; preds = %89, %47
%94 = load i32, i32* %7
%95 = call i32 @mpf_clear(i32 %94)
%96 = load i32, i32* %8
%97 = call i32 @mpf_clear(i32 %96)
%98 = load i32, i32* %9
%99 = call i32 @mpf_clear(i32 %98)
%100 = load i32, i32* %10
%101 = call i32 @mpf_clear(i32 %100)
%102 = load i32, i32* %11
%103 = call i32 @mpf_clear(i32 %102)
br label %104
104: ; preds = %93, %21
ret void
}

LLVM IR (-O2):
define void @question_mark(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mpf_set_ui(i32 %0, i32 0)
%5 = tail call i64 @mpf_sgn(i32 %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %48, label %7
7: ; preds = %3
%8 = tail call i32 @mpf_init(i32 undef)
%9 = tail call i32 @mpf_init(i32 undef)
%10 = tail call i32 @mpf_init(i32 undef)
%11 = tail call i32 @mpf_init(i32 undef)
%12 = tail call i32 @mpf_init(i32 undef)
%13 = tail call i32 @mpf_set(i32 undef, i32 %1)
%14 = tail call i32 @mpf_set_ui(i32 undef, i32 1)
%15 = uitofp i32 %2 to double
%16 = fmul double %15, 3.321000e+00
%17 = tail call i64 @floor(double %16)
%18 = add nsw i64 %17, -2
%19 = tail call i32 @mpf_div_2exp(i32 undef, i32 undef, i64 %18)
%20 = icmp sgt i64 %17, -1
br i1 %20, label %21, label %42
21: ; preds = %7, %36
%22 = phi i32 [ %39, %36 ], [ 1, %7 ]
%23 = phi i64 [ %28, %36 ], [ -1, %7 ]
%24 = tail call i32 @mpf_ui_div(i32 undef, i32 1, i32 undef)
%25 = tail call i32 @mpf_floor(i32 undef, i32 undef)
%26 = tail call i32 @mpf_sub(i32 undef, i32 undef, i32 undef)
%27 = tail call i64 @mpf_get_si(i32 undef)
%28 = add nsw i64 %27, %23
%29 = tail call i32 @mpf_div_2exp(i32 undef, i32 undef, i64 %28)
%30 = and i32 %22, 1
%31 = icmp eq i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %21
%33 = tail call i32 @mpf_add(i32 %0, i32 %0, i32 undef)
br label %36
34: ; preds = %21
%35 = tail call i32 @mpf_sub(i32 %0, i32 %0, i32 undef)
br label %36
36: ; preds = %34, %32
%37 = tail call i64 @mpf_cmp(i32 undef, i32 undef)
%38 = icmp sgt i64 %37, -1
%39 = add nuw nsw i32 %22, 1
%40 = icmp slt i64 %28, %17
%41 = select i1 %38, i1 %40, i1 false
br i1 %41, label %21, label %42
42: ; preds = %36, %7
%43 = tail call i32 @mpf_clear(i32 undef)
%44 = tail call i32 @mpf_clear(i32 undef)
%45 = tail call i32 @mpf_clear(i32 undef)
%46 = tail call i32 @mpf_clear(i32 undef)
%47 = tail call i32 @mpf_clear(i32 undef)
br label %48
48: ; preds = %3, %42
ret void
}