#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*/ MPFR_RNDN;
int ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
double log(double volatile);
int /*<<< orphan*/ log1p(int);
int /*<<< orphan*/ mpfr_div(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_get_d(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_log(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_d(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_prec(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpfr_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
double nextafter(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double volatile, ...);
int /*<<< orphan*/ stdout;
int main(void) {
  mpfr_t p, q, r;
  mpfr_init(p);
  mpfr_set_prec(p, 200);
  mpfr_init(q);
  mpfr_set_prec(q, 200);
  mpfr_init(r);
  mpfr_set_prec(r, 200);
  mpfr_set_d(p, .49999, MPFR_RNDN);
  mpfr_set_d(q, 1, MPFR_RNDN);
  mpfr_sub(r, q, p, MPFR_RNDN);
  mpfr_div(q, p, r, MPFR_RNDN);
  mpfr_log(r, q, MPFR_RNDN);
  mpfr_printf("mpfr 200-bit\t%.128Rg\n", r);
  printf("mpfr 53-bit\t%.17g\n", nextafter(mpfr_get_d(r, MPFR_RNDN), 0), 0);
  volatile double p0 = .49999;
  printf("log1p\t\t%.17g\n", nextafter(-log1p((1 - 2 * p0) / p0), 0));
  volatile double x = (1 - 2 * p0) / p0;
  volatile double xp1 = x + 1;
  printf("Goldberg\t%.17g\n", -x * log(xp1) / (xp1 - 1));
  printf("naive\t\t%.17g\n", log(p0 / (1 - p0)));
  fflush(stdout);
  return ferror(stdout);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <mpfr_init@plt>
mov    -0x8(%rbp),%edi
mov    $0xc8,%esi
call   1080 <mpfr_set_prec@plt>
mov    -0xc(%rbp),%edi
call   1040 <mpfr_init@plt>
mov    -0xc(%rbp),%edi
mov    $0xc8,%esi
call   1080 <mpfr_set_prec@plt>
mov    -0x10(%rbp),%edi
call   1040 <mpfr_init@plt>
mov    -0x10(%rbp),%edi
mov    $0xc8,%esi
call   1080 <mpfr_set_prec@plt>
mov    -0x8(%rbp),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <mpfr_set_d@plt>
mov    -0xc(%rbp),%edi
mov    0x2d9d(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1070 <mpfr_set_d@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    0x2d81(%rip),%rax
mov    (%rax),%ecx
call   1030 <mpfr_sub@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    0x2d6a(%rip),%rax
mov    (%rax),%ecx
call   10c0 <mpfr_div@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2d56(%rip),%rax
mov    (%rax),%edx
call   10a0 <mpfr_log@plt>
mov    -0x10(%rbp),%esi
lea    0xd6d(%rip),%rdi
call   10b0 <mpfr_printf@plt>
mov    -0x10(%rbp),%edi
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
call   1060 <mpfr_get_d@plt>
mov    %eax,%edi
xor    %esi,%esi
call   10e0 <nextafter@plt>
lea    0xd5d(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1090 <printf@plt>
movsd  0xd2e(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xd10(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1100 <log1p@plt>
xor    %edi,%edi
sub    %eax,%edi
xor    %esi,%esi
call   10e0 <nextafter@plt>
lea    0xd21(%rip),%rdi
mov    $0x1,%al
call   1090 <printf@plt>
movsd  -0x18(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xcd0(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xcb1(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   10f0 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xc64(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
lea    0xc9c(%rip),%rdi
mov    $0x1,%al
call   1090 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  0xc3c(%rip),%xmm1
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   10f0 <log@plt>
lea    0xc7f(%rip),%rdi
mov    $0x1,%al
call   1090 <printf@plt>
mov    0x2bf2(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    0x2be4(%rip),%rax
mov    (%rax),%edi
call   1050 <ferror@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
call   1040 <mpfr_init@plt>
mov    $0xc8,%esi
call   1080 <mpfr_set_prec@plt>
call   1040 <mpfr_init@plt>
mov    $0xc8,%esi
call   1080 <mpfr_set_prec@plt>
call   1040 <mpfr_init@plt>
mov    $0xc8,%esi
call   1080 <mpfr_set_prec@plt>
mov    0x2dcf(%rip),%rbx
mov    (%rbx),%edx
xor    %esi,%esi
call   1070 <mpfr_set_d@plt>
mov    (%rbx),%edx
mov    $0x1,%esi
call   1070 <mpfr_set_d@plt>
mov    (%rbx),%ecx
call   1030 <mpfr_sub@plt>
mov    (%rbx),%ecx
call   10c0 <mpfr_div@plt>
mov    (%rbx),%edx
call   10a0 <mpfr_log@plt>
lea    0xdd6(%rip),%rdi
call   10b0 <mpfr_printf@plt>
mov    (%rbx),%esi
call   1060 <mpfr_get_d@plt>
mov    %eax,%edi
xor    %esi,%esi
call   10e0 <nextafter@plt>
lea    0xdd0(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1090 <printf@plt>
movabs $0x3fdfffd60e94ee39,%rax
ff df 3f
mov    %rax,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xd70(%rip),%xmm1
subsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
cvttsd2si %xmm1,%edi
call   1100 <log1p@plt>
neg    %eax
mov    %eax,%edi
xor    %esi,%esi
call   10e0 <nextafter@plt>
lea    0xd94(%rip),%rdi
mov    $0x1,%al
call   1090 <printf@plt>
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xd32(%rip),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x18(%rsp),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
xorps  0xd11(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   10f0 <log@plt>
mulsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  0xce5(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd29(%rip),%rdi
mov    $0x1,%al
call   1090 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xcbd(%rip),%xmm1
subsd  0x8(%rsp),%xmm1
divsd  %xmm1,%xmm0
call   10f0 <log@plt>
lea    0xd0e(%rip),%rdi
mov    $0x1,%al
call   1090 <printf@plt>
mov    0x2c71(%rip),%rbx
mov    (%rbx),%edi
call   10d0 <fflush@plt>
mov    (%rbx),%edi
add    $0x30,%rsp
pop    %rbx
jmp    1050 <ferror@plt>

LLVM IR (-O0):
@MPFR_RNDN = global i32 0
@.str = [22 x i8] c"mpfr 200-bit\09%.128Rg\0A\00"
@.str.1 = [19 x i8] c"mpfr 53-bit\09%.17g\0A\00"
@.str.2 = [14 x i8] c"log1p\09\09%.17g\0A\00"
@.str.3 = [16 x i8] c"Goldberg\09%.17g\0A\00"
@.str.4 = [14 x i8] c"naive\09\09%.17g\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 0, i32* %1
%8 = load i32, i32* %2
%9 = call i32 @mpfr_init(i32 %8)
%10 = load i32, i32* %2
%11 = call i32 @mpfr_set_prec(i32 %10, i32 200)
%12 = load i32, i32* %3
%13 = call i32 @mpfr_init(i32 %12)
%14 = load i32, i32* %3
%15 = call i32 @mpfr_set_prec(i32 %14, i32 200)
%16 = load i32, i32* %4
%17 = call i32 @mpfr_init(i32 %16)
%18 = load i32, i32* %4
%19 = call i32 @mpfr_set_prec(i32 %18, i32 200)
%20 = load i32, i32* %2
%21 = load i32, i32* @MPFR_RNDN
%22 = call i32 @mpfr_set_d(i32 %20, i32 0, i32 %21)
%23 = load i32, i32* %3
%24 = load i32, i32* @MPFR_RNDN
%25 = call i32 @mpfr_set_d(i32 %23, i32 1, i32 %24)
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = load i32, i32* %2
%29 = load i32, i32* @MPFR_RNDN
%30 = call i32 @mpfr_sub(i32 %26, i32 %27, i32 %28, i32 %29)
%31 = load i32, i32* %3
%32 = load i32, i32* %2
%33 = load i32, i32* %4
%34 = load i32, i32* @MPFR_RNDN
%35 = call i32 @mpfr_div(i32 %31, i32 %32, i32 %33, i32 %34)
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = load i32, i32* @MPFR_RNDN
%39 = call i32 @mpfr_log(i32 %36, i32 %37, i32 %38)
%40 = load i32, i32* %4
%41 = call i32 @mpfr_printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %4
%43 = load i32, i32* @MPFR_RNDN
%44 = call i32 @mpfr_get_d(i32 %42, i32 %43)
%45 = call double @nextafter(i32 %44, i32 0)
%46 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %45, i32 0)
store volatile double 4.999900e-01, double* %5
%47 = load volatile double, double* %5
%48 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %47, double 1.000000e+00)
%49 = load volatile double, double* %5
%50 = fdiv double %48, %49
%51 = fptosi double %50 to i32
%52 = call i32 @log1p(i32 %51)
%53 = sub nsw i32 0, %52
%54 = call double @nextafter(i32 %53, i32 0)
%55 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %54)
%56 = load volatile double, double* %5
%57 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %56, double 1.000000e+00)
%58 = load volatile double, double* %5
%59 = fdiv double %57, %58
store volatile double %59, double* %6
%60 = load volatile double, double* %6
%61 = fadd double %60, 1.000000e+00
store volatile double %61, double* %7
%62 = load volatile double, double* %6
%63 = fneg double %62
%64 = load volatile double, double* %7
%65 = call double @log(double %64)
%66 = fmul double %63, %65
%67 = load volatile double, double* %7
%68 = fsub double %67, 1.000000e+00
%69 = fdiv double %66, %68
%70 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), double %69)
%71 = load volatile double, double* %5
%72 = load volatile double, double* %5
%73 = fsub double 1.000000e+00, %72
%74 = fdiv double %71, %73
%75 = call double @log(double %74)
%76 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %75)
%77 = load i32, i32* @stdout
%78 = call i32 @fflush(i32 %77)
%79 = load i32, i32* @stdout
%80 = call i32 @ferror(i32 %79)
ret i32 %80
}

LLVM IR (-O2):
@MPFR_RNDN = global i32 0
@.str = [22 x i8] c"mpfr 200-bit\09%.128Rg\0A\00"
@.str.1 = [19 x i8] c"mpfr 53-bit\09%.17g\0A\00"
@.str.2 = [14 x i8] c"log1p\09\09%.17g\0A\00"
@.str.3 = [16 x i8] c"Goldberg\09%.17g\0A\00"
@.str.4 = [14 x i8] c"naive\09\09%.17g\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = tail call i32 @mpfr_init(i32 undef)
%5 = tail call i32 @mpfr_set_prec(i32 undef, i32 200)
%6 = tail call i32 @mpfr_init(i32 undef)
%7 = tail call i32 @mpfr_set_prec(i32 undef, i32 200)
%8 = tail call i32 @mpfr_init(i32 undef)
%9 = tail call i32 @mpfr_set_prec(i32 undef, i32 200)
%10 = load i32, i32* @MPFR_RNDN
%11 = tail call i32 @mpfr_set_d(i32 undef, i32 0, i32 %10)
%12 = load i32, i32* @MPFR_RNDN
%13 = tail call i32 @mpfr_set_d(i32 undef, i32 1, i32 %12)
%14 = load i32, i32* @MPFR_RNDN
%15 = tail call i32 @mpfr_sub(i32 undef, i32 undef, i32 undef, i32 %14)
%16 = load i32, i32* @MPFR_RNDN
%17 = tail call i32 @mpfr_div(i32 undef, i32 undef, i32 undef, i32 %16)
%18 = load i32, i32* @MPFR_RNDN
%19 = tail call i32 @mpfr_log(i32 undef, i32 undef, i32 %18)
%20 = tail call i32 @mpfr_printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 undef)
%21 = load i32, i32* @MPFR_RNDN
%22 = tail call i32 @mpfr_get_d(i32 undef, i32 %21)
%23 = tail call double @nextafter(i32 %22, i32 0)
%24 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %23, i32 0)
%25 = bitcast double* %1 to i8*
store volatile double 4.999900e-01, double* %1
%26 = load volatile double, double* %1
%27 = tail call double @llvm.fmuladd.f64(double %26, double -2.000000e+00, double 1.000000e+00)
%28 = load volatile double, double* %1
%29 = fdiv double %27, %28
%30 = fptosi double %29 to i32
%31 = tail call i32 @log1p(i32 %30)
%32 = sub nsw i32 0, %31
%33 = tail call double @nextafter(i32 %32, i32 0)
%34 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %33)
%35 = bitcast double* %2 to i8*
%36 = load volatile double, double* %1
%37 = tail call double @llvm.fmuladd.f64(double %36, double -2.000000e+00, double 1.000000e+00)
%38 = load volatile double, double* %1
%39 = fdiv double %37, %38
store volatile double %39, double* %2
%40 = bitcast double* %3 to i8*
%41 = load volatile double, double* %2
%42 = fadd double %41, 1.000000e+00
store volatile double %42, double* %3
%43 = load volatile double, double* %2
%44 = fneg double %43
%45 = load volatile double, double* %3
%46 = tail call double @log(double %45)
%47 = fmul double %46, %44
%48 = load volatile double, double* %3
%49 = fadd double %48, -1.000000e+00
%50 = fdiv double %47, %49
%51 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), double %50)
%52 = load volatile double, double* %1
%53 = load volatile double, double* %1
%54 = fsub double 1.000000e+00, %53
%55 = fdiv double %52, %54
%56 = tail call double @log(double %55)
%57 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %56)
%58 = load i32, i32* @stdout
%59 = tail call i32 @fflush(i32 %58)
%60 = load i32, i32* @stdout
%61 = tail call i32 @ferror(i32 %60)
ret i32 %61
}