// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rsi, %r14
movl %edi, %ebx
movl $0x1, %r12d
cmpl $0x2, %edi
jl 0x1687
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x1687
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x1616
leaq 0x2(%rsi), %rdi
jmp 0x161b
movq 0x8(%r14,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x65, %eax
jle 0x1632
cmpl $0x66, %eax
jne 0x1649
movq %rdi, 0x5b20(%rip)      # 0x7150
jmp 0x1644
cmpl $0x61, %eax
jne 0x165b
callq 0x1090
movsd %xmm0, 0x5b14(%rip)     # 0x7158
movb $0x1, %r15b
jmp 0x166c
cmpl $0x68, %eax
je 0x1a3e
cmpl $0x76, %eax
je 0x1a20
xorl %r15d, %r15d
leaq 0x2ab0(%rip), %rdi      # 0x4115
xorl %eax, %eax
callq 0x1a64
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %ebx, %r12d
jl 0x15f7
subl %r12d, %ebx
jne 0x1698
movq 0x5945(%rip), %rax      # 0x6fd8
movq (%rax), %rax
jmp 0x16b9
cmpl $0x2, %ebx
je 0x16c9
cmpl $0x1, %ebx
jne 0x1a5d
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
leaq 0x2f19(%rip), %rsi      # 0x45cd
callq 0x1afe
movq %rax, -0x30(%rbp)
movq 0x590c(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x16f4
movslq %r12d, %rbx
movq (%r14,%rbx,8), %rdi
leaq 0x2ef6(%rip), %rsi      # 0x45cd
callq 0x1afe
movq %rax, -0x30(%rbp)
movq 0x8(%r14,%rbx,8), %rdi
leaq 0x293e(%rip), %rsi      # 0x402a
callq 0x1afe
movq %rax, %r14
movq 0x5a55(%rip), %rbx      # 0x7150
movq 0x58f6(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x29a0(%rip), %rsi      # 0x40ac
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1150
leaq 0x2eb0(%rip), %rsi      # 0x45cd
movq %rbx, %rdi
callq 0x1afe
movq %rax, %rbx
movq $0x0, 0x7a5d(%rip) # 0x9190
movl $0x0, 0x5a43(%rip)      # 0x7180
leaq 0x2982(%rip), %rsi      # 0x40c6
leaq -0x48(%rbp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x1070
cmpl $-0x1, %eax
je 0x17c2
leaq 0x5a32(%rip), %r15      # 0x7190
leaq 0x2961(%rip), %r12      # 0x40c6
leaq -0x48(%rbp), %r13
cmpl $0x400, 0x5a0d(%rip)    # imm = 0x400
jl 0x1783
leaq 0x294f(%rip), %rdi      # 0x40cb
xorl %eax, %eax
callq 0x1a64
movsd -0x48(%rbp), %xmm0
movslq 0x59f1(%rip), %rax      # 0x7180
movsd %xmm0, (%r15,%rax,8)
addsd 0x79f3(%rip), %xmm0     # 0x9190
movsd %xmm0, 0x79eb(%rip)     # 0x9190
incl %eax
movl %eax, 0x59d3(%rip)      # 0x7180
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1070
cmpl $-0x1, %eax
jne 0x1769
movq 0x582f(%rip), %rbx      # 0x6ff8
movq (%rbx), %rdi
movsd 0x79bc(%rip), %xmm0     # 0x9190
leaq 0x290d(%rip), %rsi      # 0x40e8
movb $0x1, %al
callq 0x1150
movq (%rbx), %rdi
movsd 0x596b(%rip), %xmm0     # 0x7158
leaq 0x288e(%rip), %rsi      # 0x4082
movb $0x1, %al
callq 0x1150
callq 0x1d7b
movq %rax, %r15
xorl %r12d, %r12d
movq -0x30(%rbp), %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x2188
leaq 0x2881(%rip), %rdx      # 0x409c
movq %r14, -0x38(%rbp)
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2bd9
movl 0x8(%r15), %edi
decl %edi
movsd 0x27ce(%rip), %xmm0     # 0x4008
callq 0x1050
addsd 0x27c9(%rip), %xmm0     # 0x4010
movsd %xmm0, -0x40(%rbp)
movl (%r15), %edi
shll $0x3, %edi
callq 0x1b91
movl (%r15), %ecx
testl %ecx, %ecx
jle 0x18d2
xorl %r12d, %r12d
movq -0x30(%rbp), %rbx
movq %rax, %r14
movq -0x38(%rbp), %r13
movl 0x590e(%rip), %edi      # 0x7180
shll $0x3, %edi
callq 0x1b91
movq %rax, (%r14,%r12,8)
movl 0x8(%r15), %edx
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x1616(%rip), %rcx      # 0x2ea5
callq 0x2674
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd -0x40(%rbp), %xmm0
movq (%r14,%r12,8), %rax
movsd %xmm0, (%rax)
mulsd 0x58a8(%rip), %xmm0     # 0x7158
movq %r13, %rdi
leaq 0x2848(%rip), %rsi      # 0x4102
movb $0x1, %al
callq 0x1150
incq %r12
movslq (%r15), %rcx
cmpq %rcx, %r12
jl 0x186c
xorl %r12d, %r12d
movq %r14, %rax
testl %ecx, %ecx
movq -0x30(%rbp), %rdi
jle 0x190e
movl 0x589f(%rip), %r8d      # 0x7180
movl %ecx, %ecx
xorl %r12d, %r12d
cmpl $0x2, %r8d
jl 0x1906
movq (%rax,%r12,8), %rdx
movl $0x1, %esi
movsd (%rdx), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %r8
jne 0x18f5
incq %r12
cmpq %rcx, %r12
jne 0x18e6
movq %rax, -0x58(%rbp)
cmpl 0xc(%r15), %r12d
jge 0x1a01
xorl %r13d, %r13d
leaq 0x586a(%rip), %rbx      # 0x7190
movq %r12, -0x50(%rbp)
cmpl $0x0, (%r15)
jle 0x19f0
xorl %r12d, %r12d
movq -0x38(%rbp), %r14
movl 0x8(%r15), %edx
movq %r14, %rsi
leaq 0x155c(%rip), %rcx      # 0x2ea5
callq 0x2674
movsd 0x5802(%rip), %xmm0     # 0x7158
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd -0x40(%rbp), %xmm1
movq -0x58(%rbp), %rax
movq (%rax,%r12,8), %rdi
movslq 0x580f(%rip), %rsi      # 0x7180
movslq %r13d, %rax
movsd %xmm1, (%rdi,%rax,8)
testq %rsi, %rsi
jle 0x19b4
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 0x1990
jmp 0x19b8
xorpd %xmm1, %xmm1
incl %r13d
movl %r13d, %eax
cltd
idivl %esi
mulsd %xmm1, %xmm0
movl %edx, %r13d
movq -0x38(%rbp), %r14
movq %r14, %rdi
leaq 0x272c(%rip), %rsi      # 0x4102
movb $0x1, %al
callq 0x1150
incq %r12
movslq (%r15), %rax
cmpq %rax, %r12
movq -0x30(%rbp), %rdi
jl 0x193b
movq -0x50(%rbp), %r12
incl %r12d
cmpl 0xc(%r15), %r12d
jl 0x1926
callq 0x10a0
movq -0x38(%rbp), %rdi
callq 0x10a0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5719(%rip), %rsi      # 0x7140
movq 0x571a(%rip), %rdx      # 0x7148
leaq 0x26d1(%rip), %rdi      # 0x4106
xorl %eax, %eax
callq 0x10c0
jmp 0x1a56
leaq 0x26ea(%rip), %rdi      # 0x412f
callq 0x1080
leaq 0x26eb(%rip), %rdi      # 0x413c
callq 0x1080
xorl %edi, %edi
callq 0x1210
callq 0x1270
nop