// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rbx
leaq 0x5c40(%rip), %r14      # 0x8071
movslq %ebx, %rax
cmpl %ebx, %r15d
jle 0x24e0
movq -0x40(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x24e0
movzbl 0x1(%rsi), %ecx
testl %ecx, %ecx
je 0x24e0
movb 0x2(%rsi), %r12b
testb %r12b, %r12b
je 0x2469
leaq 0x2(%rsi), %rdi
jmp 0x2472
movq -0x40(%rbp), %rdx
movq 0x8(%rdx,%rax,8), %rdi
cmpl $0x53, %ecx
je 0x24a5
cmpl $0x61, %ecx
je 0x24bb
cmpl $0x73, %ecx
je 0x2499
cmpl $0x76, %ecx
je 0x2759
xorl %r13d, %r13d
movq %r14, %rdi
xorl %eax, %eax
callq 0x632c
jmp 0x24cb
callq 0x20a0
callq 0x5358
jmp 0x24af
callq 0x20a0
callq 0x3358
cvttsd2si %xmm0, %eax
movl %eax, 0x9f7b(%rip)      # 0xc434
jmp 0x24c8
callq 0x20a0
movsd %xmm0, 0x9ce8(%rip)     # 0xc1b0
movb $0x1, %r13b
testb %r12b, %r12b
sete %al
andb %r13b, %al
movzbl %al, %eax
addl %eax, %ebx
incl %ebx
jmp 0x2431
subl %ebx, %r15d
jle 0x277c
movq 0x9ae0(%rip), %rcx      # 0xbfd0
movq (%rcx), %rcx
movq %rcx, -0x50(%rbp)
movl %r15d, %r12d
movq -0x40(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, -0x48(%rbp)
xorl %r15d, %r15d
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq %r15, %r12
je 0x2601
cmpq $0x14, %r15
jb 0x253d
leaq 0x5b58(%rip), %rdi      # 0x808b
callq 0x2090
jmp 0x25ea
movq -0x48(%rbp), %rax
movq (%rax,%r15,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x2554
cmpb $0x0, 0x1(%rdi)
je 0x25f2
leaq 0x5abd(%rip), %rsi      # 0x8018
callq 0x645c
movq %rax, %rbx
movq %rbx, -0x100(%rbp,%r15,8)
callq 0x66b8
movq %rax, %r13
movq %rax, -0x1a0(%rbp,%r15,8)
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x6a1d
movl 0xc(%r13), %ebx
cmpl %ebx, %r14d
cmovgl %r14d, %ebx
movl (%r13), %r14d
movl -0x30(%rbp), %eax
cmpl %r14d, %eax
cmovgl %eax, %r14d
movl 0x8(%r13), %edi
cvtsi2sdl -0x34(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
decl %edi
movsd 0x5a4f(%rip), %xmm0     # 0x8008
callq 0x2060
ucomisd -0x30(%rbp), %xmm0
jbe 0x25df
movl 0x8(%r13), %edi
decl %edi
movsd 0x5a35(%rip), %xmm0     # 0x8008
callq 0x2060
cvttsd2si %xmm0, %eax
movl %eax, -0x34(%rbp)
movl 0x10(%r13), %r13d
movl %r14d, -0x30(%rbp)
movl %ebx, %r14d
incq %r15
jmp 0x251d
movq 0x99df(%rip), %rax      # 0xbfd8
movq (%rax), %rbx
jmp 0x2563
movl 0x9e2d(%rip), %eax      # 0xc434
testl %eax, %eax
cmovnel %eax, %r13d
callq 0x66b8
movq -0x1a0(%rbp), %rcx
movl 0x4(%rcx), %edx
movl %edx, 0x4(%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movl %r14d, %r15d
movl -0x30(%rbp), %r14d
movl %r14d, (%rax)
movl %r15d, %ecx
movl %r13d, -0x48(%rbp)
subl %r13d, %ecx
movl %ecx, 0xc(%rax)
leaq 0x5a02(%rip), %rdx      # 0x8045
xorl %ebx, %ebx
movq -0x50(%rbp), %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0x742c
testl %r14d, %r14d
cmovlel %ebx, %r14d
movl %r14d, -0x30(%rbp)
movl %r15d, %eax
testl %r15d, %r15d
cmovlel %ebx, %eax
movl $0x0, -0x38(%rbp)
xorl %r15d, %r15d
movl %eax, -0x54(%rbp)
cmpl %eax, %r15d
je 0x270a
xorl %r14d, %r14d
cmpl -0x30(%rbp), %r14d
je 0x26ff
xorl %r13d, %r13d
xorl %ebx, %ebx
cmpq %r13, %r12
je 0x26c5
movq -0x1a0(%rbp,%r13,8), %rax
cmpl 0xc(%rax), %r15d
jge 0x26c0
cmpl (%rax), %r14d
jge 0x26c0
movq -0x100(%rbp,%r13,8), %rdi
movl 0x8(%rax), %edx
movq -0x50(%rbp), %rsi
leaq 0x5000(%rip), %rcx      # 0x76b9
callq 0x6ef2
addl %eax, %ebx
incq %r13
jmp 0x268b
cmpl -0x48(%rbp), %r15d
jl 0x26fa
cvtsi2sd %ebx, %xmm0
mulsd 0x9ad9(%rip), %xmm0     # 0xc1b0
cvttsd2si %xmm0, %ebx
movq -0x50(%rbp), %rdi
leaq 0x5f27(%rip), %rsi      # 0x860d
movl %ebx, %edx
xorl %eax, %eax
callq 0x21d0
xorl %eax, %eax
cmpl %ebx, -0x34(%rbp)
setl %al
addl %eax, -0x38(%rbp)
incl %r14d
jmp 0x2680
incl %r15d
movl -0x54(%rbp), %eax
jmp 0x2674
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x2723
movq -0x100(%rbp,%rbx,8), %rdi
callq 0x20c0
incq %rbx
jmp 0x270c
movq 0x98ce(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rdx
leaq 0x591a(%rip), %rsi      # 0x8055
movl -0x38(%rbp), %ecx
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 0x9a40(%rip), %rsi      # 0xc1a0
movq 0x9a41(%rip), %rdx      # 0xc1a8
leaq 0x58f4(%rip), %rdi      # 0x8062
xorl %eax, %eax
callq 0x20f0
xorl %edi, %edi
callq 0x22b0
leaq 0x589c(%rip), %rdi      # 0x801f
callq 0x2090
pushq $-0x1
popq %rdi
callq 0x22b0