// File: /workspace/github_c_makefile_star2_O3/pipde[P]deos-songlib/utils/filter/fir.c
// Function: main
int
main(int argc,char **argv)
    {
    int argIndex = 1;

    int i,j,index;
    double max,**last;
    FILE *in,*out;
    RRA *h;

    argIndex = processOptions(argc,argv);

    if (argc-argIndex == 0)
        {
        in = stdin;
        out = stdout;
        }
    else if (argc-argIndex == 1)
        {
        in = OpenFile(argv[argIndex],"r");
        out = stdout;
        }
    else if (argc-argIndex == 2)
        {
        in = OpenFile(argv[argIndex],"r");
        out = OpenFile(argv[argIndex+1],"w");
        }
    else
        {
        fprintf(stderr,"usage: fir -h -a<N.M> -w<N.M> -d<N.M> -l<N.M> "
            "[<input rra file> [<output rra file>]]\n");
        exit(-1);
        }

    readCoefficients(coefficientFile);
    fprintf(stderr,"filter attenuation is %f\n",attenuation);

    h = newRRAHeader();
    
    readRRAHeader(in,h,0);

    writeRRAHeader(out,h,"modifiedBy: fir",0);

    max = pow(2,h->bitsPerSample - 1) - 1;

    last = (double **) New(sizeof(double *) * h->channels);
    for (i = 0; i < h->channels; ++i)
        {
        last[i] = (double *) New(sizeof(double) * numberOfTaps);
        last[i][0] =
            readRRAAmplitude(in,out,h->bitsPerSample,outputComment) / max;
        fprintf(out,"%f\n",attenuation * last[i][0]);
        }

    for (i = 0; i < h->channels; ++i)
        for (j = 1; j < numberOfTaps; ++j)
            last[i][j] = last[i][0];

    index = 0;
    for ( ; i < h->samples; ++i)
        for (j = 0; j < h->channels; ++j)
            {
            int amp = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);
            fprintf(out,"%f\n",
                attenuation *
                    firFilter(amp / max,last[j],
                        coefficients,numberOfTaps,&index));
            }

    fclose(in);
    fclose(out);

    return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %r14d
movl $0x1, %r12d
cmpl $0x2, %edi
jl 0x16a8
movl $0x1, %r12d
movslq %r12d, %rax
movq (%rbx,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x16a8
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x1637
leaq 0x2(%rsi), %rdi
jmp 0x163c
movq 0x8(%rbx,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x65, %eax
jle 0x1653
cmpl $0x66, %eax
jne 0x166a
movq %rdi, 0x5aff(%rip)      # 0x7150
jmp 0x1665
cmpl $0x61, %eax
jne 0x167c
callq 0x1090
movsd %xmm0, 0x5af3(%rip)     # 0x7158
movb $0x1, %r15b
jmp 0x168d
cmpl $0x68, %eax
je 0x1a5b
cmpl $0x76, %eax
je 0x1a3d
xorl %r15d, %r15d
leaq 0x2a8f(%rip), %rdi      # 0x4115
xorl %eax, %eax
callq 0x1a80
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %r14d, %r12d
jl 0x1618
subl %r12d, %r14d
jne 0x16b9
movq 0x5924(%rip), %rax      # 0x6fd8
movq (%rax), %rax
jmp 0x16dc
cmpl $0x2, %r14d
je 0x16ec
cmpl $0x1, %r14d
jne 0x1a7a
movslq %r12d, %rax
movq (%rbx,%rax,8), %rdi
leaq 0x2ef3(%rip), %rsi      # 0x45ca
callq 0x1b1a
movq %rax, -0x30(%rbp)
movq 0x58e9(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x1717
movslq %r12d, %r14
movq (%rbx,%r14,8), %rdi
leaq 0x2ed0(%rip), %rsi      # 0x45ca
callq 0x1b1a
movq %rax, -0x30(%rbp)
movq 0x8(%rbx,%r14,8), %rdi
leaq 0x291b(%rip), %rsi      # 0x402a
callq 0x1b1a
movq %rax, %r14
movq 0x5a32(%rip), %rbx      # 0x7150
movq 0x58d3(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x297d(%rip), %rsi      # 0x40ac
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1150
leaq 0x2e8a(%rip), %rsi      # 0x45ca
movq %rbx, %rdi
callq 0x1b1a
movq %rax, %rbx
movq $0x0, 0x7a3a(%rip) # 0x9190
movl $0x0, 0x5a20(%rip)      # 0x7180
leaq 0x295f(%rip), %rsi      # 0x40c6
leaq -0x48(%rbp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x1070
cmpl $-0x1, %eax
je 0x17e7
leaq 0x5a0f(%rip), %r15      # 0x7190
leaq 0x293e(%rip), %r12      # 0x40c6
leaq -0x48(%rbp), %r13
movl 0x59ee(%rip), %eax      # 0x7180
cmpl $0x400, %eax            # imm = 0x400
jl 0x17ad
leaq 0x292b(%rip), %rdi      # 0x40cb
xorl %eax, %eax
callq 0x1a80
movl 0x59d3(%rip), %eax      # 0x7180
movsd -0x48(%rbp), %xmm0
cltq
movsd %xmm0, (%r15,%rax,8)
addsd 0x79ce(%rip), %xmm0     # 0x9190
movsd %xmm0, 0x79c6(%rip)     # 0x9190
incl %eax
movl %eax, 0x59ae(%rip)      # 0x7180
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1070
cmpl $-0x1, %eax
jne 0x178c
movq 0x580a(%rip), %rbx      # 0x6ff8
movq (%rbx), %rdi
movsd 0x7997(%rip), %xmm0     # 0x9190
leaq 0x28e8(%rip), %rsi      # 0x40e8
movb $0x1, %al
callq 0x1150
movq (%rbx), %rdi
movsd 0x5946(%rip), %xmm0     # 0x7158
leaq 0x2869(%rip), %rsi      # 0x4082
movb $0x1, %al
callq 0x1150
callq 0x1d8b
movq %rax, %r15
movq -0x30(%rbp), %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x21b1
leaq 0x285f(%rip), %rdx      # 0x409c
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2c4c
movl 0x8(%r15), %edi
decl %edi
movsd 0x27b0(%rip), %xmm0     # 0x4008
callq 0x1050
addsd 0x27ab(%rip), %xmm0     # 0x4010
movsd %xmm0, -0x40(%rbp)
movl (%r15), %edi
shll $0x3, %edi
callq 0x1b9f
movq %rax, -0x38(%rbp)
movl (%r15), %eax
testl %eax, %eax
movl $0x0, %edx
jle 0x1933
xorl %r12d, %r12d
movq -0x30(%rbp), %rbx
movq -0x38(%rbp), %r13
movl 0x58e6(%rip), %edi      # 0x7180
shll $0x3, %edi
callq 0x1b9f
movq %rax, (%r13,%r12,8)
movl 0x8(%r15), %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x165f(%rip), %rcx      # 0x2f17
callq 0x26b4
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd -0x40(%rbp), %xmm0
movq (%r13,%r12,8), %rax
movsd %xmm0, (%rax)
mulsd 0x587e(%rip), %xmm0     # 0x7158
movq %r14, %rdi
leaq 0x281e(%rip), %rsi      # 0x4102
movb $0x1, %al
callq 0x1150
incq %r12
movslq (%r15), %rax
cmpq %rax, %r12
jl 0x1894
testl %eax, %eax
jle 0x1931
movl 0x5880(%rip), %ecx      # 0x7180
xorl %edx, %edx
movq -0x38(%rbp), %r8
cmpl $0x2, %ecx
jl 0x1925
movq (%r8,%rdx,8), %rsi
movsd (%rsi), %xmm0
movl $0x1, %edi
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x1918
incq %rdx
cmpq %rax, %rdx
jne 0x1906
movl %eax, %edx
jmp 0x1933
xorl %edx, %edx
movl 0xc(%r15), %ecx
cmpl %ecx, %edx
movq -0x30(%rbp), %rdi
jge 0x1a1f
xorl %r13d, %r13d
leaq 0x5843(%rip), %rbx      # 0x7190
testl %eax, %eax
jle 0x1a15
movq %rdx, -0x50(%rbp)
xorl %r12d, %r12d
movl 0x8(%r15), %edx
movq %r14, %rsi
leaq 0x15ad(%rip), %rcx      # 0x2f17
callq 0x26b4
movsd 0x57e1(%rip), %xmm0     # 0x7158
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd -0x40(%rbp), %xmm1
movq -0x38(%rbp), %rax
movq (%rax,%r12,8), %rdi
movslq 0x57ee(%rip), %rsi      # 0x7180
movslq %r13d, %rax
movsd %xmm1, (%rdi,%rax,8)
testq %rsi, %rsi
jle 0x19d5
leaq (,%rsi,8), %r8
xorpd %xmm1, %xmm1
movl %r13d, %ecx
xorl %r9d, %r9d
movsd (%r9,%rbx), %xmm2
movl %ecx, %eax
cltd
idivl %esi
movslq %edx, %rax
mulsd (%rdi,%rax,8), %xmm2
addsd %xmm2, %xmm1
addq $0x8, %r9
incl %ecx
cmpq %r9, %r8
jne 0x19b1
jmp 0x19d9
xorpd %xmm1, %xmm1
incl %r13d
movl %r13d, %eax
cltd
idivl %esi
mulsd %xmm1, %xmm0
movl %edx, %r13d
movq %r14, %rdi
leaq 0x270f(%rip), %rsi      # 0x4102
movb $0x1, %al
callq 0x1150
incq %r12
movslq (%r15), %rax
cmpq %rax, %r12
movq -0x30(%rbp), %rdi
jl 0x195c
movl 0xc(%r15), %ecx
movq -0x50(%rbp), %rdx
incl %edx
cmpl %ecx, %edx
jl 0x194d
callq 0x10a0
movq %r14, %rdi
callq 0x10a0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x56fc(%rip), %rsi      # 0x7140
movq 0x56fd(%rip), %rdx      # 0x7148
leaq 0x26b4(%rip), %rdi      # 0x4106
xorl %eax, %eax
callq 0x10c0
jmp 0x1a73
leaq 0x26cd(%rip), %rdi      # 0x412f
callq 0x1080
leaq 0x26ce(%rip), %rdi      # 0x413c
callq 0x1080
xorl %edi, %edi
callq 0x1210
callq 0x1270
nop