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

    int i,j,maxValue;
    double ratio;
    int threshold;
    double attackDelta,releaseDelta;
    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: compress -fN [<input rra file> [<output rra file>]]\n");
        exit(-1);
        }

    h = newRRAHeader();
    
    readRRAHeader(in,h,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);
    attackDelta = peakRatio - 1;
    if (attack > 0)
        attackDelta = attackDelta / (attack * h->sampleRate);
    releaseDelta = peakRatio - 1;
    if (release > 0)
        releaseDelta = releaseDelta / (release * h->sampleRate);

    window = makeWindow(h->channels);

    fprintf(stderr,"threshold: %d\n",threshold);
    fprintf(stderr,"amplify; %f\n",amplify);
    //printf("attackdelta is %f\n",attackDelta);

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

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

            if (rms(i,amp,j) > threshold)
                {
                ratio = ratio + attackDelta;
                if (ratio > peakRatio) 
                    ratio = peakRatio;
                //printf("above threshold, ratio is %f\n",ratio);
                }
            else
                {
                ratio = ratio - releaseDelta;
                if (ratio < 1)
                    ratio = 1;
                //printf("below threshold, ratio is %f\n",ratio);
                }

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

    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 $0x48, %rsp
movq %rsi, %r14
movl %edi, %ebx
movl $0x1, %r12d
cmpl $0x2, %edi
jl 0x16d3
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x16d3
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 $0x67, %eax
jg 0x1646
cmpl $0x41, %eax
je 0x1671
cmpl $0x52, %eax
je 0x1680
cmpl $0x61, %eax
jne 0x16c0
callq 0x1080
movsd %xmm0, 0x5b2c(%rip)     # 0x7170
jmp 0x168d
cmpl $0x73, %eax
jg 0x165f
cmpl $0x72, %eax
jne 0x16ad
callq 0x1080
movsd %xmm0, 0x5afb(%rip)     # 0x7158
jmp 0x168d
cmpl $0x74, %eax
jne 0x16b7
callq 0x1200
movl %eax, 0x5ae1(%rip)      # 0x7150
jmp 0x168d
callq 0x1080
movsd %xmm0, 0x5ae2(%rip)     # 0x7160
jmp 0x168d
callq 0x1080
movsd %xmm0, 0x5adb(%rip)     # 0x7168
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %ebx, %r12d
jl 0x15f7
jmp 0x16d3
cmpl $0x68, %eax
jne 0x16c0
jmp 0x1a7d
cmpl $0x76, %eax
je 0x1a5c
xorl %r15d, %r15d
leaq 0x2a0d(%rip), %rdi      # 0x40d7
xorl %eax, %eax
callq 0x1bc0
jmp 0x1690
subl %r12d, %ebx
jne 0x16e4
movq 0x58f9(%rip), %rax      # 0x6fd8
movq (%rax), %rbx
jmp 0x1708
cmpl $0x2, %ebx
je 0x1714
cmpl $0x1, %ebx
jne 0x1ba7
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
leaq 0x3162(%rip), %rsi      # 0x4862
callq 0x1c5a
movq %rax, %rbx
movq 0x58c1(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x173e
movslq %r12d, %rbx
movq (%r14,%rbx,8), %rdi
leaq 0x3140(%rip), %rsi      # 0x4862
callq 0x1c5a
movq 0x8(%r14,%rbx,8), %rdi
movq %rax, %rbx
leaq 0x28f7(%rip), %rsi      # 0x402d
callq 0x1c5a
movq %rax, %r14
callq 0x1ecb
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x22f1
movl 0x8(%r15), %edi
decl %edi
movsd 0x28a7(%rip), %xmm0     # 0x4008
callq 0x1050
addsd 0x28a2(%rip), %xmm0     # 0x4010
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
cvtsi2sdl 0x59ce(%rip), %xmm1 # 0x7150
movsd 0x288e(%rip), %xmm0     # 0x4018
callq 0x1090
movsd 0x2879(%rip), %xmm3     # 0x4010
addsd 0x59b9(%rip), %xmm3     # 0x7158
movsd 0x59b9(%rip), %xmm2     # 0x7160
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
movsd %xmm3, -0x30(%rbp)
movsd %xmm3, -0x58(%rbp)
jbe 0x17d6
xorps %xmm3, %xmm3
cvtsi2sdl 0x4(%r15), %xmm3
mulsd %xmm3, %xmm2
movsd -0x30(%rbp), %xmm3
divsd %xmm2, %xmm3
movsd %xmm3, -0x58(%rbp)
mulsd -0x50(%rbp), %xmm0
movsd 0x5985(%rip), %xmm2     # 0x7168
ucomisd %xmm1, %xmm2
movq %rbx, -0x60(%rbp)
movq %r14, -0x38(%rbp)
jbe 0x180c
xorps %xmm1, %xmm1
cvtsi2sdl 0x4(%r15), %xmm1
mulsd %xmm1, %xmm2
movsd -0x30(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0x30(%rbp)
cvttsd2si %xmm0, %r12d
movq %r15, -0x40(%rbp)
movslq (%r15), %r14
leal (,%r14,8), %edi
callq 0x1cdf
movq %rax, %rbx
testq %r14, %r14
jle 0x1855
xorl %r13d, %r13d
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x1cdf
movq %rax, (%rbx,%r13,8)
movl $0x7d0, %edx            # imm = 0x7D0
movq %rax, %rdi
xorl %esi, %esi
callq 0x10e0
incq %r13
cmpq %r13, %r14
jne 0x1830
movq %rbx, 0x5944(%rip)      # 0x71a0
movq 0x5795(%rip), %rbx      # 0x6ff8
movq (%rbx), %rdi
leaq 0x27c2(%rip), %rsi      # 0x402f
xorl %r14d, %r14d
movl %r12d, %edx
xorl %eax, %eax
callq 0x1150
movq (%rbx), %rdi
movsd 0x58eb(%rip), %xmm0     # 0x7170
leaq 0x27b2(%rip), %rsi      # 0x403e
movb $0x1, %al
callq 0x1150
leaq 0x27b1(%rip), %rdx      # 0x404b
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
xorl %ecx, %ecx
callq 0x2d8c
movq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x1170
testl %eax, %eax
jne 0x1a0e
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd %xmm0, -0x70(%rbp)
xorl %r14d, %r14d
movsd 0x2733(%rip), %xmm0     # 0x4008
movsd %xmm0, -0x50(%rbp)
movq -0x40(%rbp), %rcx
cmpl $0x0, (%rcx)
movq %r14, -0x68(%rbp)
jle 0x19f7
movl %r14d, %eax
imulq $0x10624dd3, %rax, %rax # imm = 0x10624DD3
shrq $0x25, %rax
imull $0x1f4, %eax, %eax      # imm = 0x1F4
movl %r14d, %r13d
subl %eax, %r13d
leaq 0x58a4(%rip), %r12      # 0x71b0
xorl %r14d, %r14d
movq -0x38(%rbp), %r15
movl 0x8(%rcx), %edx
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x1734(%rip), %rcx      # 0x3057
callq 0x27f4
movl %eax, %ebx
movq 0x586f(%rip), %rax      # 0x71a0
movq (%rax,%r14,8), %rax
movl (%rax,%r13,4), %ecx
movl %ebx, %edx
subl %ecx, %edx
addl %ebx, %ecx
imull %edx, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
addsd (%r12), %xmm0
movsd %xmm0, (%r12)
movl %ebx, (%rax,%r13,4)
movsd 0x26bf(%rip), %xmm1     # 0x4020
callq 0x1090
ucomisd -0x70(%rbp), %xmm0
jbe 0x198b
movsd -0x50(%rbp), %xmm1
addsd -0x58(%rbp), %xmm1
movsd 0x57d9(%rip), %xmm0     # 0x7158
ucomisd %xmm0, %xmm1
jbe 0x19ab
movapd %xmm0, %xmm1
jmp 0x19ab
movsd -0x50(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
movsd 0x266b(%rip), %xmm0     # 0x4008
ucomisd %xmm1, %xmm0
jbe 0x19ab
movsd 0x265d(%rip), %xmm1     # 0x4008
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd 0x57b6(%rip), %xmm0     # 0x7170
movsd %xmm1, -0x50(%rbp)
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movq -0x38(%rbp), %r15
movq %r15, %rdi
leaq 0x2665(%rip), %rsi      # 0x403a
xorl %eax, %eax
callq 0x1150
incq %r14
movq -0x40(%rbp), %rcx
movslq (%rcx), %rax
addq $0x8, %r12
cmpq %rax, %r14
movq -0x60(%rbp), %rbx
jl 0x1913
movq -0x68(%rbp), %r14
incl %r14d
movq %rbx, %rdi
callq 0x1170
testl %eax, %eax
je 0x18da
movq -0x40(%rbp), %rax
movl 0xc(%rax), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r14d
jne 0x1a3f
movq %rbx, %rdi
callq 0x10a0
movq -0x38(%rbp), %rdi
callq 0x10a0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x55b2(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2610(%rip), %rsi      # 0x4060
movl %r14d, %edx
xorl %eax, %eax
callq 0x1150
jmp 0x1a1d
movq 0x56dd(%rip), %rsi      # 0x7140
movq 0x56de(%rip), %rdx      # 0x7148
leaq 0x2617(%rip), %rdi      # 0x4088
xorl %eax, %eax
callq 0x10c0
jmp 0x1ba0
leaq 0x26a8(%rip), %rdi      # 0x412c
callq 0x1070
leaq 0x26ae(%rip), %rdi      # 0x413e
callq 0x1070
leaq 0x26cb(%rip), %rdi      # 0x4167
callq 0x1070
movsd 0x56c7(%rip), %xmm0     # 0x7170
leaq 0x25e7(%rip), %rbx      # 0x4097
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x26d9(%rip), %rdi      # 0x419a
callq 0x1070
leaq 0x26f4(%rip), %rdi      # 0x41c1
callq 0x1070
leaq 0x2716(%rip), %rdi      # 0x41ef
callq 0x1070
movl 0x566c(%rip), %esi      # 0x7150
leaq 0x25cc(%rip), %rdi      # 0x40b7
xorl %eax, %eax
callq 0x10c0
leaq 0x2734(%rip), %rdi      # 0x422d
callq 0x1070
leaq 0x274e(%rip), %rdi      # 0x4253
callq 0x1070
leaq 0x276e(%rip), %rdi      # 0x427f
callq 0x1070
movsd 0x563a(%rip), %xmm0     # 0x7158
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x2781(%rip), %rdi      # 0x42b0
callq 0x1070
leaq 0x2798(%rip), %rdi      # 0x42d3
callq 0x1070
leaq 0x27bf(%rip), %rdi      # 0x4306
callq 0x1070
movsd 0x560c(%rip), %xmm0     # 0x7160
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x27e0(%rip), %rdi      # 0x4345
callq 0x1070
leaq 0x27f8(%rip), %rdi      # 0x4369
callq 0x1070
leaq 0x281e(%rip), %rdi      # 0x439b
callq 0x1070
movsd 0x55d6(%rip), %xmm0     # 0x7160
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x283d(%rip), %rdi      # 0x43d8
callq 0x1070
xorl %edi, %edi
callq 0x1210
leaq 0x2543(%rip), %rdi      # 0x40f1
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1210
nopl (%rax)