#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_ptr;
typedef int /*<<< orphan*/ mpfr_t;
typedef int /*<<< orphan*/ mpfr_srcptr;
typedef scalar_t__ mpfr_prec_t;
typedef int /*<<< orphan*/ mpfr_exp_t;

/* Variables and functions */
int /*<<< orphan*/ MPFR_RNDD;
int /*<<< orphan*/ MPFR_RNDN;
int /*<<< orphan*/ MPFR_RNDU;
int /*<<< orphan*/ mpfr_clear(int /*<<< orphan*/);
scalar_t__ mpfr_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_const_pi(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_div(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_floor(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_get_emax();
int /*<<< orphan*/ mpfr_get_emax_max();
int /*<<< orphan*/ mpfr_get_emin();
int /*<<< orphan*/ mpfr_get_emin_min();
scalar_t__ mpfr_get_prec(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_get_z(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_init2(int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ mpfr_mul_2ui(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_emax(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_emin(int /*<<< orphan*/);
scalar_t__ mpfr_sgn(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int /*<<< orphan*/);
void mpfr_quadrant(mpz_ptr k, mpfr_srcptr op) {
  mpfr_prec_t prec = mpfr_get_prec(op);
  if (mpfr_sgn(op) == 0) {
    mpz_set_ui(k, 0);
    return;
  }
  mpfr_exp_t saved_emin = mpfr_get_emin();
  mpfr_exp_t saved_emax = mpfr_get_emax();
  mpfr_set_emin(mpfr_get_emin_min());
  mpfr_set_emax(mpfr_get_emax_max());
  for (;;) {
    mpfr_t k_inf, k_sup;
    mpfr_init2(k_inf, prec);
    mpfr_const_pi(k_inf, MPFR_RNDU);
    mpfr_div(k_inf, op, k_inf, MPFR_RNDD);
    mpfr_mul_2ui(k_inf, k_inf, 1, MPFR_RNDD);
    mpfr_floor(k_inf, k_inf);
    mpfr_init2(k_sup, prec);
    mpfr_const_pi(k_sup, MPFR_RNDD);
    mpfr_div(k_sup, op, k_sup, MPFR_RNDU);
    mpfr_mul_2ui(k_sup, k_sup, 1, MPFR_RNDU);
    mpfr_floor(k_sup, k_sup);
    if (mpfr_cmp(k_inf, k_sup) == 0) {
      mpfr_get_z(k, k_inf, MPFR_RNDN);
      mpfr_clear(k_inf);
      mpfr_clear(k_sup);
      mpfr_set_emin(saved_emin);
      mpfr_set_emax(saved_emax);
      return;
    }
    mpfr_clear(k_inf);
    mpfr_clear(k_sup);
    prec += mpfr_get_prec(op);
  }
}


x86 assembly (clang, -O0):
<mpfr_quadrant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1110 <mpfr_get_prec@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   10c0 <mpfr_sgn@plt>
cmp    $0x0,%rax
jne    124b <mpfr_quadrant+0x3b>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   10f0 <mpz_set_ui@plt>
jmp    139e <mpfr_quadrant+0x18e>
mov    $0x0,%al
call   10a0 <mpfr_get_emin@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   10d0 <mpfr_get_emax@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1130 <mpfr_get_emin_min@plt>
mov    %eax,%edi
call   1050 <mpfr_set_emin@plt>
mov    $0x0,%al
call   10e0 <mpfr_get_emax_max@plt>
mov    %eax,%edi
call   1090 <mpfr_set_emax@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1120 <mpfr_init2@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
call   1030 <mpfr_const_pi@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    0x2d38(%rip),%rax
mov    (%rax),%ecx
call   10b0 <mpfr_div@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    0x2d24(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1080 <mpfr_mul_2ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1070 <mpfr_floor@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1120 <mpfr_init2@plt>
mov    -0x20(%rbp),%edi
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
call   1030 <mpfr_const_pi@plt>
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    0x2cd0(%rip),%rax
mov    (%rax),%ecx
call   10b0 <mpfr_div@plt>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    0x2cbc(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1080 <mpfr_mul_2ui@plt>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1070 <mpfr_floor@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1100 <mpfr_cmp@plt>
cmp    $0x0,%rax
jne    1379 <mpfr_quadrant+0x169>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    0x2c9b(%rip),%rax
mov    (%rax),%edx
call   1040 <mpfr_get_z@plt>
mov    -0x1c(%rbp),%edi
call   1060 <mpfr_clear@plt>
mov    -0x20(%rbp),%edi
call   1060 <mpfr_clear@plt>
mov    -0x14(%rbp),%edi
call   1050 <mpfr_set_emin@plt>
mov    -0x18(%rbp),%edi
call   1090 <mpfr_set_emax@plt>
jmp    139e <mpfr_quadrant+0x18e>
mov    -0x1c(%rbp),%edi
call   1060 <mpfr_clear@plt>
mov    -0x20(%rbp),%edi
call   1060 <mpfr_clear@plt>
mov    -0x8(%rbp),%edi
call   1110 <mpfr_get_prec@plt>
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    127b <mpfr_quadrant+0x6b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpfr_quadrant>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%r14d
mov    %esi,%edi
call   1110 <mpfr_get_prec@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   10c0 <mpfr_sgn@plt>
test   %rax,%rax
je     1335 <mpfr_quadrant+0x125>
xor    %eax,%eax
call   10a0 <mpfr_get_emin@plt>
mov    %eax,0x4(%rsp)
xor    %eax,%eax
call   10d0 <mpfr_get_emax@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1130 <mpfr_get_emin_min@plt>
mov    %eax,%edi
call   1050 <mpfr_set_emin@plt>
xor    %eax,%eax
call   10e0 <mpfr_get_emax_max@plt>
mov    %eax,%edi
call   1090 <mpfr_set_emax@plt>
mov    0x2d5e(%rip),%r13
mov    0x2d67(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rsi
call   1120 <mpfr_init2@plt>
mov    0x0(%r13),%esi
call   1030 <mpfr_const_pi@plt>
mov    (%r15),%ecx
mov    %ebp,%esi
call   10b0 <mpfr_div@plt>
mov    (%r15),%ecx
mov    $0x1,%edx
call   1080 <mpfr_mul_2ui@plt>
call   1070 <mpfr_floor@plt>
mov    %rbx,%rsi
call   1120 <mpfr_init2@plt>
mov    (%r15),%esi
call   1030 <mpfr_const_pi@plt>
mov    0x0(%r13),%ecx
mov    %ebp,%esi
call   10b0 <mpfr_div@plt>
mov    0x0(%r13),%ecx
mov    $0x1,%edx
call   1080 <mpfr_mul_2ui@plt>
call   1070 <mpfr_floor@plt>
call   1100 <mpfr_cmp@plt>
test   %rax,%rax
je     12fb <mpfr_quadrant+0xeb>
call   1060 <mpfr_clear@plt>
call   1060 <mpfr_clear@plt>
mov    %ebp,%edi
call   1110 <mpfr_get_prec@plt>
add    %rax,%rbx
jmp    1280 <mpfr_quadrant+0x70>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
call   1040 <mpfr_get_z@plt>
call   1060 <mpfr_clear@plt>
call   1060 <mpfr_clear@plt>
mov    0x4(%rsp),%edi
call   1050 <mpfr_set_emin@plt>
mov    %r12d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <mpfr_set_emax@plt>
mov    %r14d,%edi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10f0 <mpz_set_ui@plt>

LLVM IR (-O0):
@MPFR_RNDU = global i32 0
@MPFR_RNDD = global i32 0
@MPFR_RNDN = global i32 0
define void @mpfr_quadrant(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = call i64 @mpfr_get_prec(i32 %10)
store i64 %11, i64* %5
%12 = load i32, i32* %4
%13 = call i64 @mpfr_sgn(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* %3
%17 = call i32 @mpz_set_ui(i32 %16, i32 0)
br label %88
18: ; preds = %2
%19 = call i32 (...) @mpfr_get_emin()
store i32 %19, i32* %6
%20 = call i32 (...) @mpfr_get_emax()
store i32 %20, i32* %7
%21 = call i32 (...) @mpfr_get_emin_min()
%22 = call i32 @mpfr_set_emin(i32 %21)
%23 = call i32 (...) @mpfr_get_emax_max()
%24 = call i32 @mpfr_set_emax(i32 %23)
br label %25
25: ; preds = %79, %18
%26 = load i32, i32* %8
%27 = load i64, i64* %5
%28 = call i32 @mpfr_init2(i32 %26, i64 %27)
%29 = load i32, i32* %8
%30 = load i32, i32* @MPFR_RNDU
%31 = call i32 @mpfr_const_pi(i32 %29, i32 %30)
%32 = load i32, i32* %8
%33 = load i32, i32* %4
%34 = load i32, i32* %8
%35 = load i32, i32* @MPFR_RNDD
%36 = call i32 @mpfr_div(i32 %32, i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* %8
%38 = load i32, i32* %8
%39 = load i32, i32* @MPFR_RNDD
%40 = call i32 @mpfr_mul_2ui(i32 %37, i32 %38, i32 1, i32 %39)
%41 = load i32, i32* %8
%42 = load i32, i32* %8
%43 = call i32 @mpfr_floor(i32 %41, i32 %42)
%44 = load i32, i32* %9
%45 = load i64, i64* %5
%46 = call i32 @mpfr_init2(i32 %44, i64 %45)
%47 = load i32, i32* %9
%48 = load i32, i32* @MPFR_RNDD
%49 = call i32 @mpfr_const_pi(i32 %47, i32 %48)
%50 = load i32, i32* %9
%51 = load i32, i32* %4
%52 = load i32, i32* %9
%53 = load i32, i32* @MPFR_RNDU
%54 = call i32 @mpfr_div(i32 %50, i32 %51, i32 %52, i32 %53)
%55 = load i32, i32* %9
%56 = load i32, i32* %9
%57 = load i32, i32* @MPFR_RNDU
%58 = call i32 @mpfr_mul_2ui(i32 %55, i32 %56, i32 1, i32 %57)
%59 = load i32, i32* %9
%60 = load i32, i32* %9
%61 = call i32 @mpfr_floor(i32 %59, i32 %60)
%62 = load i32, i32* %8
%63 = load i32, i32* %9
%64 = call i64 @mpfr_cmp(i32 %62, i32 %63)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %79
66: ; preds = %25
%67 = load i32, i32* %3
%68 = load i32, i32* %8
%69 = load i32, i32* @MPFR_RNDN
%70 = call i32 @mpfr_get_z(i32 %67, i32 %68, i32 %69)
%71 = load i32, i32* %8
%72 = call i32 @mpfr_clear(i32 %71)
%73 = load i32, i32* %9
%74 = call i32 @mpfr_clear(i32 %73)
%75 = load i32, i32* %6
%76 = call i32 @mpfr_set_emin(i32 %75)
%77 = load i32, i32* %7
%78 = call i32 @mpfr_set_emax(i32 %77)
br label %88
79: ; preds = %25
%80 = load i32, i32* %8
%81 = call i32 @mpfr_clear(i32 %80)
%82 = load i32, i32* %9
%83 = call i32 @mpfr_clear(i32 %82)
%84 = load i32, i32* %4
%85 = call i64 @mpfr_get_prec(i32 %84)
%86 = load i64, i64* %5
%87 = add nsw i64 %86, %85
store i64 %87, i64* %5
br label %25
88: ; preds = %66, %15
ret void
}

LLVM IR (-O2):
@MPFR_RNDU = global i32 0
@MPFR_RNDD = global i32 0
@MPFR_RNDN = global i32 0
define void @mpfr_quadrant(i32 %0, i32 %1) {
%3 = tail call i64 @mpfr_get_prec(i32 %1)
%4 = tail call i64 @mpfr_sgn(i32 %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @mpz_set_ui(i32 %0, i32 0)
br label %47
8: ; preds = %2
%9 = tail call i32 (...) @mpfr_get_emin()
%10 = tail call i32 (...) @mpfr_get_emax()
%11 = tail call i32 (...) @mpfr_get_emin_min()
%12 = tail call i32 @mpfr_set_emin(i32 %11)
%13 = tail call i32 (...) @mpfr_get_emax_max()
%14 = tail call i32 @mpfr_set_emax(i32 %13)
br label %15
15: ; preds = %42, %8
%16 = phi i64 [ %3, %8 ], [ %46, %42 ]
%17 = tail call i32 @mpfr_init2(i32 undef, i64 %16)
%18 = load i32, i32* @MPFR_RNDU
%19 = tail call i32 @mpfr_const_pi(i32 undef, i32 %18)
%20 = load i32, i32* @MPFR_RNDD
%21 = tail call i32 @mpfr_div(i32 undef, i32 %1, i32 undef, i32 %20)
%22 = load i32, i32* @MPFR_RNDD
%23 = tail call i32 @mpfr_mul_2ui(i32 undef, i32 undef, i32 1, i32 %22)
%24 = tail call i32 @mpfr_floor(i32 undef, i32 undef)
%25 = tail call i32 @mpfr_init2(i32 undef, i64 %16)
%26 = load i32, i32* @MPFR_RNDD
%27 = tail call i32 @mpfr_const_pi(i32 undef, i32 %26)
%28 = load i32, i32* @MPFR_RNDU
%29 = tail call i32 @mpfr_div(i32 undef, i32 %1, i32 undef, i32 %28)
%30 = load i32, i32* @MPFR_RNDU
%31 = tail call i32 @mpfr_mul_2ui(i32 undef, i32 undef, i32 1, i32 %30)
%32 = tail call i32 @mpfr_floor(i32 undef, i32 undef)
%33 = tail call i64 @mpfr_cmp(i32 undef, i32 undef)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %15
%36 = load i32, i32* @MPFR_RNDN
%37 = tail call i32 @mpfr_get_z(i32 %0, i32 undef, i32 %36)
%38 = tail call i32 @mpfr_clear(i32 undef)
%39 = tail call i32 @mpfr_clear(i32 undef)
%40 = tail call i32 @mpfr_set_emin(i32 %9)
%41 = tail call i32 @mpfr_set_emax(i32 %10)
br label %47
42: ; preds = %15
%43 = tail call i32 @mpfr_clear(i32 undef)
%44 = tail call i32 @mpfr_clear(i32 undef)
%45 = tail call i64 @mpfr_get_prec(i32 %1)
%46 = add nsw i64 %45, %16
br label %15
47: ; preds = %35, %6
ret void
}