// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %r12
movslq %r12d, %r15
cmpl %r12d, %ebx
jle 0x1446
movq (%r14,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x1446
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x139e
leaq 0x2(%rsi), %rdi
jmp 0x13a3
movq 0x8(%r14,%r15,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x41, %eax
je 0x1401
cmpl $0x52, %eax
je 0x141f
cmpl $0x61, %eax
je 0x13f2
cmpl $0x72, %eax
je 0x1410
cmpl $0x74, %eax
je 0x13e5
cmpl $0x68, %eax
je 0x1786
cmpl $0x76, %eax
je 0x18ab
xorl %r15d, %r15d
leaq 0x2cfb(%rip), %rdi      # 0x40d7
xorl %eax, %eax
callq 0x18e4
jmp 0x142f
callq 0x1200
movl %eax, 0x5d60(%rip)      # 0x7150
jmp 0x142c
callq 0x1080
movsd %xmm0, 0x5d71(%rip)     # 0x7170
jmp 0x142c
callq 0x1080
movsd %xmm0, 0x5d52(%rip)     # 0x7160
jmp 0x142c
callq 0x1080
movsd %xmm0, 0x5d3b(%rip)     # 0x7158
jmp 0x142c
callq 0x1080
movsd %xmm0, 0x5d3c(%rip)     # 0x7168
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
jmp 0x1376
subl %r12d, %ebx
jne 0x1457
movq 0x5b86(%rip), %rax      # 0x6fd8
movq (%rax), %rbx
jmp 0x1478
cmpl $0x2, %ebx
je 0x1484
cmpl $0x1, %ebx
jne 0x18ce
movq (%r14,%r15,8), %rdi
leaq 0x33f2(%rip), %rsi      # 0x4862
callq 0x1a14
movq %rax, %rbx
movq 0x5b51(%rip), %rax      # 0x6fd0
movq (%rax), %rax
jmp 0x14a8
movq (%r14,%r15,8), %rdi
leaq 0x33d3(%rip), %rsi      # 0x4862
callq 0x1a14
movq %rax, %rbx
movq 0x8(%r14,%r15,8), %rdi
leaq 0x2b8a(%rip), %rsi      # 0x402d
callq 0x1a14
movq %rax, -0x30(%rbp)
callq 0x1c70
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x1fd5
movl 0x8(%r15), %edi
decl %edi
movsd 0x2b39(%rip), %xmm0     # 0x4008
callq 0x1050
addsd 0x2b34(%rip), %xmm0     # 0x4010
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
cvtsi2sdl 0x5c60(%rip), %xmm1 # 0x7150
movsd 0x2b20(%rip), %xmm0     # 0x4018
callq 0x1090
movsd 0x2b0b(%rip), %xmm3     # 0x4010
addsd 0x5c4b(%rip), %xmm3     # 0x7158
movsd 0x5c4b(%rip), %xmm2     # 0x7160
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
movsd %xmm3, -0x38(%rbp)
movsd %xmm3, -0x58(%rbp)
jbe 0x1541
cvtsi2sdl 0x4(%r15), %xmm3
mulsd %xmm3, %xmm2
movsd -0x38(%rbp), %xmm3
divsd %xmm2, %xmm3
movsd %xmm3, -0x58(%rbp)
mulsd -0x50(%rbp), %xmm0
movsd 0x5c1a(%rip), %xmm2     # 0x7168
ucomisd %xmm1, %xmm2
movq %rbx, -0x60(%rbp)
jbe 0x1570
cvtsi2sdl 0x4(%r15), %xmm1
mulsd %xmm1, %xmm2
movsd -0x38(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0x38(%rbp)
cvttsd2si %xmm0, %ebx
movl (%r15), %r14d
leal (,%r14,8), %edi
callq 0x1a99
movq %rax, %r12
xorl %r13d, %r13d
testl %r14d, %r14d
cmovlel %r13d, %r14d
cmpq %r14, %r13
je 0x15bd
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x1a99
movq %rax, (%r12,%r13,8)
xorl %ecx, %ecx
cmpq $0x1f4, %rcx            # imm = 0x1F4
je 0x15b8
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x15a6
incq %r13
jmp 0x1591
movq %r12, 0x5bdc(%rip)      # 0x71a0
movq 0x5a2d(%rip), %r14      # 0x6ff8
movq (%r14), %rdi
leaq 0x2a5a(%rip), %rsi      # 0x402f
movl %ebx, %edx
xorl %eax, %eax
callq 0x1150
movq (%r14), %rdi
movsd 0x5b87(%rip), %xmm0     # 0x7170
leaq 0x2a4e(%rip), %rsi      # 0x403e
movb $0x1, %al
callq 0x1150
leaq 0x2a4d(%rip), %rdx      # 0x404b
movq -0x30(%rbp), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x29e4
cvtsi2sd %ebx, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x29eb(%rip), %xmm0     # 0x4008
movsd %xmm0, -0x50(%rbp)
xorl %ebx, %ebx
movq -0x60(%rbp), %r13
movq %r13, %rdi
callq 0x1170
testl %eax, %eax
jne 0x173d
movl %ebx, -0x3c(%rbp)
movl %ebx, %eax
xorl %edx, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
divl %ecx
movl %edx, %ebx
leaq 0x5b61(%rip), %r12      # 0x71b0
xorl %r14d, %r14d
movslq (%r15), %rax
cmpq %rax, %r14
jge 0x1733
movl 0x8(%r15), %edx
movq %r13, %rdi
movq -0x30(%rbp), %rsi
leaq 0x1601(%rip), %rcx      # 0x2c71
callq 0x24aa
movl %eax, %r13d
movq 0x5b21(%rip), %rax      # 0x71a0
movq (%rax,%r14,8), %rax
movl (%rax,%rbx,4), %ecx
movl %r13d, %edx
subl %ecx, %edx
addl %r13d, %ecx
imull %edx, %ecx
cvtsi2sd %ecx, %xmm0
addsd (%r12), %xmm0
movsd %xmm0, (%r12)
movl %r13d, (%rax,%rbx,4)
movsd 0x2973(%rip), %xmm1     # 0x4020
callq 0x1090
ucomisd -0x68(%rbp), %xmm0
jbe 0x16d7
movsd -0x50(%rbp), %xmm1
addsd -0x58(%rbp), %xmm1
movsd 0x5a8d(%rip), %xmm0     # 0x7158
ucomisd %xmm0, %xmm1
jbe 0x16f7
movapd %xmm0, %xmm1
jmp 0x16f7
movsd -0x50(%rbp), %xmm1
subsd -0x38(%rbp), %xmm1
movsd 0x291f(%rip), %xmm0     # 0x4008
ucomisd %xmm1, %xmm0
jbe 0x16f7
movsd 0x2911(%rip), %xmm1     # 0x4008
cvtsi2sd %r13d, %xmm0
mulsd 0x5a6c(%rip), %xmm0     # 0x7170
movsd %xmm1, -0x50(%rbp)
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movq -0x30(%rbp), %rdi
leaq 0x291e(%rip), %rsi      # 0x403a
xorl %eax, %eax
callq 0x1150
incq %r14
addq $0x8, %r12
movq -0x60(%rbp), %r13
jmp 0x1652
movl -0x3c(%rbp), %ebx
incl %ebx
jmp 0x1628
movl 0xc(%r15), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %ebx
jne 0x176a
movq %r13, %rdi
callq 0x10a0
movq -0x30(%rbp), %rdi
callq 0x10a0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5887(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x28e5(%rip), %rsi      # 0x4060
movl %ebx, %edx
xorl %eax, %eax
callq 0x1150
jmp 0x1748
leaq 0x299f(%rip), %rdi      # 0x412c
callq 0x1070
leaq 0x29a5(%rip), %rdi      # 0x413e
callq 0x1070
leaq 0x29c2(%rip), %rdi      # 0x4167
callq 0x1070
movsd 0x59be(%rip), %xmm0     # 0x7170
leaq 0x28de(%rip), %rbx      # 0x4097
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x29d0(%rip), %rdi      # 0x419a
callq 0x1070
leaq 0x29eb(%rip), %rdi      # 0x41c1
callq 0x1070
leaq 0x2a0d(%rip), %rdi      # 0x41ef
callq 0x1070
movl 0x5963(%rip), %esi      # 0x7150
leaq 0x28c3(%rip), %rdi      # 0x40b7
xorl %eax, %eax
callq 0x10c0
leaq 0x2a2b(%rip), %rdi      # 0x422d
callq 0x1070
leaq 0x2a45(%rip), %rdi      # 0x4253
callq 0x1070
leaq 0x2a65(%rip), %rdi      # 0x427f
callq 0x1070
movsd 0x5931(%rip), %xmm0     # 0x7158
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x2a78(%rip), %rdi      # 0x42b0
callq 0x1070
leaq 0x2a8f(%rip), %rdi      # 0x42d3
callq 0x1070
leaq 0x2ab6(%rip), %rdi      # 0x4306
callq 0x1070
movsd 0x5903(%rip), %xmm0     # 0x7160
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x2ad7(%rip), %rdi      # 0x4345
callq 0x1070
leaq 0x2aef(%rip), %rdi      # 0x4369
callq 0x1070
leaq 0x2b15(%rip), %rdi      # 0x439b
callq 0x1070
movsd 0x58cd(%rip), %xmm0     # 0x7160
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x2b34(%rip), %rdi      # 0x43d8
callq 0x1070
jmp 0x18c7
movq 0x588e(%rip), %rsi      # 0x7140
movq 0x588f(%rip), %rdx      # 0x7148
leaq 0x27c8(%rip), %rdi      # 0x4088
xorl %eax, %eax
callq 0x10c0
xorl %edi, %edi
callq 0x1210
leaq 0x281c(%rip), %rdi      # 0x40f1
callq 0x1070
pushq $-0x1
popq %rdi
callq 0x1210
nop