double filter2(double x_n, double b0, double b1, double b2, double a1,
               double a2) {
  static double _x_n_1 = 0.0;
  static double _x_n_2 = 0.0;
  static double _y_n_1 = 0.0;
  static double _y_n_2 = 0.0;
  const double y_n =
      b0 * x_n + b1 * _x_n_1 + b2 * _x_n_2 - a1 * _y_n_1 - a2 * _y_n_2;
  _x_n_2 = _x_n_1;
  _x_n_1 = x_n;
  _y_n_2 = _y_n_1;
  _y_n_1 = y_n;
  return y_n;
}


x86 assembly (clang, -O0):
<filter2>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm0
mulsd  0x2eef(%rip),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  0x2ee2(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0x2ed5(%rip),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  0x2eb1(%rip),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0x2e6d(%rip),%xmm0
movsd  %xmm0,0x2e6d(%rip)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2e58(%rip)
movsd  0x2e60(%rip),%xmm0
movsd  %xmm0,0x2e60(%rip)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,0x2e4b(%rip)
movsd  -0x38(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter2>:
movsd  0x2f20(%rip),%xmm6
mulsd  %xmm6,%xmm2
mulsd  %xmm0,%xmm1
mulsd  0x2f18(%rip),%xmm3
addsd  %xmm2,%xmm1
addsd  %xmm1,%xmm3
movsd  0x2f10(%rip),%xmm1
mulsd  %xmm1,%xmm4
subsd  %xmm4,%xmm3
mulsd  0x2f08(%rip),%xmm5
subsd  %xmm5,%xmm3
movsd  %xmm6,0x2eec(%rip)
movsd  %xmm0,0x2edc(%rip)
movsd  %xmm1,0x2eec(%rip)
movsd  %xmm3,0x2edc(%rip)
movapd %xmm3,%xmm0
ret

LLVM IR (-O0):
@filter2._x_n_1 = internal global double 0.000000e+00
@filter2._x_n_2 = internal global double 0.000000e+00
@filter2._y_n_1 = internal global double 0.000000e+00
@filter2._y_n_2 = internal global double 0.000000e+00
define double @filter2(double %0, double %1, double %2, double %3, double %4, double %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
store double %5, double* %12
%14 = load double, double* %8
%15 = load double, double* %7
%16 = load double, double* %9
%17 = load double, double* @filter2._x_n_1
%18 = fmul double %16, %17
%19 = call double @llvm.fmuladd.f64(double %14, double %15, double %18)
%20 = load double, double* %10
%21 = load double, double* @filter2._x_n_2
%22 = call double @llvm.fmuladd.f64(double %20, double %21, double %19)
%23 = load double, double* %11
%24 = load double, double* @filter2._y_n_1
%25 = fneg double %23
%26 = call double @llvm.fmuladd.f64(double %25, double %24, double %22)
%27 = load double, double* %12
%28 = load double, double* @filter2._y_n_2
%29 = fneg double %27
%30 = call double @llvm.fmuladd.f64(double %29, double %28, double %26)
store double %30, double* %13
%31 = load double, double* @filter2._x_n_1
store double %31, double* @filter2._x_n_2
%32 = load double, double* %7
store double %32, double* @filter2._x_n_1
%33 = load double, double* @filter2._y_n_1
store double %33, double* @filter2._y_n_2
%34 = load double, double* %13
store double %34, double* @filter2._y_n_1
%35 = load double, double* %13
ret double %35
}

LLVM IR (-O2):
@filter2._x_n_1 = internal unnamed_addr global double 0.000000e+00
@filter2._x_n_2 = internal unnamed_addr global double 0.000000e+00
@filter2._y_n_1 = internal unnamed_addr global double 0.000000e+00
@filter2._y_n_2 = internal unnamed_addr global double 0.000000e+00
define double @filter2(double %0, double %1, double %2, double %3, double %4, double %5) {
%7 = load double, double* @filter2._x_n_1
%8 = fmul double %7, %2
%9 = tail call double @llvm.fmuladd.f64(double %1, double %0, double %8)
%10 = load double, double* @filter2._x_n_2
%11 = tail call double @llvm.fmuladd.f64(double %3, double %10, double %9)
%12 = load double, double* @filter2._y_n_1
%13 = fneg double %4
%14 = tail call double @llvm.fmuladd.f64(double %13, double %12, double %11)
%15 = load double, double* @filter2._y_n_2
%16 = fneg double %5
%17 = tail call double @llvm.fmuladd.f64(double %16, double %15, double %14)
store double %7, double* @filter2._x_n_2
store double %0, double* @filter2._x_n_1
store double %12, double* @filter2._y_n_2
store double %17, double* @filter2._y_n_1
ret double %17
}