void calc_impulse_resp(double Ft, double Bt, double *s, int cnt) {
  double z0, z1, samp;
  int i;
  s[0] = samp = 1.0;
  z0 = z1 = 0.0;
  for (i = 1; i < cnt; i++) {
    samp = samp + 2.0 * Ft * z0 + Bt * z1;
    z1 = z0;
    z0 = samp;
    s[i] = samp > 1.0 ? 1.0 : samp < -1.0 ? -1.0 : samp;
    samp = 0.0;
  }
}


x86 assembly (clang, -O0):
<calc_impulse_resp>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movsd  0xee3(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movsd  0xed2(%rip),%xmm0
movsd  %xmm0,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1229 <calc_impulse_resp+0x129>
movsd  -0x38(%rbp),%xmm0
movsd  0xea6(%rip),%xmm1
mulsd  -0x8(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe54(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c8 <calc_impulse_resp+0xc8>
movsd  0xe42(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1201 <calc_impulse_resp+0x101>
movsd  0xe40(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11ed <calc_impulse_resp+0xed>
movsd  0xe2d(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    11f7 <calc_impulse_resp+0xf7>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1149 <calc_impulse_resp+0x49>
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_impulse_resp>:
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rdi)
cmp    $0x2,%esi
jl     126e <calc_impulse_resp+0x16e>
addsd  %xmm0,%xmm0
xorpd  %xmm4,%xmm4
movapd %xmm0,%xmm3
mulsd  %xmm4,%xmm3
movsd  0xed1(%rip),%xmm8
addsd  %xmm8,%xmm3
movapd %xmm1,%xmm5
mulsd  %xmm4,%xmm5
addsd  %xmm3,%xmm5
movsd  0xec0(%rip),%xmm3
movapd %xmm3,%xmm6
maxsd  %xmm5,%xmm6
movapd %xmm8,%xmm7
cmpltsd %xmm5,%xmm7
movapd %xmm7,%xmm2
andnpd %xmm6,%xmm2
andpd  %xmm8,%xmm7
orpd   %xmm2,%xmm7
movlpd %xmm7,0x8(%rdi)
je     126e <calc_impulse_resp+0x16e>
mov    %esi,%ecx
mov    $0x2,%eax
cmp    $0x3,%esi
je     1231 <calc_impulse_resp+0x131>
lea    -0x2(%rcx),%rdx
and    $0xfffffffffffffffe,%rdx
neg    %rdx
xorpd  %xmm9,%xmm9
mov    $0x2,%eax
xorpd  %xmm4,%xmm4
nop
movapd %xmm0,%xmm2
mulsd  %xmm5,%xmm2
addsd  %xmm9,%xmm2
mulsd  %xmm1,%xmm4
addsd  %xmm2,%xmm4
movapd %xmm3,%xmm2
maxsd  %xmm4,%xmm2
movapd %xmm8,%xmm7
cmpltsd %xmm4,%xmm7
movapd %xmm7,%xmm6
andnpd %xmm2,%xmm6
andpd  %xmm8,%xmm7
orpd   %xmm6,%xmm7
movlpd %xmm7,(%rdi,%rax,8)
movapd %xmm0,%xmm2
mulsd  %xmm4,%xmm2
addsd  %xmm9,%xmm2
mulsd  %xmm1,%xmm5
addsd  %xmm2,%xmm5
movapd %xmm3,%xmm2
maxsd  %xmm5,%xmm2
movapd %xmm8,%xmm6
cmpltsd %xmm5,%xmm6
movapd %xmm6,%xmm7
andnpd %xmm2,%xmm7
andpd  %xmm8,%xmm6
orpd   %xmm7,%xmm6
movlpd %xmm6,0x8(%rdi,%rax,8)
lea    (%rdx,%rax,1),%rsi
add    $0x2,%rsi
add    $0x2,%rax
cmp    $0x2,%rsi
jne    11a0 <calc_impulse_resp+0xa0>
test   $0x1,%cl
je     126e <calc_impulse_resp+0x16e>
mulsd  %xmm5,%xmm0
xorpd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm4,%xmm1
addsd  %xmm2,%xmm1
maxsd  %xmm1,%xmm3
movapd %xmm8,%xmm0
cmpltsd %xmm1,%xmm0
movapd %xmm0,%xmm1
andnpd %xmm3,%xmm1
andpd  %xmm8,%xmm0
orpd   %xmm1,%xmm0
movlpd %xmm0,(%rdi,%rax,8)
ret

LLVM IR (-O0):
define void @calc_impulse_resp(double %0, double %1, double* %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double* %2, double** %7
store i32 %3, i32* %8
store double 1.000000e+00, double* %11
%13 = load double*, double** %7
%14 = getelementptr inbounds double, double* %13, i64 0
store double 1.000000e+00, double* %14
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %9
store i32 1, i32* %12
br label %15
15: ; preds = %47, %4
%16 = load i32, i32* %12
%17 = load i32, i32* %8
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %50
19: ; preds = %15
%20 = load double, double* %11
%21 = load double, double* %5
%22 = fmul double 2.000000e+00, %21
%23 = load double, double* %9
%24 = call double @llvm.fmuladd.f64(double %22, double %23, double %20)
%25 = load double, double* %6
%26 = load double, double* %10
%27 = call double @llvm.fmuladd.f64(double %25, double %26, double %24)
store double %27, double* %11
%28 = load double, double* %9
store double %28, double* %10
%29 = load double, double* %11
store double %29, double* %9
%30 = load double, double* %11
%31 = fcmp ogt double %30, 1.000000e+00
br i1 %31, label %32, label %33
32: ; preds = %19
br label %41
33: ; preds = %19
%34 = load double, double* %11
%35 = fcmp olt double %34, -1.000000e+00
br i1 %35, label %36, label %37
36: ; preds = %33
br label %39
37: ; preds = %33
%38 = load double, double* %11
br label %39
39: ; preds = %37, %36
%40 = phi double [ -1.000000e+00, %36 ], [ %38, %37 ]
br label %41
41: ; preds = %39, %32
%42 = phi double [ 1.000000e+00, %32 ], [ %40, %39 ]
%43 = load double*, double** %7
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
store double %42, double* %46
store double 0.000000e+00, double* %11
br label %47
47: ; preds = %41
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %15
50: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @calc_impulse_resp(double %0, double %1, double* nocapture writeonly %2, i32 %3) {
store double 1.000000e+00, double* %2
%5 = icmp sgt i32 %3, 1
br i1 %5, label %6, label %59
6: ; preds = %4
%7 = fmul double %0, 2.000000e+00
%8 = zext i32 %3 to i64
%9 = tail call double @llvm.fmuladd.f64(double %7, double 0.000000e+00, double 1.000000e+00)
%10 = tail call double @llvm.fmuladd.f64(double %1, double 0.000000e+00, double %9)
%11 = fcmp ogt double %10, 1.000000e+00
%12 = fcmp olt double %10, -1.000000e+00
%13 = select i1 %12, double -1.000000e+00, double %10
%14 = select i1 %11, double 1.000000e+00, double %13
%15 = getelementptr inbounds double, double* %2, i64 1
store double %14, double* %15
%16 = icmp eq i32 %3, 2
br i1 %16, label %59, label %17
17: ; preds = %6
%18 = and i64 %8, 1
%19 = icmp eq i32 %3, 3
br i1 %19, label %46, label %20
20: ; preds = %17
%21 = add nsw i64 %8, -2
%22 = and i64 %21, -2
br label %23
23: ; preds = %23, %20
%24 = phi i64 [ 2, %20 ], [ %43, %23 ]
%25 = phi double [ 0.000000e+00, %20 ], [ %29, %23 ]
%26 = phi double [ %10, %20 ], [ %37, %23 ]
%27 = phi i64 [ 0, %20 ], [ %44, %23 ]
%28 = tail call double @llvm.fmuladd.f64(double %7, double %26, double 0.000000e+00)
%29 = tail call double @llvm.fmuladd.f64(double %1, double %25, double %28)
%30 = fcmp ogt double %29, 1.000000e+00
%31 = fcmp olt double %29, -1.000000e+00
%32 = select i1 %31, double -1.000000e+00, double %29
%33 = select i1 %30, double 1.000000e+00, double %32
%34 = getelementptr inbounds double, double* %2, i64 %24
store double %33, double* %34
%35 = or i64 %24, 1
%36 = tail call double @llvm.fmuladd.f64(double %7, double %29, double 0.000000e+00)
%37 = tail call double @llvm.fmuladd.f64(double %1, double %26, double %36)
%38 = fcmp ogt double %37, 1.000000e+00
%39 = fcmp olt double %37, -1.000000e+00
%40 = select i1 %39, double -1.000000e+00, double %37
%41 = select i1 %38, double 1.000000e+00, double %40
%42 = getelementptr inbounds double, double* %2, i64 %35
store double %41, double* %42
%43 = add nuw nsw i64 %24, 2
%44 = add i64 %27, 2
%45 = icmp eq i64 %44, %22
br i1 %45, label %46, label %23
46: ; preds = %23, %17
%47 = phi i64 [ 2, %17 ], [ %43, %23 ]
%48 = phi double [ 0.000000e+00, %17 ], [ %29, %23 ]
%49 = phi double [ %10, %17 ], [ %37, %23 ]
%50 = icmp eq i64 %18, 0
br i1 %50, label %59, label %51
51: ; preds = %46
%52 = tail call double @llvm.fmuladd.f64(double %7, double %49, double 0.000000e+00)
%53 = tail call double @llvm.fmuladd.f64(double %1, double %48, double %52)
%54 = fcmp ogt double %53, 1.000000e+00
%55 = fcmp olt double %53, -1.000000e+00
%56 = select i1 %55, double -1.000000e+00, double %53
%57 = select i1 %54, double 1.000000e+00, double %56
%58 = getelementptr inbounds double, double* %2, i64 %47
store double %57, double* %58
br label %59
59: ; preds = %51, %46, %6, %4
ret void
}