// File: /workspace/github_c_makefile_star2_O0/pipde[P]deos-songlib/utils/crossover/crossover.c
// Function: process
static void
process(RRA *h)
    {
    int i, j; 
    int crossoverComplete = 1; 
    int buffer[h->channels], start, temp;
    double factor;
    double delta;

    /*
     * Need to pass the channel nos to
     * crossover as commandline
     * arguments
     *
     */

    writeRRAHeader(out,h,"modifiedBy: crossover",0);

    start = 0;
    factor = 1;
    temp = 0;
    for (i = 0; !feof(in); ++i)
        {
        for (j = 0; j < h->channels; ++j)
            buffer[j] = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);
        
        if(crossoverFlag > temp && crossoverComplete) 
            {
            crossoverComplete = 0;
            temp = crossoverFlag;
            }

        if(crossoverFlag && !crossoverComplete)
            {
            start++; /* counting
            crossoverSamples */

            //factor = 0.99*factor;
            //factor = ((crossoverSamples - 1) / crossoverSamples) *factor;
            delta = 1.0 / crossoverSamples; 
            factor = factor - delta;
            if(factor < 0)  factor = 0;

            if(start < crossoverSamples)
                {
                if (crossoverFlag % 2) /* Odd */
                    {
                    for(j = 0; j < h->channels; ++j)
                        {
                        if(j == channel1)
                            fprintf(out,"%d\n",(int)(buffer[channel1]*factor + buffer[channel2]*(1-factor)));
                        else if(j == channel2)      
                            fprintf(out,"%d\n",(int)(buffer[channel1]*(1-factor) + buffer[channel2]*factor));
                        else                
                            fprintf(out,"%d\n",(int)(buffer[j]));
                        }
                    }
                else /* Even */
                    {
                    for(j = 0; j < h->channels; ++j)
                        {
                        if(j == channel1)
                            fprintf(out,"%d\n",(int)(buffer[channel2]*factor + buffer[channel1]*(1-factor)));
                        else if(j == channel2)      
                            fprintf(out,"%d\n",(int)(buffer[channel2]*(1-factor) + buffer[channel1]*factor));
                        else                
                            fprintf(out,"%d\n",(int)(buffer[j]));
                        }
                    }
                }
            }
        
        if(start > crossoverSamples) 
            {
            crossoverComplete = 1;
            factor = 1;
            start = 0;
            }
        
        if(crossoverComplete )    
            {
            if(crossoverFlag % 2)
                {
                /* completed try swapping */

                /*
                 * swap the read amplitudes
                 * outputs to different channels.
                 *
                 */
                for(j = 0; j < h->channels; ++j)
                    {
                    if(j == channel1)
                        fprintf(out,"%d\n",(int)(buffer[channel2]));
                    else if(j == channel2)          
                        fprintf(out,"%d\n",(int)(buffer[channel1]));
                    else                    
                        fprintf(out,"%d\n",(int)(buffer[j]));
                    }
                //for (j = h->channels-1 ; j >= 0 ; --j)
                //    fprintf(out,"%d\n",(int)buffer[j]);

                }
            else
                {
                for (j = 0; j < h->channels; ++j)
                    fprintf(out,"%d\n",(int)buffer[j]);

                }
            }               
        }
            
    if (i != h->samples + 1)
        fprintf(stderr,"WARNING: %d samples found, %d expected\n",i,h->samples);
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl $0x1, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movq %rsp, %rcx
movq %rcx, -0x20(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
movq %rax, -0x28(%rbp)
movq 0x6b04(%rip), %rdi      # 0x8158
movq -0x8(%rbp), %rsi
leaq 0x39f3(%rip), %rdx      # 0x5052
xorl %eax, %eax
movl %eax, %ecx
callq 0x3600
movl $0x0, -0x2c(%rbp)
movsd 0x3991(%rip), %xmm0     # 0x5008
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0xc(%rbp)
movq 0x6abf(%rip), %rdi      # 0x8150
callq 0x1130
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x16a7
jmp 0x1ae8
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x16f2
movq 0x6a90(%rip), %rdi      # 0x8150
movq 0x6a91(%rip), %rsi      # 0x8158
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x236b(%rip), %rcx      # 0x3a40
callq 0x2d90
movl %eax, %edx
movq -0x48(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x16ae
movl 0x6a68(%rip), %eax      # 0x8160
cmpl -0x30(%rbp), %eax
jle 0x1713
cmpl $0x0, -0x14(%rbp)
je 0x1713
movl $0x0, -0x14(%rbp)
movl 0x6a50(%rip), %eax      # 0x8160
movl %eax, -0x30(%rbp)
cmpl $0x0, 0x6a46(%rip)      # 0x8160
je 0x19a6
cmpl $0x0, -0x14(%rbp)
jne 0x19a6
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cvtsi2sdl 0x69ed(%rip), %xmm1 # 0x8128
movsd 0x38c5(%rip), %xmm0     # 0x5008
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x38(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x176d
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x2c(%rbp), %eax
cmpl 0x69b2(%rip), %eax      # 0x8128
jge 0x19a4
movl 0x69de(%rip), %eax      # 0x8160
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x189c
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1897
movl -0x10(%rbp), %eax
cmpl 0x69b2(%rip), %eax      # 0x8164
jne 0x1809
movq -0x48(%rbp), %rax
movq 0x6999(%rip), %rdi      # 0x8158
movslq 0x699e(%rip), %rcx      # 0x8164
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd -0x38(%rbp), %xmm2
movslq 0x6955(%rip), %rcx      # 0x812c
cvtsi2sdl (%rax,%rcx,4), %xmm1
movsd 0x3824(%rip), %xmm3     # 0x5008
subsd -0x38(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
leaq 0x39d5(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
jmp 0x1887
movl -0x10(%rbp), %eax
cmpl 0x691a(%rip), %eax      # 0x812c
jne 0x1865
movq -0x48(%rbp), %rax
movq 0x6939(%rip), %rdi      # 0x8158
movslq 0x693e(%rip), %rcx      # 0x8164
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd 0x37d5(%rip), %xmm2     # 0x5008
subsd -0x38(%rbp), %xmm2
movslq 0x68ed(%rip), %rcx      # 0x812c
cvtsi2sdl (%rax,%rcx,4), %xmm1
mulsd -0x38(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
leaq 0x3979(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
jmp 0x1885
movq -0x48(%rbp), %rax
movq 0x68e8(%rip), %rdi      # 0x8158
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x3957(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
jmp 0x1887
jmp 0x1889
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x179a
jmp 0x19a2
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x19a0
movl -0x10(%rbp), %eax
cmpl 0x68a9(%rip), %eax      # 0x8164
jne 0x1912
movq -0x48(%rbp), %rax
movq 0x6890(%rip), %rdi      # 0x8158
movslq 0x685d(%rip), %rcx      # 0x812c
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd -0x38(%rbp), %xmm2
movslq 0x6884(%rip), %rcx      # 0x8164
cvtsi2sdl (%rax,%rcx,4), %xmm1
movsd 0x371b(%rip), %xmm3     # 0x5008
subsd -0x38(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
leaq 0x38cc(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
jmp 0x1990
movl -0x10(%rbp), %eax
cmpl 0x6811(%rip), %eax      # 0x812c
jne 0x196e
movq -0x48(%rbp), %rax
movq 0x6830(%rip), %rdi      # 0x8158
movslq 0x67fd(%rip), %rcx      # 0x812c
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd 0x36cc(%rip), %xmm2     # 0x5008
subsd -0x38(%rbp), %xmm2
movslq 0x681c(%rip), %rcx      # 0x8164
cvtsi2sdl (%rax,%rcx,4), %xmm1
mulsd -0x38(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
leaq 0x3870(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
jmp 0x198e
movq -0x48(%rbp), %rax
movq 0x67df(%rip), %rdi      # 0x8158
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x384e(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
jmp 0x1990
jmp 0x1992
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x18a3
jmp 0x19a2
jmp 0x19a4
jmp 0x19a6
movl -0x2c(%rbp), %eax
cmpl 0x6779(%rip), %eax      # 0x8128
jle 0x19cc
movl $0x1, -0x14(%rbp)
movsd 0x3648(%rip), %xmm0     # 0x5008
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x1ad8
movl 0x6784(%rip), %eax      # 0x8160
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x1a97
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1a95
movl -0x10(%rbp), %eax
cmpl 0x6758(%rip), %eax      # 0x8164
jne 0x1a33
movq -0x48(%rbp), %rax
movq 0x673f(%rip), %rdi      # 0x8158
movslq 0x670c(%rip), %rcx      # 0x812c
movl (%rax,%rcx,4), %edx
leaq 0x37ab(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
jmp 0x1a85
movl -0x10(%rbp), %eax
cmpl 0x66f0(%rip), %eax      # 0x812c
jne 0x1a63
movq -0x48(%rbp), %rax
movq 0x670f(%rip), %rdi      # 0x8158
movslq 0x6714(%rip), %rcx      # 0x8164
movl (%rax,%rcx,4), %edx
leaq 0x377b(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
jmp 0x1a83
movq -0x48(%rbp), %rax
movq 0x66ea(%rip), %rdi      # 0x8158
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x3759(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
jmp 0x1a85
jmp 0x1a87
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x19f4
jmp 0x1ad6
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1ad4
movq -0x48(%rbp), %rax
movq 0x66a4(%rip), %rdi      # 0x8158
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x3713(%rip), %rsi      # 0x51d5
movb $0x0, %al
callq 0x1110
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1a9e
jmp 0x1ad6
jmp 0x1ad8
jmp 0x1ada
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x168a
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0xc(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x1b1b
movq 0x64f8(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0xc(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0xc(%rax), %ecx
leaq 0x3554(%rip), %rsi      # 0x5068
movb $0x0, %al
callq 0x1110
movq -0x20(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)