#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*/ fp_inv_factorial(int /*<<< orphan*/ const, unsigned int,
                                    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_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);
int /*<<< orphan*/ mpf_set_ui(int /*<<< orphan*/ const, int);
void fp_exp_helper(mpf_t ex, const mpf_t z, unsigned int prec) {
  mpf_t zee, z_n, fact, term;
  mp_bitcnt_t bits = ((double)prec) * 3.3219281 + 50;
  mpf_init2(zee, bits);
  mpf_init2(z_n, bits);
  mpf_init2(fact, bits);
  mpf_init2(term, bits);
  mpf_set(zee, z);
  mpf_set(z_n, zee);
  mpf_set_ui(ex, 1);
  mpf_set_ui(fact, 1);
  mpf_t maxterm;
  mpf_init2(maxterm, bits);
  fp_epsilon(maxterm, prec);
  unsigned int n = 1;
  while (1) {
    fp_inv_factorial(fact, n, prec);
    mpf_mul(term, z_n, fact);
    mpf_add(ex, ex, 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(fact);
  mpf_clear(term);
  mpf_clear(maxterm);
}


x86 assembly (clang, -O0):
<fp_exp_helper>:
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  0xe3f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe3b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%edi
movsd  -0x28(%rbp),%xmm0
call   10c0 <mpf_init2@plt>
mov    -0x14(%rbp),%edi
movsd  -0x28(%rbp),%xmm0
call   10c0 <mpf_init2@plt>
mov    -0x18(%rbp),%edi
movsd  -0x28(%rbp),%xmm0
call   10c0 <mpf_init2@plt>
mov    -0x1c(%rbp),%edi
movsd  -0x28(%rbp),%xmm0
call   10c0 <mpf_init2@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <mpf_set@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <mpf_set@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   10a0 <mpf_set_ui@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   10a0 <mpf_set_ui@plt>
mov    -0x2c(%rbp),%edi
movsd  -0x28(%rbp),%xmm0
call   10c0 <mpf_init2@plt>
mov    -0x2c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <fp_epsilon@plt>
movl   $0x1,-0x30(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <fp_inv_factorial@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   10b0 <mpf_mul@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <mpf_add@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <mpf_abs@plt>
mov    -0x1c(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1050 <mpf_cmp@plt>
cmp    $0x0,%rax
jge    12a8 <fp_exp_helper+0x108>
jmp    12c4 <fp_exp_helper+0x124>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10b0 <mpf_mul@plt>
jmp    1259 <fp_exp_helper+0xb9>
mov    -0x10(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x14(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x18(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x1c(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x2c(%rbp),%edi
call   1080 <mpf_clear@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_exp_helper>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
mov    %edx,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xe42(%rip),%xmm0
addsd  0xe42(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   10c0 <mpf_init2@plt>
movsd  0x8(%rsp),%xmm0
call   10c0 <mpf_init2@plt>
movsd  0x8(%rsp),%xmm0
call   10c0 <mpf_init2@plt>
movsd  0x8(%rsp),%xmm0
call   10c0 <mpf_init2@plt>
mov    %ebx,%esi
call   1090 <mpf_set@plt>
call   1090 <mpf_set@plt>
mov    $0x1,%ebx
mov    %ebp,%edi
mov    $0x1,%esi
call   10a0 <mpf_set_ui@plt>
mov    $0x1,%esi
call   10a0 <mpf_set_ui@plt>
movsd  0x8(%rsp),%xmm0
call   10c0 <mpf_init2@plt>
mov    %r14d,%esi
call   1060 <fp_epsilon@plt>
nopl   0x0(%rax)
mov    %ebx,%esi
mov    %r14d,%edx
call   1030 <fp_inv_factorial@plt>
call   10b0 <mpf_mul@plt>
mov    %ebp,%edi
mov    %ebp,%esi
call   1070 <mpf_add@plt>
call   1040 <mpf_abs@plt>
call   1050 <mpf_cmp@plt>
test   %rax,%rax
js     1261 <fp_exp_helper+0xc1>
add    $0x1,%ebx
call   10b0 <mpf_mul@plt>
jmp    1230 <fp_exp_helper+0x90>
call   1080 <mpf_clear@plt>
call   1080 <mpf_clear@plt>
call   1080 <mpf_clear@plt>
call   1080 <mpf_clear@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <mpf_clear@plt>

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

LLVM IR (-O2):
define void @fp_exp_helper(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_init2(i32 undef, double %5)
%9 = tail call i32 @mpf_init2(i32 undef, double %5)
%10 = tail call i32 @mpf_set(i32 undef, i32 %1)
%11 = tail call i32 @mpf_set(i32 undef, i32 undef)
%12 = tail call i32 @mpf_set_ui(i32 %0, i32 1)
%13 = tail call i32 @mpf_set_ui(i32 undef, i32 1)
%14 = tail call i32 @mpf_init2(i32 undef, double %5)
%15 = tail call i32 @fp_epsilon(i32 undef, i32 %2)
br label %16
16: ; preds = %24, %3
%17 = phi i32 [ 1, %3 ], [ %25, %24 ]
%18 = tail call i32 @fp_inv_factorial(i32 undef, i32 %17, i32 %2)
%19 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%20 = tail call i32 @mpf_add(i32 %0, i32 %0, i32 undef)
%21 = tail call i32 @mpf_abs(i32 undef, i32 undef)
%22 = tail call i64 @mpf_cmp(i32 undef, i32 undef)
%23 = icmp slt i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %16
%25 = add i32 %17, 1
%26 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
br label %16
27: ; preds = %16
%28 = tail call i32 @mpf_clear(i32 undef)
%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
}