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

    int i,maxValue;
    int threshold;
    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
        {
        printf("usage: %s -fN [<input rra file> [<output rra file>]]\n",
            argv[0]);
        exit(-1);
        }

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

    if (h->channels != 1)
        Fatal("%s requires a mono audio file\n",argv[0]);

    //printf("%f,%f\n",pow(2,h->bitsPerSample-1)-1,pow(factor,thresholdDb));

    maxValue = pow(2,h->bitsPerSample-1)-1;
    threshold = maxValue * pow(factor,thresholdDb);

    double volumeUpDelta =  1.0 / secondsToSamples(volumeUpRamp);
    double volumeDownDelta =  1.0 / secondsToSamples(volumeDownRamp);
    int volumeUpWaitSamples =  secondsToSamples(volumeUpWait);
    int volumeDownWaitSamples =  secondsToSamples(volumeDownWait);

    window = makeWindow();

    fprintf(stderr,"threshold: %d\n",threshold);
    fprintf(stderr,"amplify; %f\n",amplify);
    fprintf(stderr,"volume down wait; %d\n",volumeDownWaitSamples);
    fprintf(stderr,"volume down delta; %f\n",volumeDownDelta);

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

    int reducing = 0;
    double transitionAttenuation = 1;
    int transitionSamples = 0;
    int bottomMessage = 1;
    int topMessage = 1;

    for (i = 0; !feof(in); ++i)
        {
        int amp = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);

        if (rms(i,amp) < threshold && i > windowSize)
            {
            if (!reducing) 
                {
                reducing = 1;
                transitionSamples = 0;
                fprintf(stderr,"waiting to reduce volume at %d samples\n",
                    i);
                fprintf(stderr,"attenuation is %f\n",transitionAttenuation);
                bottomMessage = 0;
                //getchar();
                }
            else if (transitionSamples < volumeDownWaitSamples)
                {
                ++transitionSamples;
                }
            else
                {
                transitionAttenuation -= volumeDownDelta;
                //fprintf(stderr,"reducing volume to %f at %d samples\n",
                    //transitionAttenuation,i);
                }
            }
        else if (i > windowSize)
            {
            if (reducing) 
                {
                reducing = 0;
                transitionSamples = 0;
                fprintf(stderr,"starting to increasing volume at %d samples\n",
                    i);
                fprintf(stderr,"attenuation is %f\n",transitionAttenuation);
                topMessage = 0;
                //getchar();
                }
            else if (transitionSamples < volumeUpWaitSamples)
                {
                ++transitionSamples;
                }
            else
                {
                transitionAttenuation += volumeUpDelta;
                //fprintf(stderr,"increasing volume to %f at %d samples\n",
                    //transitionAttenuation,i);
                }
            }
        if (transitionAttenuation > 1)
            {
            if (!topMessage)
                {
                fprintf(stderr,"at volume top\n");
                topMessage = 1;
                //getchar();
                }
            transitionAttenuation = 1;
            }
        else if (transitionAttenuation < 0)
            {
            if (!bottomMessage)
                {
                fprintf(stderr,"at volume bottom\n");
                bottomMessage = 1;
                //getchar();
                }
            transitionAttenuation = 0;
            }

        fprintf(out,"%d\n",(int) (amplify * amp * transitionAttenuation));
        }

    if (i != h->samples + 1)
        fprintf(stderr,"WARNING: %d samples found, %d expected\n",i,h->samples);

    fclose(in);
    fclose(out);

    return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r13
movl %edi, %ebx
movl $0x1, %r15d
cmpl $0x2, %edi
jl 0x2988
movl $0x1, %r15d
movslq %r15d, %rax
movq (%r13,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x2988
movb 0x2(%rsi), %r12b
testb %r12b, %r12b
je 0x28b7
leaq 0x2(%rsi), %rdi
jmp 0x28bc
movq 0x8(%r13,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x63, %eax
jle 0x28e7
cmpl $0x73, %eax
jle 0x2905
cmpl $0x74, %eax
je 0x2919
cmpl $0x75, %eax
jne 0x296c
callq 0x20b0
movsd %xmm0, 0xb8f3(%rip)     # 0xe1d8
jmp 0x2942
cmpl $0x44, %eax
je 0x2926
cmpl $0x55, %eax
je 0x2935
cmpl $0x61, %eax
jne 0x2975
callq 0x20b0
movsd %xmm0, 0xb8e5(%rip)     # 0xe1e8
jmp 0x2942
cmpl $0x64, %eax
jne 0x2962
callq 0x20b0
movsd %xmm0, 0xb8c9(%rip)     # 0xe1e0
jmp 0x2942
callq 0x22b0
movl %eax, 0xb89c(%rip)      # 0xe1c0
jmp 0x2942
callq 0x20b0
movsd %xmm0, 0xb89d(%rip)     # 0xe1d0
jmp 0x2942
callq 0x20b0
movsd %xmm0, 0xb886(%rip)     # 0xe1c8
movb $0x1, %r14b
testb %r12b, %r12b
sete %al
andb %r14b, %al
movzbl %al, %eax
addl %eax, %r15d
incl %r15d
cmpl %ebx, %r15d
jl 0x2897
jmp 0x2988
cmpl $0x68, %eax
jne 0x2975
jmp 0x2e44
cmpl $0x76, %eax
je 0x2fd9
xorl %r14d, %r14d
leaq 0x686a(%rip), %rdi      # 0x91e9
xorl %eax, %eax
callq 0x7020
jmp 0x2945
subl %r15d, %ebx
jne 0x2999
movq 0xb644(%rip), %rax      # 0xdfd8
movq (%rax), %r14
jmp 0x29be
cmpl $0x2, %ebx
je 0x29ca
cmpl $0x1, %ebx
jne 0x2ffc
movslq %r15d, %rax
movq (%r13,%rax,8), %rdi
leaq 0x6c41(%rip), %rsi      # 0x95f7
callq 0x70ba
movq %rax, %r14
movq 0xb60b(%rip), %rax      # 0xdfd0
movq (%rax), %rax
jmp 0x29f2
movslq %r15d, %rbx
movq (%r13,%rbx,8), %rdi
leaq 0x6c1e(%rip), %rsi      # 0x95f7
callq 0x70ba
movq %rax, %r14
movq 0x8(%r13,%rbx,8), %rdi
leaq 0x6648(%rip), %rsi      # 0x9035
callq 0x70ba
movq %rax, -0x40(%rbp)
callq 0x7337
movq %rax, %r15
xorl %r12d, %r12d
movq %r14, -0x80(%rbp)
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x7744
cmpl $0x1, (%r15)
je 0x2a2a
movq (%r13), %rsi
leaq 0x664a(%rip), %rdi      # 0x906d
xorl %eax, %eax
callq 0x7020
movl 0x8(%r15), %edi
decl %edi
movsd 0x65d0(%rip), %xmm0     # 0x9008
callq 0x2070
addsd 0x65cb(%rip), %xmm0     # 0x9010
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
cvtsi2sdl 0xb767(%rip), %xmm1 # 0xe1c0
movsd 0x65b7(%rip), %xmm0     # 0x9018
callq 0x20c0
mulsd -0x60(%rbp), %xmm0
cvttsd2si %xmm0, %ebx
movsd 0xb751(%rip), %xmm0     # 0xe1c8
callq 0x5efe
movsd %xmm0, -0x48(%rbp)
movsd 0xb747(%rip), %xmm0     # 0xe1d0
callq 0x5efe
movsd 0x6572(%rip), %xmm1     # 0x9008
divsd %xmm0, %xmm1
movsd %xmm1, -0x70(%rbp)
movsd 0xb731(%rip), %xmm0     # 0xe1d8
callq 0x5efe
movsd %xmm0, -0x30(%rbp)
movsd 0xb727(%rip), %xmm0     # 0xe1e0
callq 0x5efe
cvttsd2si %xmm0, %r14d
movl $0x7d0, %edi            # imm = 0x7D0
callq 0x714d
movq %rax, %r13
movl $0x7d0, %edx            # imm = 0x7D0
movq %rax, %rdi
xorl %esi, %esi
callq 0x2140
movq %r13, 0xb982(%rip)      # 0xe468
movq 0xb50b(%rip), %r13      # 0xdff8
movq (%r13), %rdi
leaq 0x6594(%rip), %rsi      # 0x908c
movl %ebx, -0x60(%rbp)
movl %ebx, %edx
xorl %eax, %eax
callq 0x21e0
movq (%r13), %rdi
movsd 0xb6d8(%rip), %xmm0     # 0xe1e8
leaq 0x6584(%rip), %rsi      # 0x909b
movb $0x1, %al
callq 0x21e0
movq (%r13), %rdi
leaq 0x657f(%rip), %rsi      # 0x90a8
movl %r14d, %edx
xorl %eax, %eax
callq 0x21e0
movq (%r13), %rdi
leaq 0x6580(%rip), %rsi      # 0x90be
movsd -0x70(%rbp), %xmm0
movb $0x1, %al
callq 0x21e0
leaq 0x6584(%rip), %rdx      # 0x90d5
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x8195
movq -0x80(%rbp), %r13
movq %r13, %rdi
callq 0x2200
testl %eax, %eax
jne 0x2dfa
movl %r14d, -0x68(%rbp)
movq %r15, -0x78(%rbp)
movsd 0x6482(%rip), %xmm1     # 0x9008
movapd %xmm1, %xmm0
divsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
cvttsd2si -0x30(%rbp), %eax
movl %eax, -0x64(%rbp)
xorps %xmm0, %xmm0
cvtsi2sdl -0x60(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movq %rbx, %rsi
movl $0x1, %ebx
xorl %r12d, %r12d
xorl %r15d, %r15d
movl $0x1, -0x34(%rbp)
movl $0x0, -0x48(%rbp)
movsd %xmm1, -0x60(%rbp)
movl $0x0, -0x30(%rbp)
movq %r12, %rax
shrq $0x2, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
shrq $0x4, %rdx
imulq $0x7d0, %rdx, %rax      # imm = 0x7D0
movq %r15, %r14
subq %rax, %r14
movq -0x78(%rbp), %rax
movl 0x8(%rax), %edx
movq %r13, %rdi
leaq 0x5854(%rip), %rcx      # 0x8461
callq 0x7c30
movl %eax, %r13d
movq 0xb84c(%rip), %rax      # 0xe468
movl (%rax,%r14), %ecx
movl %r13d, %edx
subl %ecx, %edx
addl %r13d, %ecx
imull %edx, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
addsd 0xb836(%rip), %xmm0     # 0xe470
movsd %xmm0, 0xb82e(%rip)     # 0xe470
movl %r13d, (%rax,%r14)
movsd 0x63d2(%rip), %xmm1     # 0x9020
callq 0x20c0
movsd -0x90(%rbp), %xmm1
ucomisd %xmm0, %xmm1
seta %al
cmpl $0x1f5, %r12d           # imm = 0x1F5
setae %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2c97
cmpl $0x0, -0x30(%rbp)
movsd -0x70(%rbp), %xmm0
movl -0x68(%rbp), %eax
movsd -0x60(%rbp), %xmm1
je 0x2d84
movl -0x48(%rbp), %ecx
cmpl %eax, %ecx
movl %ecx, %eax
jge 0x2cd0
incl %eax
jmp 0x2cd4
cmpl $0x1f5, %r12d           # imm = 0x1F5
movsd -0x60(%rbp), %xmm1
jb 0x2cc3
cmpl $0x0, -0x30(%rbp)
movsd 0x6357(%rip), %xmm0     # 0x9008
movl -0x48(%rbp), %eax
jne 0x2dbc
cmpl -0x64(%rbp), %eax
jge 0x2ce5
incl %eax
jmp 0x2ced
movsd 0x633d(%rip), %xmm0     # 0x9008
movl -0x48(%rbp), %eax
jmp 0x2cf4
subsd %xmm0, %xmm1
movl $0x1, -0x30(%rbp)
movsd 0x6325(%rip), %xmm0     # 0x9008
jmp 0x2cf4
addsd -0x88(%rbp), %xmm1
movl $0x0, -0x30(%rbp)
ucomisd %xmm0, %xmm1
movl %eax, -0x48(%rbp)
ja 0x2d21
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2d1c
xorpd %xmm1, %xmm1
cmpl $0x0, -0x34(%rbp)
je 0x2de5
movl $0x1, -0x34(%rbp)
movl %ebx, %r14d
jmp 0x2d2f
movl $0x1, %r14d
testl %ebx, %ebx
je 0x2daa
movapd %xmm0, %xmm1
movq -0x40(%rbp), %rbx
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
mulsd 0xb4a5(%rip), %xmm0     # 0xe1e8
movsd %xmm1, -0x60(%rbp)
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movq %rbx, %rdi
leaq 0x633d(%rip), %rsi      # 0x9097
xorl %eax, %eax
callq 0x21e0
incq %r12
movq -0x80(%rbp), %r13
movq %r13, %rdi
callq 0x2200
addq $0x4, %r15
movq %rbx, %rsi
movl %r14d, %ebx
testl %eax, %eax
je 0x2bd7
jmp 0x2df3
movl %r12d, %edi
movapd %xmm1, %xmm0
callq 0x2381
movsd -0x60(%rbp), %xmm1
xorl %eax, %eax
movl $0x1, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x2cdb
callq 0x23f1
movsd 0x6251(%rip), %xmm1     # 0x9008
jmp 0x2d2f
movl %r12d, %edi
movapd %xmm1, %xmm0
callq 0x2340
movsd -0x60(%rbp), %xmm1
movsd 0x6233(%rip), %xmm0     # 0x9008
movl $0x0, -0x30(%rbp)
xorl %eax, %eax
xorl %ebx, %ebx
jmp 0x2cf4
callq 0x23c2
xorpd %xmm1, %xmm1
jmp 0x2d15
movq %rsi, %rbx
movq -0x78(%rbp), %r15
movl 0xc(%r15), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r12d
jne 0x2e27
movq %r13, %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x20d0
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb1ca(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x633a(%rip), %rsi      # 0x9172
movl %r12d, %edx
xorl %eax, %eax
callq 0x21e0
jmp 0x2e06
leaq 0x63b8(%rip), %rdi      # 0x9203
callq 0x20a0
leaq 0x63b5(%rip), %rdi      # 0x920c
callq 0x20a0
leaq 0x63da(%rip), %rdi      # 0x923d
callq 0x20a0
leaq 0x63fa(%rip), %rdi      # 0x9269
callq 0x20a0
movl $0xa, %edi
callq 0x2050
leaq 0x640d(%rip), %rdi      # 0x9292
callq 0x20a0
leaq 0x6412(%rip), %rdi      # 0x92a3
callq 0x20a0
leaq 0x642f(%rip), %rdi      # 0x92cc
callq 0x20a0
movsd 0xb33e(%rip), %xmm0     # 0xe1e8
leaq 0x62f8(%rip), %rbx      # 0x91a9
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x643d(%rip), %rdi      # 0x92ff
callq 0x20a0
leaq 0x6458(%rip), %rdi      # 0x9326
callq 0x20a0
leaq 0x647c(%rip), %rdi      # 0x9356
callq 0x20a0
movl 0xb2db(%rip), %esi      # 0xe1c0
leaq 0x62dd(%rip), %rdi      # 0x91c9
xorl %eax, %eax
callq 0x2100
leaq 0x6498(%rip), %rdi      # 0x9392
callq 0x20a0
leaq 0x64bc(%rip), %rdi      # 0x93c2
callq 0x20a0
leaq 0x64f2(%rip), %rdi      # 0x9404
callq 0x20a0
movsd 0xb2b9(%rip), %xmm0     # 0xe1d8
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x6508(%rip), %rdi      # 0x9438
callq 0x20a0
leaq 0x652c(%rip), %rdi      # 0x9468
callq 0x20a0
leaq 0x6561(%rip), %rdi      # 0x94a9
callq 0x20a0
leaq 0x657e(%rip), %rdi      # 0x94d2
callq 0x20a0
movsd 0xb267(%rip), %xmm0     # 0xe1c8
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x658f(%rip), %rdi      # 0x9501
callq 0x20a0
leaq 0x65b5(%rip), %rdi      # 0x9533
callq 0x20a0
movsd 0xb255(%rip), %xmm0     # 0xe1e0
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x65cb(%rip), %rdi      # 0x9567
callq 0x20a0
leaq 0x65f1(%rip), %rdi      # 0x9599
callq 0x20a0
movsd 0xb21b(%rip), %xmm0     # 0xe1d0
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x6602(%rip), %rdi      # 0x95c8
callq 0x20a0
leaq 0x6627(%rip), %rdi      # 0x95f9
callq 0x20a0
jmp 0x2ff5
movq 0xb1d0(%rip), %rsi      # 0xe1b0
movq 0xb1d1(%rip), %rdx      # 0xe1b8
leaq 0x61ac(%rip), %rdi      # 0x919a
xorl %eax, %eax
callq 0x2100
xorl %edi, %edi
callq 0x22d0
movq (%r13), %rsi
leaq 0x6030(%rip), %rdi      # 0x9037
xorl %eax, %eax
callq 0x2100
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22d0