#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 mpfr_uexp_t;
typedef int /*<<< orphan*/ mpfr_srcptr;
typedef int mpfr_prec_t;
typedef int mpfr_exp_t;
typedef int mp_bitcnt_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int mpfr_get_exp(int /*<<< orphan*/);
int mpfr_get_prec(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_get_z_2exp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_inf_p(int /*<<< orphan*/);
scalar_t__ mpfr_number_p(int /*<<< orphan*/);
scalar_t__ mpfr_sgn(int /*<<< orphan*/);
scalar_t__ mpfr_zero_p(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_abs(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clrbit(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_mul_2exp(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_neg(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_tdiv_q_2exp(int /*<<< orphan*/, int /*<<< orphan*/, int);
void mpfr_as_mpz(mpz_t m, mpfr_srcptr x, mpfr_exp_t emin, mpfr_exp_t emax,
                 int subnormal) {
  mpfr_prec_t prec = mpfr_get_prec(x);
  if (mpfr_zero_p(x)) {
    mpz_set_ui(m, 0);
    return;
  }
  mpfr_uexp_t base_m;
  mp_bitcnt_t base_e = prec - 1;
  if (mpfr_number_p(x)) {
    mpfr_exp_t exp = mpfr_get_exp(x);
    mpfr_get_z_2exp(m, x);
    mpz_abs(m, m);
    mpz_clrbit(m, prec - 1);
    if (!subnormal) {
      base_m = exp - emin;
      mpz_add_ui(m, m, 1);
    } else if (exp >= emin + prec - 1) {
      base_m = exp - emin - prec + 2;
    } else {
      base_m = 1;
      base_e = exp - emin;
      mpz_tdiv_q_2exp(m, m, prec - 1 - base_e);
    }
  } else {
    assert(mpfr_inf_p(x));
    if (!subnormal) {
      base_m = emax - emin + 1;
      mpz_set_ui(m, 1);
    } else {
      base_m = emax - emin - prec + 3;
      mpz_set_ui(m, 0);
    }
  }
  mpz_t base;
  mpz_init_set_ui(base, base_m);
  mpz_mul_2exp(base, base, base_e);
  mpz_add(m, m, base);
  mpz_clear(base);
  if (mpfr_sgn(x) < 0) {
    mpz_neg(m, m);
  }
}


x86 assembly (clang, -O0):
<mpfr_as_mpz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1110 <mpfr_get_prec@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   10c0 <mpfr_zero_p@plt>
cmp    $0x0,%rax
je     1264 <mpfr_as_mpz+0x44>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   10f0 <mpz_set_ui@plt>
jmp    13cd <mpfr_as_mpz+0x1ad>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1140 <mpfr_number_p@plt>
cmp    $0x0,%rax
je     132c <mpfr_as_mpz+0x10c>
mov    -0x8(%rbp),%edi
call   1060 <mpfr_get_exp@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1130 <mpfr_get_z_2exp@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1090 <mpz_abs@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
call   1120 <mpz_clrbit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    12d6 <mpfr_as_mpz+0xb6>
mov    -0x24(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
jmp    1327 <mpfr_as_mpz+0x107>
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     12fe <mpfr_as_mpz+0xde>
mov    -0x24(%rbp),%eax
sub    -0xc(%rbp),%eax
sub    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1322 <mpfr_as_mpz+0x102>
movl   $0x1,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
sub    -0x20(%rbp),%edx
call   10b0 <mpz_tdiv_q_2exp@plt>
jmp    1327 <mpfr_as_mpz+0x107>
jmp    1381 <mpfr_as_mpz+0x161>
mov    -0x8(%rbp),%edi
call   1030 <mpfr_inf_p@plt>
mov    %eax,%edi
call   1070 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1363 <mpfr_as_mpz+0x143>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   10f0 <mpz_set_ui@plt>
jmp    137c <mpfr_as_mpz+0x15c>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
sub    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   10f0 <mpz_set_ui@plt>
jmp    1381 <mpfr_as_mpz+0x161>
mov    -0x28(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10e0 <mpz_init_set_ui@plt>
mov    -0x28(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1080 <mpz_mul_2exp@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x28(%rbp),%edx
call   10a0 <mpz_add@plt>
mov    -0x28(%rbp),%edi
call   1100 <mpz_clear@plt>
mov    -0x8(%rbp),%edi
call   10d0 <mpfr_sgn@plt>
cmp    $0x0,%rax
jge    13cd <mpfr_as_mpz+0x1ad>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <mpz_neg@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpfr_as_mpz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %ecx,%r12d
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%r15d
mov    %esi,%edi
call   1110 <mpfr_get_prec@plt>
mov    %eax,%r13d
mov    %r14d,%edi
call   10c0 <mpfr_zero_p@plt>
test   %rax,%rax
je     1268 <mpfr_as_mpz+0x48>
mov    %r15d,%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>
mov    %ebp,0x4(%rsp)
lea    -0x1(%r13),%ebp
mov    %r14d,%edi
call   1140 <mpfr_number_p@plt>
mov    %r14d,%edi
test   %rax,%rax
je     12dd <mpfr_as_mpz+0xbd>
call   1060 <mpfr_get_exp@plt>
mov    %eax,%r12d
mov    %r15d,%edi
mov    %r14d,%esi
call   1130 <mpfr_get_z_2exp@plt>
mov    %r15d,%edi
mov    %r15d,%esi
call   1090 <mpz_abs@plt>
mov    %r15d,%edi
mov    %ebp,(%rsp)
mov    %ebp,%esi
call   1120 <mpz_clrbit@plt>
cmpl   $0x0,0x4(%rsp)
je     1301 <mpfr_as_mpz+0xe1>
lea    (%rbx,%r13,1),%eax
add    $0xffffffff,%eax
cmp    %eax,%r12d
jge    1319 <mpfr_as_mpz+0xf9>
sub    %ebx,%r12d
mov    (%rsp),%edx
sub    %r12d,%edx
mov    %r15d,%edi
mov    %r15d,%esi
call   10b0 <mpz_tdiv_q_2exp@plt>
mov    %r12d,%ebp
mov    $0x1,%r12d
jmp    133c <mpfr_as_mpz+0x11c>
call   1030 <mpfr_inf_p@plt>
mov    %eax,%edi
call   1070 <assert@plt>
cmpl   $0x0,0x4(%rsp)
je     1328 <mpfr_as_mpz+0x108>
add    %ebx,%r13d
sub    %r13d,%r12d
add    $0x3,%r12d
mov    %r15d,%edi
xor    %esi,%esi
jmp    1337 <mpfr_as_mpz+0x117>
sub    %ebx,%r12d
mov    %r15d,%edi
mov    %r15d,%esi
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
mov    (%rsp),%ebp
jmp    133c <mpfr_as_mpz+0x11c>
add    %ebx,%r13d
sub    %r13d,%r12d
add    $0x2,%r12d
mov    (%rsp),%ebp
jmp    133c <mpfr_as_mpz+0x11c>
sub    %ebx,%r12d
add    $0x1,%r12d
mov    %r15d,%edi
mov    $0x1,%esi
call   10f0 <mpz_set_ui@plt>
mov    %r12d,%esi
call   10e0 <mpz_init_set_ui@plt>
mov    %ebp,%edx
call   1080 <mpz_mul_2exp@plt>
mov    %r15d,%edi
mov    %r15d,%esi
call   10a0 <mpz_add@plt>
call   1100 <mpz_clear@plt>
mov    %r14d,%edi
call   10d0 <mpfr_sgn@plt>
test   %rax,%rax
js     1377 <mpfr_as_mpz+0x157>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%edi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mpz_neg@plt>

LLVM IR (-O0):
define void @mpfr_as_mpz(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%16 = load i32, i32* %7
%17 = call i32 @mpfr_get_prec(i32 %16)
store i32 %17, i32* %11
%18 = load i32, i32* %7
%19 = call i64 @mpfr_zero_p(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %5
%22 = load i32, i32* %6
%23 = call i32 @mpz_set_ui(i32 %22, i32 0)
br label %123
24: ; preds = %5
%25 = load i32, i32* %11
%26 = sub nsw i32 %25, 1
store i32 %26, i32* %13
%27 = load i32, i32* %7
%28 = call i64 @mpfr_number_p(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %79
30: ; preds = %24
%31 = load i32, i32* %7
%32 = call i32 @mpfr_get_exp(i32 %31)
store i32 %32, i32* %14
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i32 @mpfr_get_z_2exp(i32 %33, i32 %34)
%36 = load i32, i32* %6
%37 = load i32, i32* %6
%38 = call i32 @mpz_abs(i32 %36, i32 %37)
%39 = load i32, i32* %6
%40 = load i32, i32* %11
%41 = sub nsw i32 %40, 1
%42 = call i32 @mpz_clrbit(i32 %39, i32 %41)
%43 = load i32, i32* %10
%44 = icmp ne i32 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %30
%46 = load i32, i32* %14
%47 = load i32, i32* %8
%48 = sub nsw i32 %46, %47
store i32 %48, i32* %12
%49 = load i32, i32* %6
%50 = load i32, i32* %6
%51 = call i32 @mpz_add_ui(i32 %49, i32 %50, i32 1)
br label %78
52: ; preds = %30
%53 = load i32, i32* %14
%54 = load i32, i32* %8
%55 = load i32, i32* %11
%56 = add nsw i32 %54, %55
%57 = sub nsw i32 %56, 1
%58 = icmp sge i32 %53, %57
br i1 %58, label %59, label %66
59: ; preds = %52
%60 = load i32, i32* %14
%61 = load i32, i32* %8
%62 = sub nsw i32 %60, %61
%63 = load i32, i32* %11
%64 = sub nsw i32 %62, %63
%65 = add nsw i32 %64, 2
store i32 %65, i32* %12
br label %77
66: ; preds = %52
store i32 1, i32* %12
%67 = load i32, i32* %14
%68 = load i32, i32* %8
%69 = sub nsw i32 %67, %68
store i32 %69, i32* %13
%70 = load i32, i32* %6
%71 = load i32, i32* %6
%72 = load i32, i32* %11
%73 = sub nsw i32 %72, 1
%74 = load i32, i32* %13
%75 = sub nsw i32 %73, %74
%76 = call i32 @mpz_tdiv_q_2exp(i32 %70, i32 %71, i32 %75)
br label %77
77: ; preds = %66, %59
br label %78
78: ; preds = %77, %45
br label %102
79: ; preds = %24
%80 = load i32, i32* %7
%81 = call i32 @mpfr_inf_p(i32 %80)
%82 = call i32 @assert(i32 %81)
%83 = load i32, i32* %10
%84 = icmp ne i32 %83, 0
br i1 %84, label %92, label %85
85: ; preds = %79
%86 = load i32, i32* %9
%87 = load i32, i32* %8
%88 = sub nsw i32 %86, %87
%89 = add nsw i32 %88, 1
store i32 %89, i32* %12
%90 = load i32, i32* %6
%91 = call i32 @mpz_set_ui(i32 %90, i32 1)
br label %101
92: ; preds = %79
%93 = load i32, i32* %9
%94 = load i32, i32* %8
%95 = sub nsw i32 %93, %94
%96 = load i32, i32* %11
%97 = sub nsw i32 %95, %96
%98 = add nsw i32 %97, 3
store i32 %98, i32* %12
%99 = load i32, i32* %6
%100 = call i32 @mpz_set_ui(i32 %99, i32 0)
br label %101
101: ; preds = %92, %85
br label %102
102: ; preds = %101, %78
%103 = load i32, i32* %15
%104 = load i32, i32* %12
%105 = call i32 @mpz_init_set_ui(i32 %103, i32 %104)
%106 = load i32, i32* %15
%107 = load i32, i32* %15
%108 = load i32, i32* %13
%109 = call i32 @mpz_mul_2exp(i32 %106, i32 %107, i32 %108)
%110 = load i32, i32* %6
%111 = load i32, i32* %6
%112 = load i32, i32* %15
%113 = call i32 @mpz_add(i32 %110, i32 %111, i32 %112)
%114 = load i32, i32* %15
%115 = call i32 @mpz_clear(i32 %114)
%116 = load i32, i32* %7
%117 = call i64 @mpfr_sgn(i32 %116)
%118 = icmp slt i64 %117, 0
br i1 %118, label %119, label %123
119: ; preds = %102
%120 = load i32, i32* %6
%121 = load i32, i32* %6
%122 = call i32 @mpz_neg(i32 %120, i32 %121)
br label %123
123: ; preds = %21, %119, %102
ret void
}

LLVM IR (-O2):
define void @mpfr_as_mpz(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 @mpfr_get_prec(i32 %1)
%7 = tail call i64 @mpfr_zero_p(i32 %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @mpz_set_ui(i32 %0, i32 0)
br label %59
11: ; preds = %5
%12 = add nsw i32 %6, -1
%13 = tail call i64 @mpfr_number_p(i32 %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %35, label %15
15: ; preds = %11
%16 = tail call i32 @mpfr_get_exp(i32 %1)
%17 = tail call i32 @mpfr_get_z_2exp(i32 %0, i32 %1)
%18 = tail call i32 @mpz_abs(i32 %0, i32 %0)
%19 = tail call i32 @mpz_clrbit(i32 %0, i32 %12)
%20 = icmp eq i32 %4, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = sub nsw i32 %16, %2
%23 = tail call i32 @mpz_add_ui(i32 %0, i32 %0, i32 1)
br label %48
24: ; preds = %15
%25 = add i32 %6, %2
%26 = add nsw i32 %25, -1
%27 = icmp slt i32 %16, %26
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = sub i32 2, %25
%30 = add i32 %29, %16
br label %48
31: ; preds = %24
%32 = sub nsw i32 %16, %2
%33 = sub nsw i32 %12, %32
%34 = tail call i32 @mpz_tdiv_q_2exp(i32 %0, i32 %0, i32 %33)
br label %48
35: ; preds = %11
%36 = tail call i32 @mpfr_inf_p(i32 %1)
%37 = tail call i32 @assert(i32 %36)
%38 = icmp eq i32 %4, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = sub i32 1, %2
%41 = add i32 %40, %3
%42 = tail call i32 @mpz_set_ui(i32 %0, i32 1)
br label %48
43: ; preds = %35
%44 = add i32 %3, 3
%45 = add i32 %6, %2
%46 = sub i32 %44, %45
%47 = tail call i32 @mpz_set_ui(i32 %0, i32 0)
br label %48
48: ; preds = %21, %31, %28, %39, %43
%49 = phi i32 [ %12, %43 ], [ %12, %39 ], [ %12, %28 ], [ %32, %31 ], [ %12, %21 ]
%50 = phi i32 [ %46, %43 ], [ %41, %39 ], [ %30, %28 ], [ 1, %31 ], [ %22, %21 ]
%51 = tail call i32 @mpz_init_set_ui(i32 undef, i32 %50)
%52 = tail call i32 @mpz_mul_2exp(i32 undef, i32 undef, i32 %49)
%53 = tail call i32 @mpz_add(i32 %0, i32 %0, i32 undef)
%54 = tail call i32 @mpz_clear(i32 undef)
%55 = tail call i64 @mpfr_sgn(i32 %1)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %48
%58 = tail call i32 @mpz_neg(i32 %0, i32 %0)
br label %59
59: ; preds = %48, %57, %9
ret void
}