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

/* Variables and functions */
int /*<<< orphan*/ GMP_RNDN;
double fabs(double);
int /*<<< orphan*/ mpfr_clears(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/ *);
scalar_t__ mpfr_cmp_d(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_div(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
double mpfr_get_d(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_get_d_2exp(long *, int /*<<< orphan*/,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_inits(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ mpfr_set_ui_2exp(int /*<<< orphan*/, int, long,
                                    int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
double countULP(mpfr_t d, mpfr_t c) {
  mpfr_t fry, frw;
  mpfr_inits(fry, frw, NULL);
  double c2 = mpfr_get_d(c, GMP_RNDN);
  if (c2 == 0 && mpfr_cmp_d(d, 0) != 0)
    return 10000;
  long e;
  mpfr_get_d_2exp(&e, c, GMP_RNDN);
  mpfr_set_ui_2exp(frw, 1, e - 53, GMP_RNDN);
  mpfr_sub(fry, d, c, GMP_RNDN);
  mpfr_div(fry, fry, frw, GMP_RNDN);
  double u = fabs(mpfr_get_d(fry, GMP_RNDN));
  mpfr_clears(fry, frw, NULL);
  return u;
}


x86 assembly (clang, -O0):
<countULP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <mpfr_inits@plt>
mov    -0x10(%rbp),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1050 <mpfr_get_d@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11f1 <countULP+0x71>
jp     11f1 <countULP+0x71>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1040 <mpfr_cmp_d@plt>
cmp    $0x0,%rax
je     11f1 <countULP+0x71>
movsd  0xe29(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128c <countULP+0x10c>
mov    -0x10(%rbp),%esi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rdi
call   10a0 <mpfr_get_d_2exp@plt>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rdx
sub    $0x35,%rdx
mov    0x2dc8(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1070 <mpfr_set_ui_2exp@plt>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    0x2dac(%rip),%rax
mov    (%rax),%ecx
call   1030 <mpfr_sub@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    0x2d95(%rip),%rax
mov    (%rax),%ecx
call   1080 <mpfr_div@plt>
mov    -0x14(%rbp),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
call   1050 <mpfr_get_d@plt>
movaps 0xd96(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <mpfr_clears@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countULP>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
xor    %edx,%edx
call   1090 <mpfr_inits@plt>
mov    0x2e45(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %ebx,%edi
call   1050 <mpfr_get_d@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ca <countULP+0x4a>
jp     11ca <countULP+0x4a>
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <mpfr_cmp_d@plt>
test   %rax,%rax
je     11ca <countULP+0x4a>
movsd  0xe38(%rip),%xmm0
jmp    1226 <countULP+0xa6>
mov    0x0(%rbp),%edx
lea    0x8(%rsp),%rdi
mov    %ebx,%esi
call   10a0 <mpfr_get_d_2exp@plt>
mov    0x8(%rsp),%rdx
add    $0xffffffffffffffcb,%rdx
mov    0x0(%rbp),%ecx
mov    $0x1,%esi
call   1070 <mpfr_set_ui_2exp@plt>
mov    0x0(%rbp),%ecx
mov    %r14d,%esi
mov    %ebx,%edx
call   1030 <mpfr_sub@plt>
mov    0x0(%rbp),%ecx
call   1080 <mpfr_div@plt>
mov    0x0(%rbp),%esi
call   1050 <mpfr_get_d@plt>
andpd  0xdfc(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %edx,%edx
call   1060 <mpfr_clears@plt>
movaps 0x10(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@GMP_RNDN = global i32 0
define double @countULP(i32 %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i64
%10 = alloca double
store i32 %0, i32* %4
store i32 %1, i32* %5
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = call i32 @mpfr_inits(i32 %11, i32 %12, i32* null)
%14 = load i32, i32* %5
%15 = load i32, i32* @GMP_RNDN
%16 = call double @mpfr_get_d(i32 %14, i32 %15)
store double %16, double* %8
%17 = load double, double* %8
%18 = fcmp oeq double %17, 0.000000e+00
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i32, i32* %4
%21 = call i64 @mpfr_cmp_d(i32 %20, i32 0)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store double 1.000000e+04, double* %3
br label %51
24: ; preds = %19, %2
%25 = load i32, i32* %5
%26 = load i32, i32* @GMP_RNDN
%27 = call i32 @mpfr_get_d_2exp(i64* %9, i32 %25, i32 %26)
%28 = load i32, i32* %7
%29 = load i64, i64* %9
%30 = sub nsw i64 %29, 53
%31 = load i32, i32* @GMP_RNDN
%32 = call i32 @mpfr_set_ui_2exp(i32 %28, i32 1, i64 %30, i32 %31)
%33 = load i32, i32* %6
%34 = load i32, i32* %4
%35 = load i32, i32* %5
%36 = load i32, i32* @GMP_RNDN
%37 = call i32 @mpfr_sub(i32 %33, i32 %34, i32 %35, i32 %36)
%38 = load i32, i32* %6
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = load i32, i32* @GMP_RNDN
%42 = call i32 @mpfr_div(i32 %38, i32 %39, i32 %40, i32 %41)
%43 = load i32, i32* %6
%44 = load i32, i32* @GMP_RNDN
%45 = call double @mpfr_get_d(i32 %43, i32 %44)
%46 = call double @llvm.fabs.f64(double %45)
store double %46, double* %10
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = call i32 @mpfr_clears(i32 %47, i32 %48, i32* null)
%50 = load double, double* %10
store double %50, double* %3
br label %51
51: ; preds = %24, %23
%52 = load double, double* %3
ret double %52
}

LLVM IR (-O2):
@GMP_RNDN = global i32 0
define double @countULP(i32 %0, i32 %1) {
%3 = alloca i64
%4 = tail call i32 @mpfr_inits(i32 undef, i32 undef, i32* null)
%5 = load i32, i32* @GMP_RNDN
%6 = tail call double @mpfr_get_d(i32 %1, i32 %5)
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i64 @mpfr_cmp_d(i32 %0, i32 0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8, %2
%12 = bitcast i64* %3 to i8*
%13 = load i32, i32* @GMP_RNDN
%14 = call i32 @mpfr_get_d_2exp(i64* %3, i32 %1, i32 %13)
%15 = load i64, i64* %3
%16 = add nsw i64 %15, -53
%17 = load i32, i32* @GMP_RNDN
%18 = call i32 @mpfr_set_ui_2exp(i32 undef, i32 1, i64 %16, i32 %17)
%19 = load i32, i32* @GMP_RNDN
%20 = call i32 @mpfr_sub(i32 undef, i32 %0, i32 %1, i32 %19)
%21 = load i32, i32* @GMP_RNDN
%22 = call i32 @mpfr_div(i32 undef, i32 undef, i32 undef, i32 %21)
%23 = load i32, i32* @GMP_RNDN
%24 = call double @mpfr_get_d(i32 undef, i32 %23)
%25 = call double @llvm.fabs.f64(double %24)
%26 = call i32 @mpfr_clears(i32 undef, i32 undef, i32* null)
br label %27
27: ; preds = %8, %11
%28 = phi double [ %25, %11 ], [ 1.000000e+04, %8 ]
ret double %28
}