// File: /workspace/github_c_makefile_star2_O3/jonof[P]jfaudiolib/src/mixst.c
// Function: MV_Mix16BitStereo16Stereo
void MV_Mix16BitStereo16Stereo( unsigned int position, unsigned int rate,
                         char *start, unsigned int length )
{
    unsigned short *source = (unsigned short *) start;
    short *dest = (short *) MV_MixDestination;
    int sample0l, sample0h, sample0;
    int sample1l, sample1h, sample1;
    
    while (length--) {
        sample0 = source[(position >> 16) << 1];
        sample1 = source[((position >> 16) << 1) + 1];
#ifdef BIGENDIAN
        sample0l = sample0 >> 8;
        sample0h = (sample0 & 255) ^ 128;
        sample1l = sample1 >> 8;
        sample1h = (sample1 & 255) ^ 128;
#else
        sample0l = sample0 & 255;
        sample0h = (sample0 >> 8) ^ 128;
        sample1l = sample1 & 255;
        sample1h = (sample1 >> 8) ^ 128;
#endif
        position += rate;
        
        sample0l = MV_LeftVolume[sample0l] >> 8;
        sample0h = MV_LeftVolume[sample0h];
        sample1l = MV_RightVolume[sample1l] >> 8;
        sample1h = MV_RightVolume[sample1h];
        sample0 = sample0l + sample0h + 128 + *dest;
        sample1 = sample1l + sample1h + 128 + *(dest + MV_RightChannelOffset/2);
        if (sample0 < -32768) sample0 = -32768;
        else if (sample0 > 32767) sample0 = 32767;
        if (sample1 < -32768) sample1 = -32768;
        else if (sample1 > 32767) sample1 = 32767;
        
        *dest = (short) sample0;
        *(dest + MV_RightChannelOffset/2) = (short) sample1;
        
        dest += MV_SampleSize / 2;
    }
    
    MV_MixPosition = position;
    MV_MixDestination = (char *) dest;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %esi, -0x4(%rsp)
leaq 0x13140(%rip), %rax     # 0x19518
movq (%rax), %r8
testl %ecx, %ecx
je 0x64fd
leaq 0x1204e(%rip), %rax     # 0x18438
movq (%rax), %r9
leaq 0x1203c(%rip), %rax     # 0x18430
movq (%rax), %r10
leaq 0x1306e(%rip), %rax     # 0x1946c
movl (%rax), %eax
movl %eax, %esi
shrl $0x1f, %esi
addl %eax, %esi
sarl %esi
movslq %esi, %r11
leaq 0x9dfd(%rip), %rax      # 0x10210
movl (%rax), %eax
movl %eax, %esi
shrl $0x1f, %esi
addl %eax, %esi
sarl %esi
movslq %esi, %rbx
addq %rbx, %rbx
movl $0xff, %r14d
movl $0x80, %r15d
movl $0xffff8001, %r12d      # imm = 0xFFFF8001
movl %edi, %eax
shrl $0xe, %eax
movl %eax, %r13d
andl $-0x4, %r13d
movzwl (%rdx,%r13), %r13d
movl %r13d, %ebp
andl %r14d, %ebp
movsbl 0x1(%r9,%rbp,2), %ebp
shrl $0x7, %r13d
andl $-0x2, %r13d
movl $0x100, %esi            # imm = 0x100
xorl %esi, %r13d
movswl (%r9,%r13), %esi
movswl (%r8), %r13d
addl %ebp, %r13d
addl %r15d, %r13d
addl %esi, %r13d
movl $0x7fff, %ebp           # imm = 0x7FFF
cmpl %ebp, %r13d
jl 0x6485
movl $0x7fff, %r13d          # imm = 0x7FFF
cmpl %r12d, %r13d
jge 0x6490
movl $0xffff8000, %r13d      # imm = 0xFFFF8000
orl $0x2, %eax
andl $-0x2, %eax
movzwl (%rdx,%rax), %eax
movl %eax, %esi
andl %r14d, %esi
movsbl 0x1(%r10,%rsi,2), %esi
shrl $0x7, %eax
andl $-0x2, %eax
movl $0x100, %r14d           # imm = 0x100
xorl %r14d, %eax
movswl (%r10,%rax), %r14d
movswl (%r8,%r11,2), %eax
addl %esi, %eax
addl %r15d, %eax
addl %r14d, %eax
cmpl %ebp, %eax
jl 0x64cf
movl $0x7fff, %eax           # imm = 0x7FFF
cmpl %r12d, %eax
jge 0x64d9
movl $0xffff8000, %eax       # imm = 0xFFFF8000
addl -0x4(%rsp), %edi
leaq (%r8,%rbx), %rbp
movw %r13w, (%r8)
movw %ax, (%r8,%r11,2)
movq %rbp, %r8
decl %ecx
movl $0xff, %r14d
jne 0x6436
jmp 0x6500
movq %r8, %rbp
leaq 0x13019(%rip), %rax     # 0x19520
movl %edi, (%rax)
leaq 0x13008(%rip), %rax     # 0x19518
movq %rbp, (%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop