// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %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 0x16f0
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x0, %eax
jne 0x1368
movq 0x6c8a(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq 0x6c74(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x1405
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x1, %eax
jne 0x139f
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x45aa(%rip), %rsi      # 0x5930
callq 0x1cb0
movq %rax, -0x48(%rbp)
movq 0x6c3a(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x1403
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x2, %eax
jne 0x13e9
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4573(%rip), %rsi      # 0x5930
callq 0x1cb0
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3d27(%rip), %rsi      # 0x5105
callq 0x1cb0
movq %rax, -0x50(%rbp)
jmp 0x1401
leaq 0x3d17(%rip), %rdi      # 0x5107
movb $0x0, %al
callq 0x1090
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x11d0
jmp 0x1403
jmp 0x1405
callq 0x2190
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2690
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
movsd 0x3be3(%rip), %xmm0     # 0x5018
callq 0x1060
movsd 0x3bc6(%rip), %xmm1     # 0x5008
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x20(%rbp)
cvtsi2sdl -0x20(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
cvtsi2sdl 0x6cc9(%rip), %xmm1 # 0x8128
movsd 0x3ba9(%rip), %xmm0     # 0x5010
callq 0x1060
movaps %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
movsd 0x6ca9(%rip), %xmm0     # 0x8130
movsd 0x3b79(%rip), %xmm1     # 0x5008
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x6c98(%rip), %xmm0     # 0x8138
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x14cc
movsd -0x38(%rbp), %xmm0
movsd 0x6c82(%rip), %xmm1     # 0x8138
movq -0x58(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm2
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x6c5c(%rip), %xmm0     # 0x8130
movsd 0x3b2c(%rip), %xmm1     # 0x5008
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x6c53(%rip), %xmm0     # 0x8140
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1519
movsd -0x40(%rbp), %xmm0
movsd 0x6c3d(%rip), %xmm1     # 0x8140
movq -0x58(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm2
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %edi
callq 0x1a10
movq %rax, 0x6c45(%rip)      # 0x8170
movq 0x6ac6(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x2c(%rbp), %edx
leaq 0x3c04(%rip), %rsi      # 0x5143
movb $0x0, %al
callq 0x1110
movq 0x6aab(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movsd 0x6bf0(%rip), %xmm0     # 0x8148
leaq 0x3bf3(%rip), %rsi      # 0x5152
movb $0x1, %al
callq 0x1110
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq 0x3bea(%rip), %rdx      # 0x515f
xorl %eax, %eax
movl %eax, %ecx
callq 0x3630
movsd 0x3a82(%rip), %xmm0     # 0x5008
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1130
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x15ac
jmp 0x169d
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x168d
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x2498(%rip), %rcx      # 0x3a70
callq 0x2dc0
movl %eax, -0x5c(%rbp)
movl -0x18(%rbp), %edi
movl -0x5c(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x1ab0
cvtsi2sdl -0x2c(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1626
movsd -0x28(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
ucomisd 0x6b1b(%rip), %xmm0     # 0x8130
jbe 0x1624
movsd 0x6b11(%rip), %xmm0     # 0x8130
movsd %xmm0, -0x28(%rbp)
jmp 0x1653
movsd -0x28(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x39cb(%rip), %xmm0     # 0x5008
ucomisd -0x28(%rbp), %xmm0
jbe 0x1651
movsd 0x39bc(%rip), %xmm0     # 0x5008
movsd %xmm0, -0x28(%rbp)
jmp 0x1653
movq -0x50(%rbp), %rdi
movsd 0x6ae9(%rip), %xmm0     # 0x8148
cvtsi2sdl -0x5c(%rbp), %xmm1
mulsd %xmm1, %xmm0
divsd -0x28(%rbp), %xmm0
cvttsd2si %xmm0, %edx
leaq 0x3ad6(%rip), %rsi      # 0x514e
movb $0x0, %al
callq 0x1110
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x15b3
jmp 0x168f
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1592
movl -0x18(%rbp), %eax
movq -0x58(%rbp), %rcx
movl 0xc(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x16d0
movq 0x6943(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
leaq 0x3aab(%rip), %rsi      # 0x5174
movb $0x0, %al
callq 0x1110
movq -0x48(%rbp), %rdi
callq 0x1070
movq -0x50(%rbp), %rdi
callq 0x1070
xorl %eax, %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)