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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fp_log2(int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ fp_log_m1(int /*<<< orphan*/, int /*<<< orphan*/,
                             unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double);
int /*<<< orphan*/ mpf_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/);
scalar_t__ mpf_cmp_d(int /*<<< orphan*/, double);
scalar_t__ mpf_cmp_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_div_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
double mpf_get_d(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/, double);
int /*<<< orphan*/ mpf_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_neg(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_set(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_ui_div(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_ui_sub(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void fp_log(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);
  mpf_set(zee, z);
  int nexp = 0;
  if (mpf_cmp_ui(zee, 0) <= 0) {
    fprintf(stderr, "Error: bad domain for fp_log: log(%g)\n", mpf_get_d(zee));
    mpf_clear(zee);
    exit(1);
  }
  while (mpf_cmp_ui(zee, 2) > 0) {
    nexp++;
    mpf_div_ui(zee, zee, 2);
  }
  while (mpf_cmp_ui(zee, 1) < 0) {
    nexp--;
    mpf_mul_ui(zee, zee, 2);
  }
  if (mpf_cmp_d(zee, 1.618) > 0) {
    mpf_ui_div(zee, 1, zee);
    mpf_ui_sub(zee, 1, zee);
    fp_log_m1(lg, zee, prec);
  } else {
    mpf_ui_sub(zee, 1, zee);
    fp_log_m1(lg, zee, prec);
    mpf_neg(lg, lg);
  }
  if (0 != nexp) {
    fp_log2(zee, prec);
    if (0 > nexp) {
      mpf_mul_ui(zee, zee, -nexp);
      mpf_neg(zee, zee);
    } else {
      mpf_mul_ui(zee, zee, nexp);
    }
    mpf_add(lg, lg, zee);
  }
  mpf_clear(zee);
}


x86 assembly (clang, -O0):
<fp_log>:
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  0xddf(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xddb(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   1110 <mpf_init2@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10a0 <mpf_set@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1120 <mpf_cmp_ui@plt>
cmp    $0x0,%rax
jg     129e <fp_log+0x9e>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   10e0 <mpf_get_d@plt>
mov    -0x24(%rbp),%edi
lea    0xd91(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <mpf_clear@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    12a3 <fp_log+0xa3>
mov    -0x1c(%rbp),%edi
mov    $0x2,%esi
call   1120 <mpf_cmp_ui@plt>
cmp    $0x0,%rax
jle    12d8 <fp_log+0xd8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x2,%edx
call   10b0 <mpf_div_ui@plt>
jmp    12a3 <fp_log+0xa3>
jmp    12dd <fp_log+0xdd>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1120 <mpf_cmp_ui@plt>
cmp    $0x0,%rax
jge    1312 <fp_log+0x112>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x2,%edx
call   10c0 <mpf_mul_ui@plt>
jmp    12dd <fp_log+0xdd>
mov    -0x1c(%rbp),%edi
movsd  0xcf3(%rip),%xmm0
call   1070 <mpf_cmp_d@plt>
cmp    $0x0,%rax
jle    135f <fp_log+0x15f>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    $0x1,%esi
call   1040 <mpf_ui_div@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    $0x1,%esi
call   10d0 <mpf_ui_sub@plt>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <fp_log_m1@plt>
jmp    1388 <fp_log+0x188>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    $0x1,%esi
call   10d0 <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>
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
je     13e5 <fp_log+0x1e5>
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   10f0 <fp_log2@plt>
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
jle    13c9 <fp_log+0x1c9>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
xor    %edx,%edx
sub    -0x20(%rbp),%edx
call   10c0 <mpf_mul_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <mpf_neg@plt>
jmp    13d7 <fp_log+0x1d7>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10c0 <mpf_mul_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1060 <mpf_add@plt>
mov    -0x1c(%rbp),%edi
call   1090 <mpf_clear@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_log>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %edx,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xde6(%rip),%xmm0
addsd  0xde6(%rip),%xmm0
call   1110 <mpf_init2@plt>
mov    %ebx,%esi
call   10a0 <mpf_set@plt>
xor    %ebx,%ebx
xor    %esi,%esi
call   1120 <mpf_cmp_ui@plt>
test   %rax,%rax
jle    1326 <fp_log+0x126>
mov    $0x2,%esi
call   1120 <mpf_cmp_ui@plt>
test   %rax,%rax
jle    128d <fp_log+0x8d>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    $0x2,%edx
call   10b0 <mpf_div_ui@plt>
mov    $0x2,%esi
call   1120 <mpf_cmp_ui@plt>
test   %rax,%rax
jg     1260 <fp_log+0x60>
jmp    128d <fp_log+0x8d>
xchg   %ax,%ax
add    $0xffffffff,%ebx
mov    $0x2,%edx
call   10c0 <mpf_mul_ui@plt>
mov    $0x1,%esi
call   1120 <mpf_cmp_ui@plt>
test   %rax,%rax
js     1280 <fp_log+0x80>
movsd  0xd6c(%rip),%xmm0
call   1070 <mpf_cmp_d@plt>
mov    $0x1,%esi
test   %rax,%rax
jle    12d2 <fp_log+0xd2>
call   1040 <mpf_ui_div@plt>
mov    $0x1,%esi
call   10d0 <mpf_ui_sub@plt>
mov    %r14d,%edi
mov    %ebp,%edx
call   1030 <fp_log_m1@plt>
test   %ebx,%ebx
jne    12f0 <fp_log+0xf0>
jmp    131d <fp_log+0x11d>
call   10d0 <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>
test   %ebx,%ebx
je     131d <fp_log+0x11d>
mov    %ebp,%esi
call   10f0 <fp_log2@plt>
test   %ebx,%ebx
js     1304 <fp_log+0x104>
mov    %ebx,%edx
call   10c0 <mpf_mul_ui@plt>
jmp    1312 <fp_log+0x112>
neg    %ebx
mov    %ebx,%edx
call   10c0 <mpf_mul_ui@plt>
call   1050 <mpf_neg@plt>
mov    %r14d,%edi
mov    %r14d,%esi
call   1060 <mpf_add@plt>
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <mpf_clear@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%ebx
call   10e0 <mpf_get_d@plt>
lea    0xcdd(%rip),%rsi
mov    %ebx,%edi
call   1080 <fprintf@plt>
call   1090 <mpf_clear@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Error: bad domain for fp_log: log(%g)\0A\00"
define void @fp_log(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = uitofp i32 %10 to double
%12 = call double @llvm.fmuladd.f64(double %11, double 3.322000e+00, double 5.000000e+01)
store double %12, double* %7
%13 = load i32, i32* %8
%14 = load double, double* %7
%15 = call i32 @mpf_init2(i32 %13, double %14)
%16 = load i32, i32* %8
%17 = load i32, i32* %5
%18 = call i32 @mpf_set(i32 %16, i32 %17)
store i32 0, i32* %9
%19 = load i32, i32* %8
%20 = call i64 @mpf_cmp_ui(i32 %19, i32 0)
%21 = icmp sle i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %3
%23 = load i32, i32* @stderr
%24 = load i32, i32* %8
%25 = call double @mpf_get_d(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), double %25)
%27 = load i32, i32* %8
%28 = call i32 @mpf_clear(i32 %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %3
br label %31
31: ; preds = %35, %30
%32 = load i32, i32* %8
%33 = call i64 @mpf_cmp_ui(i32 %32, i32 2)
%34 = icmp sgt i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
%38 = load i32, i32* %8
%39 = load i32, i32* %8
%40 = call i32 @mpf_div_ui(i32 %38, i32 %39, i32 2)
br label %31
41: ; preds = %31
br label %42
42: ; preds = %46, %41
%43 = load i32, i32* %8
%44 = call i64 @mpf_cmp_ui(i32 %43, i32 1)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i32, i32* %9
%48 = add nsw i32 %47, -1
store i32 %48, i32* %9
%49 = load i32, i32* %8
%50 = load i32, i32* %8
%51 = call i32 @mpf_mul_ui(i32 %49, i32 %50, i32 2)
br label %42
52: ; preds = %42
%53 = load i32, i32* %8
%54 = call i64 @mpf_cmp_d(i32 %53, double 1.618000e+00)
%55 = icmp sgt i64 %54, 0
br i1 %55, label %56, label %67
56: ; preds = %52
%57 = load i32, i32* %8
%58 = load i32, i32* %8
%59 = call i32 @mpf_ui_div(i32 %57, i32 1, i32 %58)
%60 = load i32, i32* %8
%61 = load i32, i32* %8
%62 = call i32 @mpf_ui_sub(i32 %60, i32 1, i32 %61)
%63 = load i32, i32* %4
%64 = load i32, i32* %8
%65 = load i32, i32* %6
%66 = call i32 @fp_log_m1(i32 %63, i32 %64, i32 %65)
br label %78
67: ; preds = %52
%68 = load i32, i32* %8
%69 = load i32, i32* %8
%70 = call i32 @mpf_ui_sub(i32 %68, i32 1, i32 %69)
%71 = load i32, i32* %4
%72 = load i32, i32* %8
%73 = load i32, i32* %6
%74 = call i32 @fp_log_m1(i32 %71, i32 %72, i32 %73)
%75 = load i32, i32* %4
%76 = load i32, i32* %4
%77 = call i32 @mpf_neg(i32 %75, i32 %76)
br label %78
78: ; preds = %67, %56
%79 = load i32, i32* %9
%80 = icmp ne i32 0, %79
br i1 %80, label %81, label %106
81: ; preds = %78
%82 = load i32, i32* %8
%83 = load i32, i32* %6
%84 = call i32 @fp_log2(i32 %82, i32 %83)
%85 = load i32, i32* %9
%86 = icmp sgt i32 0, %85
br i1 %86, label %87, label %96
87: ; preds = %81
%88 = load i32, i32* %8
%89 = load i32, i32* %8
%90 = load i32, i32* %9
%91 = sub nsw i32 0, %90
%92 = call i32 @mpf_mul_ui(i32 %88, i32 %89, i32 %91)
%93 = load i32, i32* %8
%94 = load i32, i32* %8
%95 = call i32 @mpf_neg(i32 %93, i32 %94)
br label %101
96: ; preds = %81
%97 = load i32, i32* %8
%98 = load i32, i32* %8
%99 = load i32, i32* %9
%100 = call i32 @mpf_mul_ui(i32 %97, i32 %98, i32 %99)
br label %101
101: ; preds = %96, %87
%102 = load i32, i32* %4
%103 = load i32, i32* %4
%104 = load i32, i32* %8
%105 = call i32 @mpf_add(i32 %102, i32 %103, i32 %104)
br label %106
106: ; preds = %101, %78
%107 = load i32, i32* %8
%108 = call i32 @mpf_clear(i32 %107)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Error: bad domain for fp_log: log(%g)\0A\00"
define void @fp_log(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_set(i32 undef, i32 %1)
%8 = tail call i64 @mpf_cmp_ui(i32 undef, i32 0)
%9 = icmp slt i64 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = tail call i64 @mpf_cmp_ui(i32 undef, i32 2)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %23, label %19
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = tail call double @mpf_get_d(i32 undef)
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), double %15)
%17 = tail call i32 @mpf_clear(i32 undef)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %23, %10
%20 = phi i32 [ 0, %10 ], [ %25, %23 ]
%21 = tail call i64 @mpf_cmp_ui(i32 undef, i32 1)
%22 = icmp slt i64 %21, 0
br i1 %22, label %29, label %35
23: ; preds = %10, %23
%24 = phi i32 [ %25, %23 ], [ 0, %10 ]
%25 = add nuw nsw i32 %24, 1
%26 = tail call i32 @mpf_div_ui(i32 undef, i32 undef, i32 2)
%27 = tail call i64 @mpf_cmp_ui(i32 undef, i32 2)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %23, label %19
29: ; preds = %19, %29
%30 = phi i32 [ %31, %29 ], [ %20, %19 ]
%31 = add nsw i32 %30, -1
%32 = tail call i32 @mpf_mul_ui(i32 undef, i32 undef, i32 2)
%33 = tail call i64 @mpf_cmp_ui(i32 undef, i32 1)
%34 = icmp slt i64 %33, 0
br i1 %34, label %29, label %35
35: ; preds = %29, %19
%36 = phi i32 [ %20, %19 ], [ %31, %29 ]
%37 = tail call i64 @mpf_cmp_d(i32 undef, double 1.618000e+00)
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = tail call i32 @mpf_ui_div(i32 undef, i32 1, i32 undef)
%41 = tail call i32 @mpf_ui_sub(i32 undef, i32 1, i32 undef)
%42 = tail call i32 @fp_log_m1(i32 %0, i32 undef, i32 %2)
br label %47
43: ; preds = %35
%44 = tail call i32 @mpf_ui_sub(i32 undef, i32 1, i32 undef)
%45 = tail call i32 @fp_log_m1(i32 %0, i32 undef, i32 %2)
%46 = tail call i32 @mpf_neg(i32 %0, i32 %0)
br label %47
47: ; preds = %43, %39
%48 = icmp eq i32 %36, 0
br i1 %48, label %60, label %49
49: ; preds = %47
%50 = tail call i32 @fp_log2(i32 undef, i32 %2)
%51 = icmp slt i32 %36, 0
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = sub nsw i32 0, %36
%54 = tail call i32 @mpf_mul_ui(i32 undef, i32 undef, i32 %53)
%55 = tail call i32 @mpf_neg(i32 undef, i32 undef)
br label %58
56: ; preds = %49
%57 = tail call i32 @mpf_mul_ui(i32 undef, i32 undef, i32 %36)
br label %58
58: ; preds = %56, %52
%59 = tail call i32 @mpf_add(i32 %0, i32 %0, i32 undef)
br label %60
60: ; preds = %58, %47
%61 = tail call i32 @mpf_clear(i32 undef)
ret void
}