#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 /*<<< orphan*/);
int /*<<< orphan*/ mpf_sub(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
void fp_sine_series(mpf_t si, const mpf_t z, unsigned int prec) {
  mp_bitcnt_t bits = ((double)prec) * 3.322 + 50;
  mpf_t zsq, z_n, fact, term;
  mpf_init2(zsq, bits);
  mpf_init2(z_n, bits);
  mpf_init2(fact, bits);
  mpf_init2(term, bits);
  mpf_set(z_n, z);
  mpf_mul(zsq, z, z);
  mpf_set_ui(si, 0);
  prec += 2;
  mpf_t maxterm;
  mpf_init2(maxterm, bits);
  fp_epsilon(maxterm, prec);
  unsigned int n = 1;
  unsigned int s = 0;
  while (1) {
    fp_inv_factorial(fact, n, prec);
    mpf_mul(term, z_n, fact);
    if (0 == s % 2) {
      mpf_add(si, si, term);
    } else {
      mpf_sub(si, si, term);
    }
    mpf_abs(term, term);
    if (mpf_cmp(term, maxterm) < 0)
      break;
    n += 2;
    mpf_mul(z_n, z_n, zsq);
    s++;
  }
  mpf_clear(zsq);
  mpf_clear(z_n);
  mpf_clear(fact);
  mpf_clear(term);
  mpf_clear(maxterm);
}


x86 assembly (clang, -O0):
<fp_sine_series>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe2f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe2b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10d0 <mpf_init2@plt>
mov    -0x20(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10d0 <mpf_init2@plt>
mov    -0x24(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10d0 <mpf_init2@plt>
mov    -0x28(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10d0 <mpf_init2@plt>
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <mpf_set@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   10c0 <mpf_mul@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   10a0 <mpf_set_ui@plt>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x2c(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10d0 <mpf_init2@plt>
mov    -0x2c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <fp_epsilon@plt>
movl   $0x1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <fp_inv_factorial@plt>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   10c0 <mpf_mul@plt>
mov    -0x34(%rbp),%ecx
and    $0x1,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    12ab <fp_sine_series+0xfb>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1070 <mpf_add@plt>
jmp    12b9 <fp_sine_series+0x109>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x28(%rbp),%edx
call   10b0 <mpf_sub@plt>
mov    -0x28(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <mpf_abs@plt>
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1050 <mpf_cmp@plt>
cmp    $0x0,%rax
jge    12de <fp_sine_series+0x12e>
jmp    1303 <fp_sine_series+0x153>
mov    -0x30(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   10c0 <mpf_mul@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    126c <fp_sine_series+0xbc>
mov    -0x1c(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x20(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x24(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x28(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x2c(%rbp),%edi
call   1080 <mpf_clear@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_sine_series>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%r15d
mov    %edx,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xe32(%rip),%xmm0
addsd  0xe32(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   10d0 <mpf_init2@plt>
movsd  (%rsp),%xmm0
call   10d0 <mpf_init2@plt>
movsd  (%rsp),%xmm0
call   10d0 <mpf_init2@plt>
movsd  (%rsp),%xmm0
call   10d0 <mpf_init2@plt>
mov    %ebx,%esi
call   1090 <mpf_set@plt>
mov    %ebx,%esi
mov    %ebx,%edx
call   10c0 <mpf_mul@plt>
xor    %ebp,%ebp
mov    %r15d,%edi
xor    %esi,%esi
call   10a0 <mpf_set_ui@plt>
add    $0x2,%r14d
movsd  (%rsp),%xmm0
call   10d0 <mpf_init2@plt>
mov    %r14d,%esi
call   1060 <fp_epsilon@plt>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%esi
mov    %r14d,%edx
call   1030 <fp_inv_factorial@plt>
call   10c0 <mpf_mul@plt>
mov    %r15d,%edi
mov    %r15d,%esi
test   $0x1,%bpl
jne    1270 <fp_sine_series+0xc0>
call   1070 <mpf_add@plt>
jmp    1275 <fp_sine_series+0xc5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   10b0 <mpf_sub@plt>
call   1040 <mpf_abs@plt>
call   1050 <mpf_cmp@plt>
test   %rax,%rax
js     1291 <fp_sine_series+0xe1>
add    $0x2,%ebx
call   10c0 <mpf_mul@plt>
add    $0x1,%ebp
jmp    1240 <fp_sine_series+0x90>
call   1080 <mpf_clear@plt>
call   1080 <mpf_clear@plt>
call   1080 <mpf_clear@plt>
call   1080 <mpf_clear@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <mpf_clear@plt>

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

LLVM IR (-O2):
define void @fp_sine_series(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_init2(i32 undef, double %5)
%10 = tail call i32 @mpf_set(i32 undef, i32 %1)
%11 = tail call i32 @mpf_mul(i32 undef, i32 %1, i32 %1)
%12 = tail call i32 @mpf_set_ui(i32 %0, i32 0)
%13 = add i32 %2, 2
%14 = tail call i32 @mpf_init2(i32 undef, double %5)
%15 = tail call i32 @fp_epsilon(i32 undef, i32 %13)
br label %16
16: ; preds = %31, %3
%17 = phi i32 [ 1, %3 ], [ %32, %31 ]
%18 = phi i32 [ 0, %3 ], [ %34, %31 ]
%19 = tail call i32 @fp_inv_factorial(i32 undef, i32 %17, i32 %13)
%20 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%21 = and i32 %18, 1
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = tail call i32 @mpf_add(i32 %0, i32 %0, i32 undef)
br label %27
25: ; preds = %16
%26 = tail call i32 @mpf_sub(i32 %0, i32 %0, i32 undef)
br label %27
27: ; preds = %25, %23
%28 = tail call i32 @mpf_abs(i32 undef, i32 undef)
%29 = tail call i64 @mpf_cmp(i32 undef, i32 undef)
%30 = icmp slt i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = add i32 %17, 2
%33 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%34 = add i32 %18, 1
br label %16
35: ; preds = %27
%36 = tail call i32 @mpf_clear(i32 undef)
%37 = tail call i32 @mpf_clear(i32 undef)
%38 = tail call i32 @mpf_clear(i32 undef)
%39 = tail call i32 @mpf_clear(i32 undef)
%40 = tail call i32 @mpf_clear(i32 undef)
ret void
}