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

/* Variables and functions */
int /*<<< orphan*/ MPFR_RNDD;
int /*<<< orphan*/ MPFR_RNDU;
int mpfr_check_range(int /*<<< orphan*/, int /*<<< orphan*/,
                     int /*<<< orphan*/);
scalar_t__ mpfr_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_const_pi(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_div_2exp(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_get_emax();
int /*<<< orphan*/ mpfr_get_emin();
int mpfr_get_prec(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_init2(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpfr_mul_z(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_emax(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_emin(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_zero(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpfr_subnormalize(int /*<<< orphan*/, int,
                                     int /*<<< orphan*/);
scalar_t__ mpz_sgn(int /*<<< orphan*/);
void mpfr_piHalf(mpfr_t r, mpz_t k, mpfr_rnd_t rnd, mpfr_exp_t emin,
                 mpfr_exp_t emax, int subnormal) {
  if (mpz_sgn(k) == 0) {
    mpfr_set_zero(r, 1);
    return;
  }
  mpfr_t r2;
  mpfr_init2(r2, mpfr_get_prec(r));
  mpfr_prec_t prec = mpfr_get_prec(r) * 2;
  do {
    mpfr_t inf, sup;
    mpfr_init2(inf, prec);
    mpfr_const_pi(inf, MPFR_RNDD);
    mpfr_div_2exp(inf, inf, 1, MPFR_RNDD);
    mpfr_mul_z(inf, inf, k, MPFR_RNDD);
    mpfr_init2(sup, prec);
    mpfr_const_pi(sup, MPFR_RNDU);
    mpfr_div_2exp(sup, sup, 1, MPFR_RNDU);
    mpfr_mul_z(sup, sup, k, MPFR_RNDU);
    mpfr_exp_t saved_emin = mpfr_get_emin();
    mpfr_exp_t saved_emax = mpfr_get_emax();
    mpfr_set_emin(emin);
    mpfr_set_emax(emax);
    int ti = mpfr_check_range(r, mpfr_set(r, inf, rnd), rnd);
    int ts = mpfr_check_range(r2, mpfr_set(r2, sup, rnd), rnd);
    if (subnormal) {
      mpfr_subnormalize(r, ti, rnd);
      mpfr_subnormalize(r2, ts, rnd);
    }
    mpfr_set_emin(saved_emin);
    mpfr_set_emax(saved_emax);
    prec += mpfr_get_prec(r);
  } while (mpfr_cmp(r, r2) != 0);
}


x86 assembly (clang, -O0):
<mpfr_piHalf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1110 <mpz_sgn@plt>
cmp    $0x0,%rax
jne    1230 <mpfr_piHalf+0x40>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1050 <mpfr_set_zero@plt>
jmp    13b3 <mpfr_piHalf+0x1c3>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x4(%rbp),%edi
call   10d0 <mpfr_get_prec@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
call   10e0 <mpfr_init2@plt>
mov    -0x4(%rbp),%edi
call   10d0 <mpfr_get_prec@plt>
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   10e0 <mpfr_init2@plt>
mov    -0x24(%rbp),%edi
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
call   1030 <mpfr_const_pi@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    0x2d69(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10f0 <mpfr_div_2exp@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    0x2d4d(%rip),%rax
mov    (%rax),%ecx
call   10a0 <mpfr_mul_z@plt>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%esi
call   10e0 <mpfr_init2@plt>
mov    -0x28(%rbp),%edi
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
call   1030 <mpfr_const_pi@plt>
mov    -0x28(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    0x2d0d(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10f0 <mpfr_div_2exp@plt>
mov    -0x28(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    0x2cf1(%rip),%rax
mov    (%rax),%ecx
call   10a0 <mpfr_mul_z@plt>
mov    $0x0,%al
call   1090 <mpfr_get_emin@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   10b0 <mpfr_get_emax@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <mpfr_set_emin@plt>
mov    -0x14(%rbp),%edi
call   1080 <mpfr_set_emax@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <mpfr_set@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
mov    -0xc(%rbp),%edx
call   1100 <mpfr_check_range@plt>
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <mpfr_set@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%esi
mov    -0xc(%rbp),%edx
call   1100 <mpfr_check_range@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1380 <mpfr_piHalf+0x190>
mov    -0x4(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <mpfr_subnormalize@plt>
mov    -0x1c(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <mpfr_subnormalize@plt>
mov    -0x2c(%rbp),%edi
call   1040 <mpfr_set_emin@plt>
mov    -0x30(%rbp),%edi
call   1080 <mpfr_set_emax@plt>
mov    -0x4(%rbp),%edi
call   10d0 <mpfr_get_prec@plt>
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10c0 <mpfr_cmp@plt>
cmp    $0x0,%rax
jne    1256 <mpfr_piHalf+0x66>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpfr_piHalf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0x10(%rsp)
mov    %r8d,0xc(%rsp)
mov    %ecx,0x8(%rsp)
mov    %edx,%r12d
mov    %edi,%ebx
mov    %esi,0x4(%rsp)
mov    %esi,%edi
call   1110 <mpz_sgn@plt>
test   %rax,%rax
je     136d <mpfr_piHalf+0x17d>
mov    %ebx,%edi
call   10d0 <mpfr_get_prec@plt>
mov    %eax,%esi
call   10e0 <mpfr_init2@plt>
mov    %ebx,%edi
call   10d0 <mpfr_get_prec@plt>
mov    %eax,%r14d
add    %eax,%r14d
jmp    127a <mpfr_piHalf+0x8a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x14(%rsp),%edi
call   1040 <mpfr_set_emin@plt>
mov    %ebp,%edi
call   1080 <mpfr_set_emax@plt>
mov    %ebx,%edi
call   10d0 <mpfr_get_prec@plt>
add    %eax,%r14d
mov    %ebx,%edi
call   10c0 <mpfr_cmp@plt>
test   %rax,%rax
je     135e <mpfr_piHalf+0x16e>
mov    %r14d,%esi
call   10e0 <mpfr_init2@plt>
mov    0x2d5f(%rip),%rbp
mov    0x0(%rbp),%esi
call   1030 <mpfr_const_pi@plt>
mov    0x0(%rbp),%ecx
mov    $0x1,%edx
call   10f0 <mpfr_div_2exp@plt>
mov    0x0(%rbp),%ecx
mov    0x4(%rsp),%ebp
mov    %ebp,%edx
call   10a0 <mpfr_mul_z@plt>
mov    %r14d,%esi
call   10e0 <mpfr_init2@plt>
mov    0x2d1d(%rip),%rax
mov    %ebx,%r15d
mov    %rax,%rbx
mov    (%rax),%esi
call   1030 <mpfr_const_pi@plt>
mov    (%rbx),%ecx
mov    $0x1,%edx
call   10f0 <mpfr_div_2exp@plt>
mov    (%rbx),%ecx
mov    %r15d,%ebx
mov    %ebp,%edx
call   10a0 <mpfr_mul_z@plt>
xor    %eax,%eax
call   1090 <mpfr_get_emin@plt>
mov    %eax,0x14(%rsp)
xor    %eax,%eax
call   10b0 <mpfr_get_emax@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%edi
call   1040 <mpfr_set_emin@plt>
mov    0xc(%rsp),%edi
call   1080 <mpfr_set_emax@plt>
mov    %r15d,%edi
mov    %r12d,%edx
call   1060 <mpfr_set@plt>
mov    %r15d,%edi
mov    %eax,%esi
mov    %r12d,%edx
call   1100 <mpfr_check_range@plt>
mov    %eax,%r13d
mov    %r12d,%edx
call   1060 <mpfr_set@plt>
mov    %eax,%esi
mov    %r12d,%edx
call   1100 <mpfr_check_range@plt>
cmpl   $0x0,0x10(%rsp)
je     1250 <mpfr_piHalf+0x60>
mov    %eax,%r15d
mov    %ebx,%edi
mov    %r13d,%esi
mov    %r12d,%edx
call   1070 <mpfr_subnormalize@plt>
mov    %r15d,%esi
mov    %r12d,%edx
call   1070 <mpfr_subnormalize@plt>
jmp    1250 <mpfr_piHalf+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%edi
mov    $0x1,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mpfr_set_zero@plt>

LLVM IR (-O0):
@MPFR_RNDD = global i32 0
@MPFR_RNDU = global i32 0
define void @mpfr_piHalf(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%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
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%21 = load i32, i32* %8
%22 = call i64 @mpz_sgn(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %6
%25 = load i32, i32* %7
%26 = call i32 @mpfr_set_zero(i32 %25, i32 1)
br label %111
27: ; preds = %6
%28 = load i32, i32* %13
%29 = load i32, i32* %7
%30 = call i32 @mpfr_get_prec(i32 %29)
%31 = call i32 @mpfr_init2(i32 %28, i32 %30)
%32 = load i32, i32* %7
%33 = call i32 @mpfr_get_prec(i32 %32)
%34 = mul nsw i32 %33, 2
store i32 %34, i32* %14
br label %35
35: ; preds = %106, %27
%36 = load i32, i32* %15
%37 = load i32, i32* %14
%38 = call i32 @mpfr_init2(i32 %36, i32 %37)
%39 = load i32, i32* %15
%40 = load i32, i32* @MPFR_RNDD
%41 = call i32 @mpfr_const_pi(i32 %39, i32 %40)
%42 = load i32, i32* %15
%43 = load i32, i32* %15
%44 = load i32, i32* @MPFR_RNDD
%45 = call i32 @mpfr_div_2exp(i32 %42, i32 %43, i32 1, i32 %44)
%46 = load i32, i32* %15
%47 = load i32, i32* %15
%48 = load i32, i32* %8
%49 = load i32, i32* @MPFR_RNDD
%50 = call i32 @mpfr_mul_z(i32 %46, i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %16
%52 = load i32, i32* %14
%53 = call i32 @mpfr_init2(i32 %51, i32 %52)
%54 = load i32, i32* %16
%55 = load i32, i32* @MPFR_RNDU
%56 = call i32 @mpfr_const_pi(i32 %54, i32 %55)
%57 = load i32, i32* %16
%58 = load i32, i32* %16
%59 = load i32, i32* @MPFR_RNDU
%60 = call i32 @mpfr_div_2exp(i32 %57, i32 %58, i32 1, i32 %59)
%61 = load i32, i32* %16
%62 = load i32, i32* %16
%63 = load i32, i32* %8
%64 = load i32, i32* @MPFR_RNDU
%65 = call i32 @mpfr_mul_z(i32 %61, i32 %62, i32 %63, i32 %64)
%66 = call i32 (...) @mpfr_get_emin()
store i32 %66, i32* %17
%67 = call i32 (...) @mpfr_get_emax()
store i32 %67, i32* %18
%68 = load i32, i32* %10
%69 = call i32 @mpfr_set_emin(i32 %68)
%70 = load i32, i32* %11
%71 = call i32 @mpfr_set_emax(i32 %70)
%72 = load i32, i32* %7
%73 = load i32, i32* %7
%74 = load i32, i32* %15
%75 = load i32, i32* %9
%76 = call i32 @mpfr_set(i32 %73, i32 %74, i32 %75)
%77 = load i32, i32* %9
%78 = call i32 @mpfr_check_range(i32 %72, i32 %76, i32 %77)
store i32 %78, i32* %19
%79 = load i32, i32* %13
%80 = load i32, i32* %13
%81 = load i32, i32* %16
%82 = load i32, i32* %9
%83 = call i32 @mpfr_set(i32 %80, i32 %81, i32 %82)
%84 = load i32, i32* %9
%85 = call i32 @mpfr_check_range(i32 %79, i32 %83, i32 %84)
store i32 %85, i32* %20
%86 = load i32, i32* %12
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %97
88: ; preds = %35
%89 = load i32, i32* %7
%90 = load i32, i32* %19
%91 = load i32, i32* %9
%92 = call i32 @mpfr_subnormalize(i32 %89, i32 %90, i32 %91)
%93 = load i32, i32* %13
%94 = load i32, i32* %20
%95 = load i32, i32* %9
%96 = call i32 @mpfr_subnormalize(i32 %93, i32 %94, i32 %95)
br label %97
97: ; preds = %88, %35
%98 = load i32, i32* %17
%99 = call i32 @mpfr_set_emin(i32 %98)
%100 = load i32, i32* %18
%101 = call i32 @mpfr_set_emax(i32 %100)
%102 = load i32, i32* %7
%103 = call i32 @mpfr_get_prec(i32 %102)
%104 = load i32, i32* %14
%105 = add nsw i32 %104, %103
store i32 %105, i32* %14
br label %106
106: ; preds = %97
%107 = load i32, i32* %7
%108 = load i32, i32* %13
%109 = call i64 @mpfr_cmp(i32 %107, i32 %108)
%110 = icmp ne i64 %109, 0
br i1 %110, label %35, label %111
111: ; preds = %24, %106
ret void
}

LLVM IR (-O2):
@MPFR_RNDD = global i32 0
@MPFR_RNDU = global i32 0
define void @mpfr_piHalf(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i64 @mpz_sgn(i32 %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @mpfr_set_zero(i32 %0, i32 1)
br label %51
11: ; preds = %6
%12 = tail call i32 @mpfr_get_prec(i32 %0)
%13 = tail call i32 @mpfr_init2(i32 undef, i32 %12)
%14 = tail call i32 @mpfr_get_prec(i32 %0)
%15 = shl nsw i32 %14, 1
%16 = icmp eq i32 %5, 0
br label %17
17: ; preds = %44, %11
%18 = phi i32 [ %15, %11 ], [ %48, %44 ]
%19 = tail call i32 @mpfr_init2(i32 undef, i32 %18)
%20 = load i32, i32* @MPFR_RNDD
%21 = tail call i32 @mpfr_const_pi(i32 undef, i32 %20)
%22 = load i32, i32* @MPFR_RNDD
%23 = tail call i32 @mpfr_div_2exp(i32 undef, i32 undef, i32 1, i32 %22)
%24 = load i32, i32* @MPFR_RNDD
%25 = tail call i32 @mpfr_mul_z(i32 undef, i32 undef, i32 %1, i32 %24)
%26 = tail call i32 @mpfr_init2(i32 undef, i32 %18)
%27 = load i32, i32* @MPFR_RNDU
%28 = tail call i32 @mpfr_const_pi(i32 undef, i32 %27)
%29 = load i32, i32* @MPFR_RNDU
%30 = tail call i32 @mpfr_div_2exp(i32 undef, i32 undef, i32 1, i32 %29)
%31 = load i32, i32* @MPFR_RNDU
%32 = tail call i32 @mpfr_mul_z(i32 undef, i32 undef, i32 %1, i32 %31)
%33 = tail call i32 (...) @mpfr_get_emin()
%34 = tail call i32 (...) @mpfr_get_emax()
%35 = tail call i32 @mpfr_set_emin(i32 %3)
%36 = tail call i32 @mpfr_set_emax(i32 %4)
%37 = tail call i32 @mpfr_set(i32 %0, i32 undef, i32 %2)
%38 = tail call i32 @mpfr_check_range(i32 %0, i32 %37, i32 %2)
%39 = tail call i32 @mpfr_set(i32 undef, i32 undef, i32 %2)
%40 = tail call i32 @mpfr_check_range(i32 undef, i32 %39, i32 %2)
br i1 %16, label %44, label %41
41: ; preds = %17
%42 = tail call i32 @mpfr_subnormalize(i32 %0, i32 %38, i32 %2)
%43 = tail call i32 @mpfr_subnormalize(i32 undef, i32 %40, i32 %2)
br label %44
44: ; preds = %41, %17
%45 = tail call i32 @mpfr_set_emin(i32 %33)
%46 = tail call i32 @mpfr_set_emax(i32 %34)
%47 = tail call i32 @mpfr_get_prec(i32 %0)
%48 = add nsw i32 %47, %18
%49 = tail call i64 @mpfr_cmp(i32 %0, i32 undef)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %17
51: ; preds = %44, %9
ret void
}