// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %r12
movslq %r12d, %r15
cmpl %r12d, %r14d
jle 0x1403
movq (%rbx,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x1403
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x139b
leaq 0x2(%rsi), %rdi
jmp 0x13a0
movq 0x8(%rbx,%r15,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x61, %eax
je 0x13d3
cmpl $0x66, %eax
je 0x13e2
cmpl $0x68, %eax
je 0x1741
cmpl $0x76, %eax
je 0x175b
xorl %r15d, %r15d
leaq 0x2d4b(%rip), %rdi      # 0x4115
xorl %eax, %eax
callq 0x17a4
jmp 0x13ec
callq 0x1090
movsd %xmm0, 0x5d78(%rip)     # 0x7158
jmp 0x13e9
movq %rdi, 0x5d67(%rip)      # 0x7150
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
jmp 0x1377
subl %r12d, %r14d
jne 0x1414
movq 0x5bc9(%rip), %rax      # 0x6fd8
movq (%rax), %rax
jmp 0x1434
cmpl $0x2, %r14d
je 0x1444
cmpl $0x1, %r14d
jne 0x177e
movq (%rbx,%r15,8), %rdi
leaq 0x319b(%rip), %rsi      # 0x45ca
callq 0x18d4
movq %rax, -0x38(%rbp)
movq 0x5b91(%rip), %rax      # 0x6fd0
movq (%rax), %rax
jmp 0x1469
movq (%rbx,%r15,8), %rdi
leaq 0x317b(%rip), %rsi      # 0x45ca
callq 0x18d4
movq %rax, -0x38(%rbp)
movq 0x8(%rbx,%r15,8), %rdi
leaq 0x2bc6(%rip), %rsi      # 0x402a
callq 0x18d4
movq %rax, -0x30(%rbp)
movq 0x5cdc(%rip), %rbx      # 0x7150
movq 0x5b7d(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2c27(%rip), %rsi      # 0x40ac
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1150
leaq 0x3134(%rip), %rsi      # 0x45ca
movq %rbx, %rdi
callq 0x18d4
movq %rax, %rbx
andq $0x0, 0x7ce7(%rip)      # 0x9190
leaq 0x2c16(%rip), %r15      # 0x40c6
leaq -0x50(%rbp), %r12
leaq 0x2c10(%rip), %r13      # 0x40cb
leaq 0x5cce(%rip), %r14      # 0x7190
xorl %eax, %eax
movl %eax, 0x5cb6(%rip)      # 0x7180
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1070
cmpl $-0x1, %eax
je 0x151d
movl 0x5c9b(%rip), %eax      # 0x7180
cmpl $0x400, %eax            # imm = 0x400
jl 0x14fc
movq %r13, %rdi
xorl %eax, %eax
callq 0x17a4
movl 0x5c84(%rip), %eax      # 0x7180
movsd -0x50(%rbp), %xmm0
cltq
movsd %xmm0, (%r14,%rax,8)
addsd 0x7c7f(%rip), %xmm0     # 0x9190
movsd %xmm0, 0x7c77(%rip)     # 0x9190
incl %eax
jmp 0x14c4
movq 0x5ad4(%rip), %rbx      # 0x6ff8
movq (%rbx), %rdi
movsd 0x7c61(%rip), %xmm0     # 0x9190
leaq 0x2bb2(%rip), %rsi      # 0x40e8
movb $0x1, %al
callq 0x1150
movq (%rbx), %rdi
movsd 0x5c10(%rip), %xmm0     # 0x7158
leaq 0x2b33(%rip), %rsi      # 0x4082
movb $0x1, %al
callq 0x1150
callq 0x1b30
movq %rax, %r15
xorl %ebx, %ebx
movq -0x38(%rbp), %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x1e95
leaq 0x2b27(%rip), %rdx      # 0x409c
movq -0x30(%rbp), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x28a4
movl 0x8(%r15), %edi
decl %edi
movsd 0x2a77(%rip), %xmm0     # 0x4008
callq 0x1050
addsd 0x2a72(%rip), %xmm0     # 0x4010
movsd %xmm0, -0x40(%rbp)
movl (%r15), %edi
shll $0x3, %edi
callq 0x1959
movq %rax, %r12
movq -0x30(%rbp), %r13
movslq (%r15), %rax
movslq 0x5bc1(%rip), %rdi      # 0x7180
cmpq %rax, %rbx
jge 0x1616
shll $0x3, %edi
callq 0x1959
movq %rax, (%r12,%rbx,8)
movl 0x8(%r15), %edx
movq -0x38(%rbp), %rdi
movq %r13, %rsi
leaq 0x154f(%rip), %rcx      # 0x2b31
callq 0x236a
cvtsi2sd %eax, %xmm0
divsd -0x40(%rbp), %xmm0
movq (%r12,%rbx,8), %rax
movsd %xmm0, (%rax)
mulsd 0x5b58(%rip), %xmm0     # 0x7158
movq %r13, %rdi
leaq 0x2af8(%rip), %rsi      # 0x4102
movb $0x1, %al
callq 0x1150
incq %rbx
jmp 0x15b5
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %r9d
cmovgl %eax, %r9d
pushq $0x1
popq %rdx
cmpq %r9, %rcx
je 0x164d
movq %rdx, %rsi
cmpq %rdi, %rsi
jge 0x1648
movq (%r12,%rcx,8), %r8
movsd (%r8), %xmm0
movsd %xmm0, (%r8,%rsi,8)
incq %rsi
jmp 0x162f
incq %rcx
jmp 0x1627
xorl %r13d, %r13d
cmpl 0xc(%r15), %r9d
jge 0x171e
movq %r9, -0x48(%rbp)
xorl %ebx, %ebx
movslq %eax, %rcx
cmpq %rcx, %rbx
jge 0x1712
movl 0x8(%r15), %edx
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x14b2(%rip), %rcx      # 0x2b31
callq 0x236a
movsd 0x5acc(%rip), %xmm0     # 0x7158
cvtsi2sd %eax, %xmm1
divsd -0x40(%rbp), %xmm1
movq (%r12,%rbx,8), %rdi
movl 0x5ae1(%rip), %esi      # 0x7180
movslq %r13d, %rax
movsd %xmm1, (%rdi,%rax,8)
testl %esi, %esi
movl $0x0, %r8d
cmovgl %esi, %r8d
shlq $0x3, %r8
xorpd %xmm1, %xmm1
xorl %r9d, %r9d
movl %r13d, %ecx
cmpq %r9, %r8
je 0x16e5
movsd (%r9,%r14), %xmm2
movl %ecx, %eax
cltd
idivl %esi
movslq %edx, %rax
mulsd (%rdi,%rax,8), %xmm2
addsd %xmm2, %xmm1
incl %ecx
addq $0x8, %r9
jmp 0x16c1
incl %r13d
movl %r13d, %eax
cltd
idivl %esi
mulsd %xmm1, %xmm0
movl %edx, %r13d
movq -0x30(%rbp), %rdi
leaq 0x2a02(%rip), %rsi      # 0x4102
movb $0x1, %al
callq 0x1150
incq %rbx
movl (%r15), %eax
jmp 0x1660
movq -0x48(%rbp), %r9
incl %r9d
jmp 0x1650
movq -0x38(%rbp), %rdi
callq 0x10a0
movq -0x30(%rbp), %rdi
callq 0x10a0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x29e7(%rip), %rdi      # 0x412f
callq 0x1080
leaq 0x29e8(%rip), %rdi      # 0x413c
callq 0x1080
jmp 0x1777
movq 0x59de(%rip), %rsi      # 0x7140
movq 0x59df(%rip), %rdx      # 0x7148
leaq 0x2996(%rip), %rdi      # 0x4106
xorl %eax, %eax
callq 0x10c0
xorl %edi, %edi
callq 0x1210
movq 0x5873(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x289d(%rip), %rdi      # 0x402c
pushq $0x55
popq %rsi
pushq $0x1
popq %rdx
callq 0x1220
pushq $-0x1
popq %rdi
callq 0x1210
nop