#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 */
int /*<<< orphan*/ assert(int);
double sinc(double);
int fir_bandpass(double *h, double *w, int N, double fc1, double fc2) {
  int i, j;
  int delay;
  assert(N & 1);
  delay = (N - 1) / 2;
  for (i = 0, j = N - 1; i <= delay; i++, j--) {
    h[i] = ((double)fc2 * sinc(fc2 * (i - delay)) -
            (double)fc1 * sinc(fc1 * (i - delay))) *
           w[i];
    h[j] = h[i];
  }
  h[delay] = fc2 - fc1;
  return N;
}


x86 assembly (clang, -O0):
<fir_bandpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    -0x14(%rbp),%edi
and    $0x1,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jg     123e <fir_bandpass+0x11e>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x2c(%rbp),%eax
sub    -0x34(%rbp),%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
call   1040 <sinc@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x2c(%rbp),%eax
sub    -0x34(%rbp),%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
call   1040 <sinc@plt>
movsd  -0x50(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    1169 <fir_bandpass+0x49>
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fir_bandpass>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r13
mov    %edx,%edi
and    $0x1,%edi
call   1030 <assert@plt>
movsd  0x20(%rsp),%xmm1
lea    -0x1(%rbx),%eax
shr    $0x1f,%eax
add    %ebx,%eax
add    $0xffffffff,%eax
sar    %eax
mov    %eax,0xc(%rsp)
mov    %rbx,0x18(%rsp)
test   %ebx,%ebx
js     120a <fir_bandpass+0xea>
xor    %ebp,%ebp
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
mov    $0x0,%ebx
cmovg  %ecx,%ebx
mov    0x18(%rsp),%eax
add    $0x1,%ebx
lea    -0x8(,%rax,8),%r14
ff
add    %r13,%r14
mov    %ecx,%r12d
neg    %r12d
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x28(%rsp)
mulsd  %xmm1,%xmm0
call   1040 <sinc@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x28(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
call   1040 <sinc@plt>
movsd  0x20(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm0
movsd  0x30(%rsp),%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm0,%xmm2
mulsd  (%r15,%rbp,8),%xmm2
movsd  %xmm2,0x0(%r13,%rbp,8)
movsd  %xmm2,(%r14)
add    $0x1,%rbp
add    $0xfffffffffffffff8,%r14
cmp    %rbp,%rbx
jne    11a0 <fir_bandpass+0x80>
subsd  0x10(%rsp),%xmm1
movslq 0xc(%rsp),%rax
movsd  %xmm1,0x0(%r13,%rax,8)
mov    0x18(%rsp),%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fir_bandpass(double* %0, double* %1, i32 %2, double %3, double %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store i32 %2, i32* %8
store double %3, double* %9
store double %4, double* %10
%14 = load i32, i32* %8
%15 = and i32 %14, 1
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %8
%18 = sub nsw i32 %17, 1
%19 = sdiv i32 %18, 2
store i32 %19, i32* %13
store i32 0, i32* %11
%20 = load i32, i32* %8
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %12
br label %22
22: ; preds = %65, %5
%23 = load i32, i32* %11
%24 = load i32, i32* %13
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %70
26: ; preds = %22
%27 = load double, double* %10
%28 = load double, double* %10
%29 = load i32, i32* %11
%30 = load i32, i32* %13
%31 = sub nsw i32 %29, %30
%32 = sitofp i32 %31 to double
%33 = fmul double %28, %32
%34 = call double @sinc(double %33)
%35 = load double, double* %9
%36 = load double, double* %9
%37 = load i32, i32* %11
%38 = load i32, i32* %13
%39 = sub nsw i32 %37, %38
%40 = sitofp i32 %39 to double
%41 = fmul double %36, %40
%42 = call double @sinc(double %41)
%43 = fmul double %35, %42
%44 = fneg double %43
%45 = call double @llvm.fmuladd.f64(double %27, double %34, double %44)
%46 = load double*, double** %7
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = fmul double %45, %50
%52 = load double*, double** %6
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
store double %51, double* %55
%56 = load double*, double** %6
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = load double*, double** %6
%62 = load i32, i32* %12
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
store double %60, double* %64
br label %65
65: ; preds = %26
%66 = load i32, i32* %11
%67 = add nsw i32 %66, 1
store i32 %67, i32* %11
%68 = load i32, i32* %12
%69 = add nsw i32 %68, -1
store i32 %69, i32* %12
br label %22
70: ; preds = %22
%71 = load double, double* %10
%72 = load double, double* %9
%73 = fsub double %71, %72
%74 = load double*, double** %6
%75 = load i32, i32* %13
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
store double %73, double* %77
%78 = load i32, i32* %8
ret i32 %78
}

LLVM IR (-O2):
define i32 @fir_bandpass(double* nocapture writeonly %0, double* nocapture %1, i32 returned %2, double %3, double %4) {
%6 = and i32 %2, 1
%7 = tail call i32 @assert(i32 %6)
%8 = add nsw i32 %2, -1
%9 = sdiv i32 %8, 2
%10 = icmp slt i32 %2, 0
br i1 %10, label %37, label %11
11: ; preds = %5
%12 = zext i32 %2 to i64
%13 = call i32 @llvm.smax.i32(i32 %9, i32 0)
%14 = add nuw nsw i32 %13, 1
%15 = zext i32 %14 to i64
br label %16
16: ; preds = %11, %16
%17 = phi i64 [ %12, %11 ], [ %19, %16 ]
%18 = phi i64 [ 0, %11 ], [ %35, %16 ]
%19 = add nsw i64 %17, -1
%20 = trunc i64 %18 to i32
%21 = sub nsw i32 %20, %9
%22 = sitofp i32 %21 to double
%23 = fmul double %22, %4
%24 = tail call double @sinc(double %23)
%25 = fmul double %22, %3
%26 = tail call double @sinc(double %25)
%27 = fneg double %26
%28 = fmul double %27, %3
%29 = tail call double @llvm.fmuladd.f64(double %4, double %24, double %28)
%30 = getelementptr inbounds double, double* %1, i64 %18
%31 = load double, double* %30
%32 = fmul double %31, %29
%33 = getelementptr inbounds double, double* %0, i64 %18
store double %32, double* %33
%34 = getelementptr inbounds double, double* %0, i64 %19
store double %32, double* %34
%35 = add nuw nsw i64 %18, 1
%36 = icmp eq i64 %35, %15
br i1 %36, label %37, label %16
37: ; preds = %16, %5
%38 = fsub double %4, %3
%39 = sext i32 %9 to i64
%40 = getelementptr inbounds double, double* %0, i64 %39
store double %38, double* %40
ret i32 %2
}