#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_pi_half(int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ fp_sine_series(int /*<<< orphan*/, int /*<<< orphan*/,
                                  unsigned int);
int /*<<< orphan*/ fp_two_over_pi(int /*<<< orphan*/, unsigned int);
unsigned long labs(long);
int /*<<< orphan*/ mpf_clear(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_neg(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_set(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
void fp_sine(mpf_t si, const mpf_t z, unsigned int prec) {
  mp_bitcnt_t bits = ((double)prec) * 3.322 + 50;
  mpf_t zee, pih, per, top;
  mpf_init2(zee, bits);
  mpf_init2(pih, bits);
  mpf_init2(per, bits);
  mpf_init2(top, bits);
  mpf_set(zee, z);
  fp_two_over_pi(top, prec);
  mpf_mul(per, zee, top);
  mpf_floor(per, per);
  long quad = mpf_get_si(per);
  fp_pi_half(pih, prec);
  mpf_mul(per, per, pih);
  mpf_sub(zee, zee, per);
  unsigned long iq = labs(quad);
  if ((1 == iq % 4) || (3 == iq % 4)) {
    mpf_sub(zee, pih, zee);
  }
  fp_sine_series(si, zee, prec);
  if (0 > quad)
    iq++;
  iq /= 2;
  if (iq % 2) {
    mpf_neg(si, si);
  }
  mpf_clear(zee);
  mpf_clear(pih);
  mpf_clear(per);
  mpf_clear(top);
}


x86 assembly (clang, -O0):
<fp_sine>:
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  0xe1f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe1b(%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    -0x24(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10e0 <mpf_init2@plt>
mov    -0x28(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10e0 <mpf_init2@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <mpf_set@plt>
mov    -0x28(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <fp_two_over_pi@plt>
mov    -0x24(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%edx
call   10b0 <mpf_mul@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <mpf_floor@plt>
mov    -0x24(%rbp),%edi
call   10d0 <mpf_get_si@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <fp_pi_half@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10b0 <mpf_mul@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x24(%rbp),%edx
call   10a0 <mpf_sub@plt>
mov    -0x30(%rbp),%rdi
call   1050 <labs@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rcx
and    $0x3,%rcx
mov    $0x1,%eax
cmp    %rcx,%rax
je     12c5 <fp_sine+0x105>
mov    -0x38(%rbp),%rcx
and    $0x3,%rcx
mov    $0x3,%eax
cmp    %rcx,%rax
jne    12d3 <fp_sine+0x113>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   10a0 <mpf_sub@plt>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   10c0 <fp_sine_series@plt>
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jle    12f9 <fp_sine+0x139>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1322 <fp_sine+0x162>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1070 <mpf_neg@plt>
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>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_sine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%r14d
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   1080 <mpf_set@plt>
mov    %r15d,%esi
call   1050 <fp_two_over_pi@plt>
call   10a0 <mpf_mul@plt>
call   1030 <mpf_floor@plt>
call   10c0 <mpf_get_si@plt>
mov    %rax,%rbp
mov    %r15d,%esi
call   1040 <fp_pi_half@plt>
call   10a0 <mpf_mul@plt>
call   1090 <mpf_sub@plt>
mov    %rbp,%rbx
neg    %rbx
cmovs  %rbp,%rbx
mov    %ebx,%eax
not    %eax
test   $0x1,%al
jne    1248 <fp_sine+0x98>
call   1090 <mpf_sub@plt>
mov    %r14d,%edi
mov    %r15d,%edx
call   10b0 <fp_sine_series@plt>
shr    $0x3f,%rbp
add    %ebx,%ebp
test   $0x2,%bpl
je     126a <fp_sine+0xba>
mov    %r14d,%edi
mov    %r14d,%esi
call   1060 <mpf_neg@plt>
call   1070 <mpf_clear@plt>
call   1070 <mpf_clear@plt>
call   1070 <mpf_clear@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <mpf_clear@plt>

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

LLVM IR (-O2):
define void @fp_sine(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 @fp_two_over_pi(i32 undef, i32 %2)
%12 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%13 = tail call i32 @mpf_floor(i32 undef, i32 undef)
%14 = tail call i64 @mpf_get_si(i32 undef)
%15 = tail call i32 @fp_pi_half(i32 undef, i32 %2)
%16 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%17 = tail call i32 @mpf_sub(i32 undef, i32 undef, i32 undef)
%18 = tail call i64 @llvm.abs.i64(i64 %14, i1 true)
%19 = and i64 %18, 3
switch i64 %19, label %22 [
i64 1, label %20
i64 3, label %20
]
20: ; preds = %3, %3
%21 = tail call i32 @mpf_sub(i32 undef, i32 undef, i32 undef)
br label %22
22: ; preds = %3, %20
%23 = tail call i32 @fp_sine_series(i32 %0, i32 undef, i32 %2)
%24 = lshr i64 %14, 63
%25 = add nuw i64 %18, %24
%26 = and i64 %25, 2
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = tail call i32 @mpf_neg(i32 %0, i32 %0)
br label %30
30: ; preds = %28, %22
%31 = tail call i32 @mpf_clear(i32 undef)
%32 = tail call i32 @mpf_clear(i32 undef)
%33 = tail call i32 @mpf_clear(i32 undef)
%34 = tail call i32 @mpf_clear(i32 undef)
ret void
}