#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*/ fp_e(int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ fp_exp_helper(int /*<<< orphan*/, int /*<<< orphan*/,
                                 unsigned int);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/);
scalar_t__ mpf_cmp_d(int /*<<< orphan*/, double);
int /*<<< orphan*/ mpf_div(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_floor(int /*<<< orphan*/, int /*<<< orphan*/);
long mpf_get_si(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/, double);
int /*<<< orphan*/ mpf_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_pow_ui(int /*<<< orphan*/, int /*<<< orphan*/, long);
int /*<<< orphan*/ mpf_set(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
void fp_exp(mpf_t ex, const mpf_t z, unsigned int prec) {
  mp_bitcnt_t bits = ((double)prec) * 3.3219281 + 50;
  mpf_t zee, zf;
  mpf_init2(zee, bits);
  mpf_init2(zf, bits);
  mpf_set(zee, z);
  mpf_floor(zf, zee);
  mpf_sub(zee, zee, zf);
  long intpart = mpf_get_si(zf);
  if (mpf_cmp_d(zee, 0.5) > 0) {
    mpf_sub_ui(zee, zee, 1);
    intpart++;
  }
  fp_exp_helper(ex, zee, prec);
  if (intpart) {
    fp_e(zee, prec);
    if (0 < intpart) {
      mpf_pow_ui(zf, zee, intpart);
      mpf_mul(ex, ex, zf);
    } else {
      mpf_pow_ui(zf, zee, -intpart);
      mpf_div(ex, ex, zf);
    }
  }
  mpf_clear(zee);
  mpf_clear(zf);
}


x86 assembly (clang, -O0):
<fp_exp>:
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  0xe17(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe13(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10e0 <mpf_init2@plt>
mov    -0x20(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10e0 <mpf_init2@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <mpf_set@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <mpf_floor@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1090 <mpf_sub@plt>
mov    -0x20(%rbp),%edi
call   10d0 <mpf_get_si@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
movsd  0xda5(%rip),%xmm0
call   1060 <mpf_cmp_d@plt>
cmp    $0x0,%rax
jle    1286 <fp_exp+0xb6>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1040 <mpf_sub_ui@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   10f0 <fp_exp_helper@plt>
cmpq   $0x0,-0x28(%rbp)
je     12fe <fp_exp+0x12e>
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <fp_e@plt>
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jge    12d8 <fp_exp+0x108>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   10a0 <mpf_pow_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10b0 <mpf_mul@plt>
jmp    12f9 <fp_exp+0x129>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
sub    -0x28(%rbp),%rdx
call   10a0 <mpf_pow_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10c0 <mpf_div@plt>
jmp    12fe <fp_exp+0x12e>
mov    -0x1c(%rbp),%edi
call   1070 <mpf_clear@plt>
mov    -0x20(%rbp),%edi
call   1070 <mpf_clear@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_exp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %edx,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xe12(%rip),%xmm0
addsd  0xe12(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   10e0 <mpf_init2@plt>
movsd  0x8(%rsp),%xmm0
call   10e0 <mpf_init2@plt>
mov    %ebx,%esi
call   1080 <mpf_set@plt>
call   1030 <mpf_floor@plt>
call   1090 <mpf_sub@plt>
call   10d0 <mpf_get_si@plt>
mov    %rax,%rbx
movsd  0xde3(%rip),%xmm0
call   1060 <mpf_cmp_d@plt>
test   %rax,%rax
jle    1245 <fp_exp+0x75>
mov    $0x1,%edx
call   1040 <mpf_sub_ui@plt>
add    $0x1,%rbx
mov    %r14d,%edi
mov    %ebp,%edx
call   10f0 <fp_exp_helper@plt>
test   %rbx,%rbx
je     128b <fp_exp+0xbb>
mov    %ebp,%esi
call   1050 <fp_e@plt>
test   %rbx,%rbx
jle    1275 <fp_exp+0xa5>
mov    %rbx,%rdx
call   10a0 <mpf_pow_ui@plt>
mov    %r14d,%edi
mov    %r14d,%esi
call   10b0 <mpf_mul@plt>
jmp    128b <fp_exp+0xbb>
neg    %rbx
mov    %rbx,%rdx
call   10a0 <mpf_pow_ui@plt>
mov    %r14d,%edi
mov    %r14d,%esi
call   10c0 <mpf_div@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_exp(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 i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = uitofp i32 %11 to double
%13 = call double @llvm.fmuladd.f64(double %12, double 0x400A934F0A294EAE, double 5.000000e+01)
store double %13, double* %7
%14 = load i32, i32* %8
%15 = load double, double* %7
%16 = call i32 @mpf_init2(i32 %14, double %15)
%17 = load i32, i32* %9
%18 = load double, double* %7
%19 = call i32 @mpf_init2(i32 %17, double %18)
%20 = load i32, i32* %8
%21 = load i32, i32* %5
%22 = call i32 @mpf_set(i32 %20, i32 %21)
%23 = load i32, i32* %9
%24 = load i32, i32* %8
%25 = call i32 @mpf_floor(i32 %23, i32 %24)
%26 = load i32, i32* %8
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = call i32 @mpf_sub(i32 %26, i32 %27, i32 %28)
%30 = load i32, i32* %9
%31 = call i64 @mpf_get_si(i32 %30)
store i64 %31, i64* %10
%32 = load i32, i32* %8
%33 = call i64 @mpf_cmp_d(i32 %32, double 5.000000e-01)
%34 = icmp sgt i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %3
%36 = load i32, i32* %8
%37 = load i32, i32* %8
%38 = call i32 @mpf_sub_ui(i32 %36, i32 %37, i32 1)
%39 = load i64, i64* %10
%40 = add nsw i64 %39, 1
store i64 %40, i64* %10
br label %41
41: ; preds = %35, %3
%42 = load i32, i32* %4
%43 = load i32, i32* %8
%44 = load i32, i32* %6
%45 = call i32 @fp_exp_helper(i32 %42, i32 %43, i32 %44)
%46 = load i64, i64* %10
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %74
48: ; preds = %41
%49 = load i32, i32* %8
%50 = load i32, i32* %6
%51 = call i32 @fp_e(i32 %49, i32 %50)
%52 = load i64, i64* %10
%53 = icmp slt i64 0, %52
br i1 %53, label %54, label %63
54: ; preds = %48
%55 = load i32, i32* %9
%56 = load i32, i32* %8
%57 = load i64, i64* %10
%58 = call i32 @mpf_pow_ui(i32 %55, i32 %56, i64 %57)
%59 = load i32, i32* %4
%60 = load i32, i32* %4
%61 = load i32, i32* %9
%62 = call i32 @mpf_mul(i32 %59, i32 %60, i32 %61)
br label %73
63: ; preds = %48
%64 = load i32, i32* %9
%65 = load i32, i32* %8
%66 = load i64, i64* %10
%67 = sub nsw i64 0, %66
%68 = call i32 @mpf_pow_ui(i32 %64, i32 %65, i64 %67)
%69 = load i32, i32* %4
%70 = load i32, i32* %4
%71 = load i32, i32* %9
%72 = call i32 @mpf_div(i32 %69, i32 %70, i32 %71)
br label %73
73: ; preds = %63, %54
br label %74
74: ; preds = %73, %41
%75 = load i32, i32* %8
%76 = call i32 @mpf_clear(i32 %75)
%77 = load i32, i32* %9
%78 = call i32 @mpf_clear(i32 %77)
ret void
}

LLVM IR (-O2):
define void @fp_exp(i32 %0, i32 %1, i32 %2) {
%4 = uitofp i32 %2 to double
%5 = tail call double @llvm.fmuladd.f64(double %4, double 0x400A934F0A294EAE, 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_set(i32 undef, i32 %1)
%9 = tail call i32 @mpf_floor(i32 undef, i32 undef)
%10 = tail call i32 @mpf_sub(i32 undef, i32 undef, i32 undef)
%11 = tail call i64 @mpf_get_si(i32 undef)
%12 = tail call i64 @mpf_cmp_d(i32 undef, double 5.000000e-01)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = tail call i32 @mpf_sub_ui(i32 undef, i32 undef, i32 1)
%16 = add nsw i64 %11, 1
br label %17
17: ; preds = %14, %3
%18 = phi i64 [ %16, %14 ], [ %11, %3 ]
%19 = tail call i32 @fp_exp_helper(i32 %0, i32 undef, i32 %2)
%20 = icmp eq i64 %18, 0
br i1 %20, label %31, label %21
21: ; preds = %17
%22 = tail call i32 @fp_e(i32 undef, i32 %2)
%23 = icmp sgt i64 %18, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call i32 @mpf_pow_ui(i32 undef, i32 undef, i64 %18)
%26 = tail call i32 @mpf_mul(i32 %0, i32 %0, i32 undef)
br label %31
27: ; preds = %21
%28 = sub nsw i64 0, %18
%29 = tail call i32 @mpf_pow_ui(i32 undef, i32 undef, i64 %28)
%30 = tail call i32 @mpf_div(i32 %0, i32 %0, i32 undef)
br label %31
31: ; preds = %24, %27, %17
%32 = tail call i32 @mpf_clear(i32 undef)
%33 = tail call i32 @mpf_clear(i32 undef)
ret void
}