// File: /workspace/github_c_makefile_star2_O1/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, %r13
movl $0x1, %ebx
cmpl $0x2, %edi
jl 0x2858
movl $0x1, %ebx
movl %edi, %r14d
movslq %ebx, %rcx
movq (%r13,%rcx,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x2858
movzbl 0x1(%rsi), %eax
testl %eax, %eax
je 0x2858
movb 0x2(%rsi), %r15b
testb %r15b, %r15b
je 0x27d5
leaq 0x2(%rsi), %rdi
jmp 0x27da
movq 0x8(%r13,%rcx,8), %rdi
cmpl $0x72, %eax
jg 0x27f8
cmpl $0x53, %eax
je 0x2809
cmpl $0x61, %eax
jne 0x282b
callq 0x20a0
movsd %xmm0, 0xa9ba(%rip)     # 0xd1b0
jmp 0x281d
cmpl $0x73, %eax
jne 0x2822
callq 0x20a0
callq 0x5a02
jmp 0x2813
callq 0x20a0
callq 0x3714
cvttsd2si %xmm0, %eax
movl %eax, 0xac17(%rip)      # 0xd434
movb $0x1, %r12b
jmp 0x283c
cmpl $0x76, %eax
je 0x2ae2
xorl %r12d, %r12d
leaq 0x683e(%rip), %rdi      # 0x9073
xorl %eax, %eax
callq 0x6b24
testb %r15b, %r15b
sete %al
andb %r12b, %al
movzbl %al, %eax
addl %eax, %ebx
incl %ebx
movl %r14d, %edi
cmpl %r14d, %ebx
jl 0x27a9
movq %r13, -0x58(%rbp)
subl %ebx, %edi
jle 0x2b05
movq 0xa765(%rip), %rax      # 0xcfd0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movslq %ebx, %rax
movl %edi, -0x4c(%rbp)
movl %edi, %r13d
movq -0x58(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, -0x40(%rbp)
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %r15d, %r15d
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
cmpq $0x14, %r12
jb 0x28b4
leaq 0x67e3(%rip), %rdi      # 0x908d
callq 0x2090
jmp 0x296b
movq -0x40(%rbp), %rax
movq (%rax,%r12,8), %rbx
movq %rbx, %rdi
leaq 0x677f(%rip), %rsi      # 0x9045
callq 0x21b0
testl %eax, %eax
je 0x28e3
movq %rbx, %rdi
leaq 0x673f(%rip), %rsi      # 0x9018
callq 0x6bbe
movq %rax, %r14
jmp 0x28ed
movq 0xa6ee(%rip), %rax      # 0xcfd8
movq (%rax), %r14
movq %r14, -0x100(%rbp,%r12,8)
callq 0x6e3b
movq %rax, %rbx
movq %rax, -0x1a0(%rbp,%r12,8)
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x7248
movl 0xc(%rbx), %eax
cmpl %eax, %r15d
cmovlel %eax, %r15d
movl (%rbx), %eax
movl -0x2c(%rbp), %ecx
cmpl %eax, %ecx
cmovlel %eax, %ecx
movl %ecx, -0x2c(%rbp)
movl 0x8(%rbx), %edi
xorps %xmm0, %xmm0
cvtsi2sdl -0x30(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
decl %edi
movsd 0x66c5(%rip), %xmm0     # 0x9008
callq 0x2060
ucomisd -0x38(%rbp), %xmm0
jbe 0x2968
movl 0x8(%rbx), %edi
decl %edi
movsd 0x66ac(%rip), %xmm0     # 0x9008
callq 0x2060
cvttsd2si %xmm0, %eax
movl %eax, -0x30(%rbp)
movl 0x10(%rbx), %ebx
incq %r12
cmpq %r12, %r13
jne 0x289d
movl 0xaab7(%rip), %eax      # 0xd434
testl %eax, %eax
cmovnel %eax, %ebx
callq 0x6e3b
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 %r15d, %ecx
movl %ebx, -0x40(%rbp)
subl %ebx, %ecx
movl %ecx, 0xc(%rax)
leaq 0x6696(%rip), %rdx      # 0x9047
movq $0x0, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0x7c99
testl %r15d, %r15d
jle 0x2a85
xorl %r12d, %r12d
movq $0x0, -0x38(%rbp)
movl %r15d, -0x50(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x2a75
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %ebx, %ebx
movq -0x1a0(%rbp,%r14,8), %rax
cmpl 0xc(%rax), %r12d
jge 0x2a21
cmpl (%rax), %r15d
jge 0x2a21
movq -0x100(%rbp,%r14,8), %rdi
movl 0x8(%rax), %edx
movq -0x48(%rbp), %rsi
leaq 0x554b(%rip), %rcx      # 0x7f65
callq 0x7734
addl %eax, %ebx
incq %r14
cmpq %r14, %r13
jne 0x29f1
cmpl -0x40(%rbp), %r12d
jl 0x2a68
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd 0xa772(%rip), %xmm0     # 0xd1b0
cvttsd2si %xmm0, %ebx
movq -0x48(%rbp), %rdi
leaq 0x6ba0(%rip), %rsi      # 0x95ed
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 %r15d
cmpl -0x2c(%rbp), %r15d
jne 0x29ec
incl %r12d
movl -0x50(%rbp), %r15d
cmpl %r15d, %r12d
jne 0x29df
movl -0x4c(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ebx
cmovgel %eax, %ebx
xorl %r14d, %r14d
movq -0x100(%rbp,%r14,8), %rdi
callq 0x20c0
incq %r14
cmpq %r14, %rbx
jne 0x2a96
movq 0xa546(%rip), %rax      # 0xcff8
movq (%rax), %rdi
movq -0x58(%rbp), %rax
movq (%rax), %rdx
leaq 0x6594(%rip), %rsi      # 0x9057
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 0xa6b7(%rip), %rsi      # 0xd1a0
movq 0xa6b8(%rip), %rdx      # 0xd1a8
leaq 0x656d(%rip), %rdi      # 0x9064
xorl %eax, %eax
callq 0x20f0
xorl %edi, %edi
callq 0x22c0
leaq 0x6513(%rip), %rdi      # 0x901f
callq 0x2090
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22c0
nop