#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 */

/* Variables and functions */
float cos_core(float);
float my_rint(float);
float sin_core(float);
float my_sin(float x) {
  float q, t;
  int quadrant;
  q = my_rint(x * 6.3661977236758138e-1);
  quadrant = (int)q;
  t = x - q * 1.5707963267923333e+00;
  t = t - q * 2.5633441515945189e-12;
  if (quadrant & 1) {
    t = cos_core(t);
  } else {
    t = sin_core(t);
  }
  return (quadrant & 2) ? -t : t;
}


x86 assembly (clang, -O0):
<my_sin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xec2(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <my_rint@plt>
movss  %xmm0,-0x8(%rbp)
cvttss2si -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe6f(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe25(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     120f <my_sin+0xdf>
movss  -0xc(%rbp),%xmm0
call   1040 <cos_core@plt>
movss  %xmm0,-0xc(%rbp)
jmp    121e <my_sin+0xee>
movss  -0xc(%rbp),%xmm0
call   1030 <sin_core@plt>
movss  %xmm0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1249 <my_sin+0x119>
movss  -0xc(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1253 <my_sin+0x123>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_sin>:
push   %rbx
sub    $0x10,%rsp
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xeb9(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <my_rint@plt>
cvttss2si %xmm0,%ebx
cvtss2sd %xmm0,%xmm0
movsd  0xea4(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%rsp),%xmm1
cvtsd2ss %xmm1,%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xe92(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
test   $0x1,%bl
jne    1197 <my_sin+0x67>
call   1030 <sin_core@plt>
test   $0x2,%bl
jne    11a1 <my_sin+0x71>
jmp    11a8 <my_sin+0x78>
call   1040 <cos_core@plt>
test   $0x2,%bl
je     11a8 <my_sin+0x78>
xorps  0xe78(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @my_sin(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca i32
store float %0, float* %2
%6 = load float, float* %2
%7 = fpext float %6 to double
%8 = fmul double %7, 0x3FE45F306DC9C883
%9 = fptrunc double %8 to float
%10 = call float @my_rint(float %9)
store float %10, float* %3
%11 = load float, float* %3
%12 = fptosi float %11 to i32
store i32 %12, i32* %5
%13 = load float, float* %2
%14 = fpext float %13 to double
%15 = load float, float* %3
%16 = fpext float %15 to double
%17 = fneg double %16
%18 = call double @llvm.fmuladd.f64(double %17, double 0x3FF921FB54440000, double %14)
%19 = fptrunc double %18 to float
store float %19, float* %4
%20 = load float, float* %4
%21 = fpext float %20 to double
%22 = load float, float* %3
%23 = fpext float %22 to double
%24 = fneg double %23
%25 = call double @llvm.fmuladd.f64(double %24, double 0x3D868C234C4C6629, double %21)
%26 = fptrunc double %25 to float
store float %26, float* %4
%27 = load i32, i32* %5
%28 = and i32 %27, 1
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %1
%31 = load float, float* %4
%32 = call float @cos_core(float %31)
store float %32, float* %4
br label %36
33: ; preds = %1
%34 = load float, float* %4
%35 = call float @sin_core(float %34)
store float %35, float* %4
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %5
%38 = and i32 %37, 2
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load float, float* %4
%42 = fneg float %41
br label %45
43: ; preds = %36
%44 = load float, float* %4
br label %45
45: ; preds = %43, %40
%46 = phi float [ %42, %40 ], [ %44, %43 ]
ret float %46
}

LLVM IR (-O2):
define float @my_sin(float %0) {
%2 = fpext float %0 to double
%3 = fmul double %2, 0x3FE45F306DC9C883
%4 = fptrunc double %3 to float
%5 = tail call float @my_rint(float %4)
%6 = fptosi float %5 to i32
%7 = fpext float %5 to double
%8 = fneg double %7
%9 = tail call double @llvm.fmuladd.f64(double %8, double 0x3FF921FB54440000, double %2)
%10 = fptrunc double %9 to float
%11 = fpext float %10 to double
%12 = tail call double @llvm.fmuladd.f64(double %8, double 0x3D868C234C4C6629, double %11)
%13 = fptrunc double %12 to float
%14 = and i32 %6, 1
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %1
%17 = tail call float @cos_core(float %13)
br label %20
18: ; preds = %1
%19 = tail call float @sin_core(float %13)
br label %20
20: ; preds = %18, %16
%21 = phi float [ %17, %16 ], [ %19, %18 ]
%22 = and i32 %6, 2
%23 = icmp eq i32 %22, 0
%24 = fneg float %21
%25 = select i1 %23, float %21, float %24
ret float %25
}