// File: /workspace/github_c_makefile_star2_O1/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 0x16a3
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x16a3
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x15e6
leaq 0x2(%rsi), %rdi
jmp 0x15eb
movq 0x8(%r14,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x67, %eax
jg 0x1616
cmpl $0x41, %eax
je 0x1641
cmpl $0x52, %eax
je 0x1650
cmpl $0x61, %eax
jne 0x1690
callq 0x1080
movsd %xmm0, 0x5b5c(%rip)     # 0x7170
jmp 0x165d
cmpl $0x73, %eax
jg 0x162f
cmpl $0x72, %eax
jne 0x167d
callq 0x1080
movsd %xmm0, 0x5b2b(%rip)     # 0x7158
jmp 0x165d
cmpl $0x74, %eax
jne 0x1687
callq 0x1200
movl %eax, 0x5b11(%rip)      # 0x7150
jmp 0x165d
callq 0x1080
movsd %xmm0, 0x5b12(%rip)     # 0x7160
jmp 0x165d
callq 0x1080
movsd %xmm0, 0x5b0b(%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 0x15c7
jmp 0x16a3
cmpl $0x68, %eax
jne 0x1690
jmp 0x1a4d
cmpl $0x76, %eax
je 0x1a2c
xorl %r15d, %r15d
leaq 0x2a3d(%rip), %rdi      # 0x40d7
xorl %eax, %eax
callq 0x1b90
jmp 0x1660
subl %r12d, %ebx
jne 0x16b4
movq 0x5929(%rip), %rax      # 0x6fd8
movq (%rax), %rbx
jmp 0x16d8
cmpl $0x2, %ebx
je 0x16e4
cmpl $0x1, %ebx
jne 0x1b77
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
leaq 0x3195(%rip), %rsi      # 0x4865
callq 0x1c2a
movq %rax, %rbx
movq 0x58f1(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x170e
movslq %r12d, %rbx
movq (%r14,%rbx,8), %rdi
leaq 0x3173(%rip), %rsi      # 0x4865
callq 0x1c2a
movq 0x8(%r14,%rbx,8), %rdi
movq %rax, %rbx
leaq 0x2927(%rip), %rsi      # 0x402d
callq 0x1c2a
movq %rax, %r14
callq 0x1ea7
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x22b4
movl 0x8(%r15), %edi
decl %edi
movsd 0x28d7(%rip), %xmm0     # 0x4008
callq 0x1050
addsd 0x28d2(%rip), %xmm0     # 0x4010
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
cvtsi2sdl 0x59fe(%rip), %xmm1 # 0x7150
movsd 0x28be(%rip), %xmm0     # 0x4018
callq 0x1090
movsd 0x28a9(%rip), %xmm3     # 0x4010
addsd 0x59e9(%rip), %xmm3     # 0x7158
movsd 0x59e9(%rip), %xmm2     # 0x7160
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
movsd %xmm3, -0x30(%rbp)
movsd %xmm3, -0x58(%rbp)
jbe 0x17a6
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 0x59b5(%rip), %xmm2     # 0x7168
ucomisd %xmm1, %xmm2
movq %rbx, -0x60(%rbp)
movq %r14, -0x38(%rbp)
jbe 0x17dc
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 0x1cbd
movq %rax, %rbx
testq %r14, %r14
jle 0x1825
xorl %r13d, %r13d
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x1cbd
movq %rax, (%rbx,%r13,8)
movl $0x7d0, %edx            # imm = 0x7D0
movq %rax, %rdi
xorl %esi, %esi
callq 0x10e0
incq %r13
cmpq %r13, %r14
jne 0x1800
movq %rbx, 0x5974(%rip)      # 0x71a0
movq 0x57c5(%rip), %rbx      # 0x6ff8
movq (%rbx), %rdi
leaq 0x27f2(%rip), %rsi      # 0x402f
xorl %r14d, %r14d
movl %r12d, %edx
xorl %eax, %eax
callq 0x1150
movq (%rbx), %rdi
movsd 0x591b(%rip), %xmm0     # 0x7170
leaq 0x27e2(%rip), %rsi      # 0x403e
movb $0x1, %al
callq 0x1150
leaq 0x27e1(%rip), %rdx      # 0x404b
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
xorl %ecx, %ecx
callq 0x2d05
movq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x1170
testl %eax, %eax
jne 0x19de
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd %xmm0, -0x70(%rbp)
xorl %r14d, %r14d
movsd 0x2763(%rip), %xmm0     # 0x4008
movsd %xmm0, -0x50(%rbp)
movq -0x40(%rbp), %rcx
cmpl $0x0, (%rcx)
movq %r14, -0x68(%rbp)
jle 0x19c7
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 0x58d4(%rip), %r12      # 0x71b0
xorl %r14d, %r14d
movq -0x38(%rbp), %r15
movl 0x8(%rcx), %edx
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x16de(%rip), %rcx      # 0x2fd1
callq 0x27a0
movl %eax, %ebx
movq 0x589f(%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 0x26ef(%rip), %xmm1     # 0x4020
callq 0x1090
ucomisd -0x70(%rbp), %xmm0
jbe 0x195b
movsd -0x50(%rbp), %xmm1
addsd -0x58(%rbp), %xmm1
movsd 0x5809(%rip), %xmm0     # 0x7158
ucomisd %xmm0, %xmm1
jbe 0x197b
movapd %xmm0, %xmm1
jmp 0x197b
movsd -0x50(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
movsd 0x269b(%rip), %xmm0     # 0x4008
ucomisd %xmm1, %xmm0
jbe 0x197b
movsd 0x268d(%rip), %xmm1     # 0x4008
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd 0x57e6(%rip), %xmm0     # 0x7170
movsd %xmm1, -0x50(%rbp)
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movq -0x38(%rbp), %r15
movq %r15, %rdi
leaq 0x2695(%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 0x18e3
movq -0x68(%rbp), %r14
incl %r14d
movq %rbx, %rdi
callq 0x1170
testl %eax, %eax
je 0x18aa
movq -0x40(%rbp), %rax
movl 0xc(%rax), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r14d
jne 0x1a0f
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 0x55e2(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2640(%rip), %rsi      # 0x4060
movl %r14d, %edx
xorl %eax, %eax
callq 0x1150
jmp 0x19ed
movq 0x570d(%rip), %rsi      # 0x7140
movq 0x570e(%rip), %rdx      # 0x7148
leaq 0x2647(%rip), %rdi      # 0x4088
xorl %eax, %eax
callq 0x10c0
jmp 0x1b70
leaq 0x26d8(%rip), %rdi      # 0x412c
callq 0x1070
leaq 0x26de(%rip), %rdi      # 0x413e
callq 0x1070
leaq 0x26fb(%rip), %rdi      # 0x4167
callq 0x1070
movsd 0x56f7(%rip), %xmm0     # 0x7170
leaq 0x2617(%rip), %rbx      # 0x4097
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x2709(%rip), %rdi      # 0x419a
callq 0x1070
leaq 0x2724(%rip), %rdi      # 0x41c1
callq 0x1070
leaq 0x2746(%rip), %rdi      # 0x41ef
callq 0x1070
movl 0x569c(%rip), %esi      # 0x7150
leaq 0x25fc(%rip), %rdi      # 0x40b7
xorl %eax, %eax
callq 0x10c0
leaq 0x2764(%rip), %rdi      # 0x422d
callq 0x1070
leaq 0x277e(%rip), %rdi      # 0x4253
callq 0x1070
leaq 0x279e(%rip), %rdi      # 0x427f
callq 0x1070
movsd 0x566a(%rip), %xmm0     # 0x7158
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x27b1(%rip), %rdi      # 0x42b0
callq 0x1070
leaq 0x27c8(%rip), %rdi      # 0x42d3
callq 0x1070
leaq 0x27ef(%rip), %rdi      # 0x4306
callq 0x1070
movsd 0x563c(%rip), %xmm0     # 0x7160
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x2810(%rip), %rdi      # 0x4345
callq 0x1070
leaq 0x2828(%rip), %rdi      # 0x4369
callq 0x1070
leaq 0x284e(%rip), %rdi      # 0x439b
callq 0x1070
movsd 0x5606(%rip), %xmm0     # 0x7160
movq %rbx, %rdi
movb $0x1, %al
callq 0x10c0
leaq 0x286d(%rip), %rdi      # 0x43d8
callq 0x1070
xorl %edi, %edi
callq 0x1210
leaq 0x2573(%rip), %rdi      # 0x40f1
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1210
nopl (%rax)