// File: /workspace/github_c_makefile_star2_O3/pipde[P]deos-songlib/utils/mixer/fastmixer.c
// Function: main
int
main(int argc,char **argv)
    {
    int argIndex;
    int i,j,k;
    int maxSize = 0,clips = 0;
    int inRRACount;
    int maxChannels,maxSamples,maxSkip;
    RRA *r,*rraheaders[MAX_RRAS];
    FILE *out,*rrafiles[MAX_RRAS];

    // should have at least one inputs 

    argIndex = processOptions(argc,argv);

    inRRACount = argc - argIndex;

    if (inRRACount < 1)
        {
        puts("fastmixer in.rra [more rra files ...]");
        exit(-1);
        }

    out = stdout;

    /* read in rras, keeping track of the highest sampleCount */

    maxSkip = maxChannels = maxSamples = 0;

    for (i = 0; i < inRRACount; ++i)
        {
        if (i >= MAX_RRAS)
            {
            printf(" skipping (too many input files)\n");
            continue;
            }

        if (strcmp(argv[argIndex + i],"-") == 0)
            rrafiles[i] = stdin;
        else
            rrafiles[i] = OpenFile(argv[argIndex + i],"r");

        rraheaders[i] = newRRAHeader();
        readRRAHeader(rrafiles[i],rraheaders[i],0);

        if (maxSamples < rraheaders[i]->samples)
            maxSamples = rraheaders[i]->samples;
        if (maxChannels < rraheaders[i]->channels)
            maxChannels = rraheaders[i]->channels;
        if (maxSkip < rraheaders[i]->skip)
            maxSkip = rraheaders[i]->skip;
        if (maxSize < pow(2,rraheaders[i]->bitsPerSample - 1))
            maxSize = pow(2,rraheaders[i]->bitsPerSample - 1);
            maxSkip = rraheaders[i]->skip;
        }
    if (skip != 0) maxSkip = skip;

    r = newRRAHeader();
    r->sampleRate = rraheaders[0]->sampleRate;
    r->bitsPerSample = rraheaders[0]->bitsPerSample;
    r->channels = maxChannels;
    r->samples = maxSamples - maxSkip;

    writeRRAHeader(out,r,"createdBy: fmix",0);

    for (i = 0; i < maxSamples; ++i)
        {
        for (j = 0; j < maxChannels; ++j)
            {
            int total = 0;
            for (k = 0; k < inRRACount; ++k)
                {
                if (i < rraheaders[k]->samples && j < rraheaders[k]->channels)
                    {
                    //total += readRRAAmplitude 
                                        //( rrafiles[k], rraheaders[k]->bitsPerSample, 0);
                    total += readRRAAmplitude(rrafiles[k],out,rraheaders[k]->bitsPerSample,outputComment);
                    }
                }
            if (i >= maxSkip)
                {
                int x = total * attenuation;
                fprintf(out,"%d\n",x);
                if (x > maxSize)
                    {
                    ++clips;
                    }
                }
            }
        }

    for (i = 0; i < inRRACount; ++i)
        fclose(rrafiles[i]);

    fprintf(stderr,"%s clip: %d\n",argv[0],clips);
    return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, -0x40(%rbp)
movl %edi, %r15d
movl $0x1, %ebx
cmpl $0x2, %edi
jl 0x2840
movl $0x1, %ebx
leaq 0x68e0(%rip), %r14      # 0x9071
movslq %ebx, %rcx
movq -0x40(%rbp), %rax
movq (%rax,%rcx,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x2840
movzbl 0x1(%rsi), %eax
testl %eax, %eax
je 0x2840
movb 0x2(%rsi), %r12b
testb %r12b, %r12b
je 0x27c0
leaq 0x2(%rsi), %rdi
jmp 0x27c9
movq -0x40(%rbp), %rdx
movq 0x8(%rdx,%rcx,8), %rdi
cmpl $0x72, %eax
jg 0x27e7
cmpl $0x53, %eax
je 0x27f8
cmpl $0x61, %eax
jne 0x281a
callq 0x20a0
movsd %xmm0, 0xa9cb(%rip)     # 0xd1b0
jmp 0x280c
cmpl $0x73, %eax
jne 0x2811
callq 0x20a0
callq 0x5ae8
jmp 0x2802
callq 0x20a0
callq 0x36df
cvttsd2si %xmm0, %eax
movl %eax, 0xac28(%rip)      # 0xd434
movb $0x1, %r13b
jmp 0x2827
cmpl $0x76, %eax
je 0x2abd
xorl %r13d, %r13d
movq %r14, %rdi
xorl %eax, %eax
callq 0x6c58
testb %r12b, %r12b
sete %al
andb %r13b, %al
movzbl %al, %eax
addl %eax, %ebx
incl %ebx
cmpl %r15d, %ebx
jl 0x2791
subl %ebx, %r15d
jle 0x2ae0
movq 0xa780(%rip), %rax      # 0xcfd0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movslq %ebx, %rax
movl %r15d, %r13d
movq -0x40(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, -0x48(%rbp)
xorl %r15d, %r15d
xorl %ebx, %ebx
xorl %r14d, %r14d
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
cmpq $0x14, %r15
jb 0x2896
leaq 0x67ff(%rip), %rdi      # 0x908b
callq 0x2090
jmp 0x2944
movq -0x48(%rbp), %rax
movq (%rax,%r15,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x28ad
cmpb $0x0, 0x1(%rdi)
je 0x2952
leaq 0x6764(%rip), %rsi      # 0x9018
callq 0x6cf2
movq %rax, %rbx
movq %rbx, -0x100(%rbp,%r15,8)
callq 0x6f63
movq %rax, %r12
movq %rax, -0x1a0(%rbp,%r15,8)
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x7389
movl 0xc(%r12), %eax
cmpl %eax, %r14d
cmovlel %eax, %r14d
movl (%r12), %eax
movl -0x2c(%rbp), %ecx
cmpl %eax, %ecx
cmovlel %eax, %ecx
movl %ecx, -0x2c(%rbp)
movl 0x8(%r12), %edi
xorps %xmm0, %xmm0
cvtsi2sdl -0x30(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
decl %edi
movsd 0x66f0(%rip), %xmm0     # 0x9008
callq 0x2060
ucomisd -0x38(%rbp), %xmm0
jbe 0x293f
movl 0x8(%r12), %edi
decl %edi
movsd 0x66d5(%rip), %xmm0     # 0x9008
callq 0x2060
cvttsd2si %xmm0, %eax
movl %eax, -0x30(%rbp)
movl 0x10(%r12), %ebx
incq %r15
cmpq %r15, %r13
jne 0x287f
jmp 0x2961
movq 0xa67f(%rip), %rax      # 0xcfd8
movq (%rax), %rbx
jmp 0x28bc
movl 0xaacd(%rip), %eax      # 0xd434
testl %eax, %eax
cmovnel %eax, %ebx
callq 0x6f63
movq -0x1a0(%rbp), %rcx
movl 0x4(%rcx), %edx
movl %edx, 0x4(%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
movl %r14d, %ecx
movl %ebx, -0x48(%rbp)
subl %ebx, %ecx
movl %ecx, 0xc(%rax)
leaq 0x66aa(%rip), %rdx      # 0x9045
movq $0x0, -0x38(%rbp)
movq -0x50(%rbp), %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0x7e24
testl %r14d, %r14d
jle 0x2a6f
xorl %r15d, %r15d
movq $0x0, -0x38(%rbp)
movl %r14d, -0x54(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x2a5f
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %ebx, %ebx
movq -0x1a0(%rbp,%r12,8), %rax
cmpl 0xc(%rax), %r15d
jge 0x2a0b
cmpl (%rax), %r14d
jge 0x2a0b
movq -0x100(%rbp,%r12,8), %rdi
movl 0x8(%rax), %edx
movq -0x50(%rbp), %rsi
leaq 0x56eb(%rip), %rcx      # 0x80ef
callq 0x788c
addl %eax, %ebx
incq %r12
cmpq %r12, %r13
jne 0x29db
cmpl -0x48(%rbp), %r15d
jl 0x2a52
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd 0xa788(%rip), %xmm0     # 0xd1b0
cvttsd2si %xmm0, %ebx
movq -0x50(%rbp), %rdi
leaq 0x6bf6(%rip), %rsi      # 0x962d
movl %ebx, %edx
xorl %eax, %eax
callq 0x21d0
xorl %eax, %eax
cmpl %ebx, -0x30(%rbp)
setl %al
movq -0x38(%rbp), %rcx
addl %eax, %ecx
movq %rcx, -0x38(%rbp)
incl %r14d
cmpl -0x2c(%rbp), %r14d
jne 0x29d6
incl %r15d
movl -0x54(%rbp), %r14d
cmpl %r14d, %r15d
jne 0x29c9
xorl %ebx, %ebx
movq -0x100(%rbp,%rbx,8), %rdi
callq 0x20c0
incq %rbx
cmpq %rbx, %r13
jne 0x2a71
movq 0xa56b(%rip), %rax      # 0xcff8
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rdx
leaq 0x65b7(%rip), %rsi      # 0x9055
movq -0x38(%rbp), %rcx
xorl %eax, %eax
callq 0x21d0
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa6dc(%rip), %rsi      # 0xd1a0
movq 0xa6dd(%rip), %rdx      # 0xd1a8
leaq 0x6590(%rip), %rdi      # 0x9062
xorl %eax, %eax
callq 0x20f0
xorl %edi, %edi
callq 0x22c0
leaq 0x6538(%rip), %rdi      # 0x901f
callq 0x2090
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22c0
nop