// File: /workspace/github_c_makefile_star2_O3/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 0x2958
movl $0x1, %r15d
movslq %r15d, %rax
movq (%r13,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x2958
movb 0x2(%rsi), %r12b
testb %r12b, %r12b
je 0x2887
leaq 0x2(%rsi), %rdi
jmp 0x288c
movq 0x8(%r13,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x63, %eax
jle 0x28b7
cmpl $0x73, %eax
jle 0x28d5
cmpl $0x74, %eax
je 0x28e9
cmpl $0x75, %eax
jne 0x293c
callq 0x20b0
movsd %xmm0, 0xb923(%rip)     # 0xe1d8
jmp 0x2912
cmpl $0x44, %eax
je 0x28f6
cmpl $0x55, %eax
je 0x2905
cmpl $0x61, %eax
jne 0x2945
callq 0x20b0
movsd %xmm0, 0xb915(%rip)     # 0xe1e8
jmp 0x2912
cmpl $0x64, %eax
jne 0x2932
callq 0x20b0
movsd %xmm0, 0xb8f9(%rip)     # 0xe1e0
jmp 0x2912
callq 0x22b0
movl %eax, 0xb8cc(%rip)      # 0xe1c0
jmp 0x2912
callq 0x20b0
movsd %xmm0, 0xb8cd(%rip)     # 0xe1d0
jmp 0x2912
callq 0x20b0
movsd %xmm0, 0xb8b6(%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 0x2867
jmp 0x2958
cmpl $0x68, %eax
jne 0x2945
jmp 0x2e40
cmpl $0x76, %eax
je 0x2fd5
xorl %r14d, %r14d
leaq 0x689a(%rip), %rdi      # 0x91e9
xorl %eax, %eax
callq 0x7174
jmp 0x2915
subl %r15d, %ebx
jne 0x2969
movq 0xb674(%rip), %rax      # 0xdfd8
movq (%rax), %r14
jmp 0x298e
cmpl $0x2, %ebx
je 0x299a
cmpl $0x1, %ebx
jne 0x2ff8
movslq %r15d, %rax
movq (%r13,%rax,8), %rdi
leaq 0x6c71(%rip), %rsi      # 0x95f7
callq 0x720e
movq %rax, %r14
movq 0xb63b(%rip), %rax      # 0xdfd0
movq (%rax), %r15
jmp 0x29c5
movslq %r15d, %rbx
movq (%r13,%rbx,8), %rdi
leaq 0x6c4e(%rip), %rsi      # 0x95f7
callq 0x720e
movq %rax, %r14
movq 0x8(%r13,%rbx,8), %rdi
leaq 0x6678(%rip), %rsi      # 0x9035
callq 0x720e
movq %rax, %r15
callq 0x747f
movq %rax, %rbx
xorl %r12d, %r12d
movq %r14, -0x78(%rbp)
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x78a5
cmpl $0x1, (%rbx)
je 0x29f8
movq (%r13), %rsi
leaq 0x667c(%rip), %rdi      # 0x906d
xorl %eax, %eax
callq 0x7174
movl 0x8(%rbx), %edi
decl %edi
movsd 0x6603(%rip), %xmm0     # 0x9008
callq 0x2070
addsd 0x65fe(%rip), %xmm0     # 0x9010
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
cvtsi2sdl 0xb79a(%rip), %xmm1 # 0xe1c0
movsd 0x65ea(%rip), %xmm0     # 0x9018
callq 0x20c0
mulsd -0x60(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x60(%rbp)
movsd 0xb781(%rip), %xmm0     # 0xe1c8
callq 0x6004
movsd %xmm0, -0x40(%rbp)
movsd 0xb777(%rip), %xmm0     # 0xe1d0
callq 0x6004
movsd 0x65a2(%rip), %xmm1     # 0x9008
divsd %xmm0, %xmm1
movsd %xmm1, -0x70(%rbp)
movsd 0xb761(%rip), %xmm0     # 0xe1d8
callq 0x6004
movsd %xmm0, -0x30(%rbp)
movsd 0xb757(%rip), %xmm0     # 0xe1e0
callq 0x6004
cvttsd2si %xmm0, %r14d
movl $0x7d0, %edi            # imm = 0x7D0
callq 0x7293
movq %rax, %r13
movl $0x7d0, %edx            # imm = 0x7D0
movq %rax, %rdi
xorl %esi, %esi
callq 0x2140
movq %r13, 0xb9b2(%rip)      # 0xe468
movq 0xb53b(%rip), %r13      # 0xdff8
movq (%r13), %rdi
leaq 0x65c4(%rip), %rsi      # 0x908c
movl -0x60(%rbp), %edx
xorl %eax, %eax
callq 0x21e0
movq (%r13), %rdi
movsd 0xb70a(%rip), %xmm0     # 0xe1e8
leaq 0x65b6(%rip), %rsi      # 0x909b
movb $0x1, %al
callq 0x21e0
movq (%r13), %rdi
leaq 0x65b1(%rip), %rsi      # 0x90a8
movl %r14d, %edx
xorl %eax, %eax
callq 0x21e0
movq (%r13), %rdi
leaq 0x65b2(%rip), %rsi      # 0x90be
movsd -0x70(%rbp), %xmm0
movb $0x1, %al
callq 0x21e0
leaq 0x65b6(%rip), %rdx      # 0x90d5
movq %r15, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x8340
movq -0x78(%rbp), %r13
movq %r13, %rdi
callq 0x2200
testl %eax, %eax
je 0x2b6c
movl 0xc(%rbx), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r12d
jne 0x2e20
movq %r13, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x20d0
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, -0x68(%rbp)
movsd 0x6490(%rip), %xmm1     # 0x9008
movapd %xmm1, %xmm0
cvttsd2si -0x30(%rbp), %eax
movl %eax, -0x64(%rbp)
divsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
cvtsi2sdl -0x60(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movl $0x1, -0x38(%rbp)
xorl %r12d, %r12d
xorl %r14d, %r14d
movl $0x1, -0x34(%rbp)
movl $0x0, -0x40(%rbp)
movsd %xmm1, -0x60(%rbp)
movl $0x0, -0x30(%rbp)
movq %rbx, -0x48(%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, %rsi
movq %r14, %r15
subq %rax, %r15
movl 0x8(%rbx), %edx
movq %r13, %rdi
movq %rsi, %rbx
leaq 0x5a0a(%rip), %rcx      # 0x860b
callq 0x7da8
movl %eax, %r13d
movq 0xb858(%rip), %rax      # 0xe468
movl (%rax,%r15), %ecx
movl %r13d, %edx
subl %ecx, %edx
addl %r13d, %ecx
imull %edx, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
addsd 0xb842(%rip), %xmm0     # 0xe470
movsd %xmm0, 0xb83a(%rip)     # 0xe470
movl %r13d, (%rax,%r15)
movsd 0x63de(%rip), %xmm1     # 0x9020
callq 0x20c0
movsd -0x88(%rbp), %xmm1
ucomisd %xmm0, %xmm1
seta %al
cmpl $0x1f5, %r12d           # imm = 0x1F5
setae %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2c8a
cmpl $0x0, -0x30(%rbp)
movsd -0x70(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
je 0x2d83
movl -0x40(%rbp), %eax
cmpl -0x68(%rbp), %eax
movq %rbx, %r15
jge 0x2cd1
incl %eax
jmp 0x2cd5
cmpl $0x1f5, %r12d           # imm = 0x1F5
movsd -0x60(%rbp), %xmm1
jb 0x2cbd
cmpl $0x0, -0x30(%rbp)
movq %rbx, %r15
movsd 0x6361(%rip), %xmm0     # 0x9008
movl -0x40(%rbp), %eax
jne 0x2dac
cmpl -0x64(%rbp), %eax
movq -0x48(%rbp), %rbx
jge 0x2cea
incl %eax
jmp 0x2cef
movq %rbx, %r15
movq -0x48(%rbp), %rbx
movsd 0x633c(%rip), %xmm0     # 0x9008
movl -0x40(%rbp), %eax
jmp 0x2cf6
subsd %xmm0, %xmm1
movl $0x1, -0x30(%rbp)
movq -0x48(%rbp), %rbx
movsd 0x6320(%rip), %xmm0     # 0x9008
jmp 0x2cf6
addsd -0x80(%rbp), %xmm1
movl $0x0, -0x30(%rbp)
movl %eax, -0x40(%rbp)
ucomisd %xmm0, %xmm1
ja 0x2d20
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2d35
xorpd %xmm1, %xmm1
cmpl $0x0, -0x34(%rbp)
je 0x2e12
movl $0x1, -0x34(%rbp)
jmp 0x2d35
movapd %xmm0, %xmm1
cmpl $0x0, -0x38(%rbp)
movl $0x1, -0x38(%rbp)
je 0x2dde
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
mulsd 0xb4a3(%rip), %xmm0     # 0xe1e8
movsd %xmm1, -0x60(%rbp)
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movq %r15, %rdi
leaq 0x633b(%rip), %rsi      # 0x9097
xorl %eax, %eax
callq 0x21e0
incq %r12
movq -0x78(%rbp), %r13
movq %r13, %rdi
callq 0x2200
addq $0x4, %r14
testl %eax, %eax
je 0x2bc9
jmp 0x2b3c
movl %r12d, %edi
movapd %xmm1, %xmm0
callq 0x2397
movsd -0x60(%rbp), %xmm1
xorl %eax, %eax
movl $0x1, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq %rbx, %r15
jmp 0x2cdc
movl %r12d, %edi
movapd %xmm1, %xmm0
callq 0x2340
movsd -0x60(%rbp), %xmm1
movl $0x0, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x38(%rbp)
testb $0x1, %al
movq -0x48(%rbp), %rbx
je 0x2cff
movq 0xb213(%rip), %rax      # 0xdff8
movq (%rax), %rcx
movl $0xe, %esi
movl $0x1, %edx
leaq 0x6358(%rip), %rdi      # 0x9151
callq 0x22e0
movl $0x1, -0x38(%rbp)
movsd 0x61fb(%rip), %xmm1     # 0x9008
jmp 0x2d35
callq 0x23d8
xorpd %xmm1, %xmm1
jmp 0x2d17
movq 0xb1d1(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x6341(%rip), %rsi      # 0x9172
movl %r12d, %edx
xorl %eax, %eax
callq 0x21e0
jmp 0x2b4b
leaq 0x63bc(%rip), %rdi      # 0x9203
callq 0x20a0
leaq 0x63b9(%rip), %rdi      # 0x920c
callq 0x20a0
leaq 0x63de(%rip), %rdi      # 0x923d
callq 0x20a0
leaq 0x63fe(%rip), %rdi      # 0x9269
callq 0x20a0
movl $0xa, %edi
callq 0x2050
leaq 0x6411(%rip), %rdi      # 0x9292
callq 0x20a0
leaq 0x6416(%rip), %rdi      # 0x92a3
callq 0x20a0
leaq 0x6433(%rip), %rdi      # 0x92cc
callq 0x20a0
movsd 0xb342(%rip), %xmm0     # 0xe1e8
leaq 0x62fc(%rip), %rbx      # 0x91a9
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x6441(%rip), %rdi      # 0x92ff
callq 0x20a0
leaq 0x645c(%rip), %rdi      # 0x9326
callq 0x20a0
leaq 0x6480(%rip), %rdi      # 0x9356
callq 0x20a0
movl 0xb2df(%rip), %esi      # 0xe1c0
leaq 0x62e1(%rip), %rdi      # 0x91c9
xorl %eax, %eax
callq 0x2100
leaq 0x649c(%rip), %rdi      # 0x9392
callq 0x20a0
leaq 0x64c0(%rip), %rdi      # 0x93c2
callq 0x20a0
leaq 0x64f6(%rip), %rdi      # 0x9404
callq 0x20a0
movsd 0xb2bd(%rip), %xmm0     # 0xe1d8
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x650c(%rip), %rdi      # 0x9438
callq 0x20a0
leaq 0x6530(%rip), %rdi      # 0x9468
callq 0x20a0
leaq 0x6565(%rip), %rdi      # 0x94a9
callq 0x20a0
leaq 0x6582(%rip), %rdi      # 0x94d2
callq 0x20a0
movsd 0xb26b(%rip), %xmm0     # 0xe1c8
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x6593(%rip), %rdi      # 0x9501
callq 0x20a0
leaq 0x65b9(%rip), %rdi      # 0x9533
callq 0x20a0
movsd 0xb259(%rip), %xmm0     # 0xe1e0
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x65cf(%rip), %rdi      # 0x9567
callq 0x20a0
leaq 0x65f5(%rip), %rdi      # 0x9599
callq 0x20a0
movsd 0xb21f(%rip), %xmm0     # 0xe1d0
movq %rbx, %rdi
movb $0x1, %al
callq 0x2100
leaq 0x6606(%rip), %rdi      # 0x95c8
callq 0x20a0
leaq 0x662b(%rip), %rdi      # 0x95f9
callq 0x20a0
jmp 0x2ff1
movq 0xb1d4(%rip), %rsi      # 0xe1b0
movq 0xb1d5(%rip), %rdx      # 0xe1b8
leaq 0x61b0(%rip), %rdi      # 0x919a
xorl %eax, %eax
callq 0x2100
xorl %edi, %edi
callq 0x22d0
movq (%r13), %rsi
leaq 0x6034(%rip), %rdi      # 0x9037
xorl %eax, %eax
callq 0x2100
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22d0