// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x16b0
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x0, %eax
jne 0x1378
movq 0x6c7a(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq 0x6c64(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x141f
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x1, %eax
jne 0x13af
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4272(%rip), %rsi      # 0x5608
callq 0x1b30
movq %rax, -0x38(%rbp)
movq 0x6c2a(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x141d
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x2, %eax
jne 0x13f9
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x423b(%rip), %rsi      # 0x5608
callq 0x1b30
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3c94(%rip), %rsi      # 0x5082
callq 0x1b30
movq %rax, -0x40(%rbp)
jmp 0x141b
movq 0x6bf8(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x3c7a(%rip), %rsi      # 0x5084
movb $0x0, %al
callq 0x1120
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x11e0
jmp 0x141d
jmp 0x141f
movq 0x6d0a(%rip), %rdi      # 0x8130
callq 0x1840
movq 0x6bc6(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movsd 0x6cfb(%rip), %xmm0     # 0x8138
leaq 0x3c96(%rip), %rsi      # 0x50da
movb $0x1, %al
callq 0x1120
callq 0x2010
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2510
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq 0x3c80(%rip), %rdx      # 0x50f4
xorl %eax, %eax
movl %eax, %ecx
callq 0x34b0
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
movsd 0x3b7d(%rip), %xmm0     # 0x5010
callq 0x1070
movsd 0x3b68(%rip), %xmm1     # 0x5008
subsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x48(%rbp), %rax
movslq (%rax), %rax
shlq $0x3, %rax
movl %eax, %edi
callq 0x1c30
movq %rax, -0x30(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1562
movslq 0x6c84(%rip), %rax      # 0x8160
shlq $0x3, %rax
movl %eax, %edi
callq 0x1c30
movq %rax, %rdx
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x23e4(%rip), %rcx      # 0x38f0
callq 0x2c40
cvtsi2sd %eax, %xmm0
divsd -0x28(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax)
movq -0x40(%rbp), %rdi
movsd 0x6c02(%rip), %xmm0     # 0x8138
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax), %xmm0
leaq 0x3c0d(%rip), %rsi      # 0x515a
movb $0x1, %al
callq 0x1120
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x14c6
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x15c3
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x6bdc(%rip), %eax      # 0x8160
jge 0x15b6
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x157b
jmp 0x15b8
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1569
movl $0x0, -0x20(%rbp)
movl -0x18(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x168b
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x167b
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x22ea(%rip), %rcx      # 0x38f0
callq 0x2c40
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movsd 0x6b1a(%rip), %xmm0     # 0x8138
movsd %xmm0, -0x58(%rbp)
cvtsi2sdl -0x4c(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl 0x6b21(%rip), %edx      # 0x8160
leaq 0x6b2a(%rip), %rsi      # 0x8170
leaq -0x20(%rbp), %rcx
callq 0x1930
movq -0x60(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
mulsd %xmm1, %xmm0
leaq 0x3af4(%rip), %rsi      # 0x515a
movb $0x1, %al
callq 0x1120
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x15e1
jmp 0x167d
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x15ca
movq -0x38(%rbp), %rdi
callq 0x1080
movq -0x40(%rbp), %rdi
callq 0x1080
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)