#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_log_m1(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                             unsigned int);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/ const);
scalar_t__ mpf_cmp_d(int /*<<< orphan*/ const, double);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/ const, double);
int /*<<< orphan*/ mpf_neg(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_ui_div(int /*<<< orphan*/ const, int,
                              int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_ui_sub(int /*<<< orphan*/ const, int,
                              int /*<<< orphan*/ const);
void fp_log_simple(mpf_t lg, const mpf_t z, unsigned int prec) {
  mp_bitcnt_t bits = ((double)prec) * 3.322 + 50;
  mpf_t zee;
  mpf_init2(zee, bits);
  if (mpf_cmp_d(z, 1.618) > 0) {
    mpf_ui_div(zee, 1, z);
    mpf_ui_sub(zee, 1, zee);
    fp_log_m1(lg, zee, prec);
  } else {
    mpf_ui_sub(zee, 1, z);
    fp_log_m1(lg, zee, prec);
    mpf_neg(lg, lg);
  }
  mpf_clear(zee);
}


x86 assembly (clang, -O0):
<fp_log_simple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe77(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe73(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   1090 <mpf_init2@plt>
mov    -0x8(%rbp),%edi
movsd  0xe42(%rip),%xmm0
call   1060 <mpf_cmp_d@plt>
cmp    $0x0,%rax
jle    1200 <fp_log_simple+0x90>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    $0x1,%esi
call   1040 <mpf_ui_div@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    $0x1,%esi
call   1080 <mpf_ui_sub@plt>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <fp_log_m1@plt>
jmp    1229 <fp_log_simple+0xb9>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    $0x1,%esi
call   1080 <mpf_ui_sub@plt>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <fp_log_m1@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <mpf_neg@plt>
mov    -0x1c(%rbp),%edi
call   1070 <mpf_clear@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_log_simple>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %edx,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xe76(%rip),%xmm0
addsd  0xe76(%rip),%xmm0
call   1090 <mpf_init2@plt>
movsd  0xe71(%rip),%xmm0
mov    %ebx,%edi
call   1060 <mpf_cmp_d@plt>
mov    $0x1,%esi
mov    %ebx,%edx
test   %rax,%rax
jle    11cd <fp_log_simple+0x5d>
call   1040 <mpf_ui_div@plt>
mov    $0x1,%esi
call   1080 <mpf_ui_sub@plt>
mov    %r14d,%edi
mov    %ebp,%edx
call   1030 <fp_log_m1@plt>
jmp    11e7 <fp_log_simple+0x77>
call   1080 <mpf_ui_sub@plt>
mov    %r14d,%edi
mov    %ebp,%edx
call   1030 <fp_log_m1@plt>
mov    %r14d,%edi
mov    %r14d,%esi
call   1050 <mpf_neg@plt>
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <mpf_clear@plt>

LLVM IR (-O0):
define void @fp_log_simple(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = uitofp i32 %9 to double
%11 = call double @llvm.fmuladd.f64(double %10, double 3.322000e+00, double 5.000000e+01)
store double %11, double* %7
%12 = load i32, i32* %8
%13 = load double, double* %7
%14 = call i32 @mpf_init2(i32 %12, double %13)
%15 = load i32, i32* %5
%16 = call i64 @mpf_cmp_d(i32 %15, double 1.618000e+00)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %3
%19 = load i32, i32* %8
%20 = load i32, i32* %5
%21 = call i32 @mpf_ui_div(i32 %19, i32 1, i32 %20)
%22 = load i32, i32* %8
%23 = load i32, i32* %8
%24 = call i32 @mpf_ui_sub(i32 %22, i32 1, i32 %23)
%25 = load i32, i32* %4
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = call i32 @fp_log_m1(i32 %25, i32 %26, i32 %27)
br label %40
29: ; preds = %3
%30 = load i32, i32* %8
%31 = load i32, i32* %5
%32 = call i32 @mpf_ui_sub(i32 %30, i32 1, i32 %31)
%33 = load i32, i32* %4
%34 = load i32, i32* %8
%35 = load i32, i32* %6
%36 = call i32 @fp_log_m1(i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* %4
%38 = load i32, i32* %4
%39 = call i32 @mpf_neg(i32 %37, i32 %38)
br label %40
40: ; preds = %29, %18
%41 = load i32, i32* %8
%42 = call i32 @mpf_clear(i32 %41)
ret void
}

LLVM IR (-O2):
define void @fp_log_simple(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 i64 @mpf_cmp_d(i32 %1, double 1.618000e+00)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = tail call i32 @mpf_ui_div(i32 undef, i32 1, i32 %1)
%11 = tail call i32 @mpf_ui_sub(i32 undef, i32 1, i32 undef)
%12 = tail call i32 @fp_log_m1(i32 %0, i32 undef, i32 %2)
br label %17
13: ; preds = %3
%14 = tail call i32 @mpf_ui_sub(i32 undef, i32 1, i32 %1)
%15 = tail call i32 @fp_log_m1(i32 %0, i32 undef, i32 %2)
%16 = tail call i32 @mpf_neg(i32 %0, i32 %0)
br label %17
17: ; preds = %13, %9
%18 = tail call i32 @mpf_clear(i32 undef)
ret void
}