#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*/ const mpf_t;
typedef double mp_bitcnt_t;

/* Variables and functions */
int /*<<< orphan*/ fp_epsilon(int /*<<< orphan*/ const, unsigned int);
int /*<<< orphan*/ mpf_abs(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_add(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/ const);
scalar_t__ mpf_cmp(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_div_ui(int /*<<< orphan*/ const,
                              int /*<<< orphan*/ const, unsigned int);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/ const, double);
int /*<<< orphan*/ mpf_mul(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_set(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
void fp_log_m1(mpf_t lg, const mpf_t z, unsigned int prec) {
  mp_bitcnt_t bits = ((double)prec) * 3.322 + 50;
  mpf_t zee, z_n, term;
  mpf_init2(zee, bits);
  mpf_init2(z_n, bits);
  mpf_init2(term, bits);
  mpf_set(zee, z);
  mpf_mul(z_n, zee, zee);
  mpf_set(lg, zee);
  mpf_t maxterm;
  mpf_init2(maxterm, bits);
  fp_epsilon(maxterm, prec);
  unsigned int n = 2;
  while (1) {
    mpf_div_ui(term, z_n, n);
    mpf_add(lg, lg, term);
    mpf_abs(term, term);
    if (mpf_cmp(term, maxterm) < 0)
      break;
    n++;
    mpf_mul(z_n, z_n, zee);
  }
  mpf_clear(zee);
  mpf_clear(z_n);
  mpf_clear(term);
  mpf_clear(maxterm);
}


x86 assembly (clang, -O0):
<fp_log_m1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe4f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe4b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10b0 <mpf_init2@plt>
mov    -0x20(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10b0 <mpf_init2@plt>
mov    -0x24(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10b0 <mpf_init2@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <mpf_set@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   10a0 <mpf_mul@plt>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1080 <mpf_set@plt>
mov    -0x28(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10b0 <mpf_init2@plt>
mov    -0x28(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <fp_epsilon@plt>
movl   $0x2,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1090 <mpf_div_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1060 <mpf_add@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <mpf_abs@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <mpf_cmp@plt>
cmp    $0x0,%rax
jge    1271 <fp_log_m1+0xe1>
jmp    128d <fp_log_m1+0xfd>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   10a0 <mpf_mul@plt>
jmp    1230 <fp_log_m1+0xa0>
mov    -0x1c(%rbp),%edi
call   1070 <mpf_clear@plt>
mov    -0x20(%rbp),%edi
call   1070 <mpf_clear@plt>
mov    -0x24(%rbp),%edi
call   1070 <mpf_clear@plt>
mov    -0x28(%rbp),%edi
call   1070 <mpf_clear@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_log_m1>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%ebx
mov    %edx,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xe52(%rip),%xmm0
addsd  0xe52(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   10b0 <mpf_init2@plt>
movsd  0x8(%rsp),%xmm0
call   10b0 <mpf_init2@plt>
movsd  0x8(%rsp),%xmm0
call   10b0 <mpf_init2@plt>
mov    %r14d,%esi
call   1080 <mpf_set@plt>
call   10a0 <mpf_mul@plt>
mov    %ebx,%edi
call   1080 <mpf_set@plt>
movsd  0x8(%rsp),%xmm0
call   10b0 <mpf_init2@plt>
mov    %ebp,%esi
call   1050 <fp_epsilon@plt>
mov    $0x2,%edx
call   1090 <mpf_div_ui@plt>
mov    %ebx,%edi
mov    %ebx,%esi
call   1060 <mpf_add@plt>
call   1030 <mpf_abs@plt>
call   1040 <mpf_cmp@plt>
test   %rax,%rax
js     1257 <fp_log_m1+0xc7>
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   10a0 <mpf_mul@plt>
mov    %ebp,%edx
call   1090 <mpf_div_ui@plt>
mov    %ebx,%edi
mov    %ebx,%esi
call   1060 <mpf_add@plt>
call   1030 <mpf_abs@plt>
call   1040 <mpf_cmp@plt>
add    $0x1,%ebp
test   %rax,%rax
jns    1230 <fp_log_m1+0xa0>
call   1070 <mpf_clear@plt>
call   1070 <mpf_clear@plt>
call   1070 <mpf_clear@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <mpf_clear@plt>

LLVM IR (-O0):
define void @fp_log_m1(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* %6
%14 = uitofp i32 %13 to double
%15 = call double @llvm.fmuladd.f64(double %14, double 3.322000e+00, double 5.000000e+01)
store double %15, double* %7
%16 = load i32, i32* %8
%17 = load double, double* %7
%18 = call i32 @mpf_init2(i32 %16, double %17)
%19 = load i32, i32* %9
%20 = load double, double* %7
%21 = call i32 @mpf_init2(i32 %19, double %20)
%22 = load i32, i32* %10
%23 = load double, double* %7
%24 = call i32 @mpf_init2(i32 %22, double %23)
%25 = load i32, i32* %8
%26 = load i32, i32* %5
%27 = call i32 @mpf_set(i32 %25, i32 %26)
%28 = load i32, i32* %9
%29 = load i32, i32* %8
%30 = load i32, i32* %8
%31 = call i32 @mpf_mul(i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* %4
%33 = load i32, i32* %8
%34 = call i32 @mpf_set(i32 %32, i32 %33)
%35 = load i32, i32* %11
%36 = load double, double* %7
%37 = call i32 @mpf_init2(i32 %35, double %36)
%38 = load i32, i32* %11
%39 = load i32, i32* %6
%40 = call i32 @fp_epsilon(i32 %38, i32 %39)
store i32 2, i32* %12
br label %41
41: ; preds = %3, %58
%42 = load i32, i32* %10
%43 = load i32, i32* %9
%44 = load i32, i32* %12
%45 = call i32 @mpf_div_ui(i32 %42, i32 %43, i32 %44)
%46 = load i32, i32* %4
%47 = load i32, i32* %4
%48 = load i32, i32* %10
%49 = call i32 @mpf_add(i32 %46, i32 %47, i32 %48)
%50 = load i32, i32* %10
%51 = load i32, i32* %10
%52 = call i32 @mpf_abs(i32 %50, i32 %51)
%53 = load i32, i32* %10
%54 = load i32, i32* %11
%55 = call i64 @mpf_cmp(i32 %53, i32 %54)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %41
br label %65
58: ; preds = %41
%59 = load i32, i32* %12
%60 = add i32 %59, 1
store i32 %60, i32* %12
%61 = load i32, i32* %9
%62 = load i32, i32* %9
%63 = load i32, i32* %8
%64 = call i32 @mpf_mul(i32 %61, i32 %62, i32 %63)
br label %41
65: ; preds = %57
%66 = load i32, i32* %8
%67 = call i32 @mpf_clear(i32 %66)
%68 = load i32, i32* %9
%69 = call i32 @mpf_clear(i32 %68)
%70 = load i32, i32* %10
%71 = call i32 @mpf_clear(i32 %70)
%72 = load i32, i32* %11
%73 = call i32 @mpf_clear(i32 %72)
ret void
}

LLVM IR (-O2):
define void @fp_log_m1(i32 %0, i32 %1, i32 %2) {
%4 = uitofp i32 %2 to double
%5 = tail call double @llvm.fmuladd.f64(double %4, double 3.322000e+00, double 5.000000e+01)
%6 = tail call i32 @mpf_init2(i32 undef, double %5)
%7 = tail call i32 @mpf_init2(i32 undef, double %5)
%8 = tail call i32 @mpf_init2(i32 undef, double %5)
%9 = tail call i32 @mpf_set(i32 undef, i32 %1)
%10 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%11 = tail call i32 @mpf_set(i32 %0, i32 undef)
%12 = tail call i32 @mpf_init2(i32 undef, double %5)
%13 = tail call i32 @fp_epsilon(i32 undef, i32 %2)
%14 = tail call i32 @mpf_div_ui(i32 undef, i32 undef, i32 2)
%15 = tail call i32 @mpf_add(i32 %0, i32 %0, i32 undef)
%16 = tail call i32 @mpf_abs(i32 undef, i32 undef)
%17 = tail call i64 @mpf_cmp(i32 undef, i32 undef)
%18 = icmp slt i64 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %3, %19
%20 = phi i32 [ %21, %19 ], [ 2, %3 ]
%21 = add i32 %20, 1
%22 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%23 = tail call i32 @mpf_div_ui(i32 undef, i32 undef, i32 %21)
%24 = tail call i32 @mpf_add(i32 %0, i32 %0, i32 undef)
%25 = tail call i32 @mpf_abs(i32 undef, i32 undef)
%26 = tail call i64 @mpf_cmp(i32 undef, i32 undef)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %19
28: ; preds = %19, %3
%29 = tail call i32 @mpf_clear(i32 undef)
%30 = tail call i32 @mpf_clear(i32 undef)
%31 = tail call i32 @mpf_clear(i32 undef)
%32 = tail call i32 @mpf_clear(i32 undef)
ret void
}