// File: /workspace/github_c_makefile_star2_O2/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
movq %rdx, %r8
movl %esi, -0x4(%rsp)
leaq 0x12679(%rip), %rax     # 0x18528
movq (%rax), %r10
leaq 0x1158f(%rip), %rax     # 0x17448
movq (%rax), %r11
leaq 0x1157d(%rip), %rax     # 0x17440
movq (%rax), %rbx
leaq 0x125af(%rip), %rax     # 0x1847c
movl (%rax), %eax
movl $0x2, %esi
cltd
idivl %esi
movslq %eax, %r14
leaq 0x933f(%rip), %rax      # 0xf220
movl (%rax), %eax
cltd
idivl %esi
cltq
addq %rax, %rax
movl $0xff, %ebp
movl $0x80, %r15d
movl $0xffff8001, %r12d      # imm = 0xFFFF8001
subl $0x1, %ecx
jb 0x5fc9
movl %edi, %r9d
shrl $0xe, %r9d
movl %r9d, %edx
andl $-0x4, %edx
movzwl (%r8,%rdx), %edx
movl %edx, %r13d
andl %ebp, %r13d
movsbl 0x1(%r11,%r13,2), %esi
shrl $0x7, %edx
andl $-0x2, %edx
movl $0x100, %r13d           # imm = 0x100
xorl %r13d, %edx
movswl (%r11,%rdx), %edx
movswl (%r10), %r13d
addl %esi, %r13d
addl %r15d, %r13d
addl %edx, %r13d
movl $0x7fff, %edx           # imm = 0x7FFF
cmpl %edx, %r13d
jl 0x5f54
movl $0x7fff, %r13d          # imm = 0x7FFF
cmpl %r12d, %r13d
jge 0x5f5f
movl $0xffff8000, %r13d      # imm = 0xFFFF8000
orl $0x2, %r9d
andl $-0x2, %r9d
movzwl (%r8,%r9), %esi
movl %esi, %r9d
andl %ebp, %r9d
movsbl 0x1(%rbx,%r9,2), %ebp
shrl $0x7, %esi
andl $-0x2, %esi
movl $0x100, %r9d            # imm = 0x100
xorl %r9d, %esi
movswl (%rbx,%rsi), %esi
movswl (%r10,%r14,2), %r9d
addl %ebp, %r9d
addl %r15d, %r9d
addl %esi, %r9d
cmpl %edx, %r9d
jl 0x5fa4
movl $0x7fff, %r9d           # imm = 0x7FFF
cmpl %r12d, %r9d
jge 0x5faf
movl $0xffff8000, %r9d       # imm = 0xFFFF8000
addl -0x4(%rsp), %edi
movw %r13w, (%r10)
movw %r9w, (%r10,%r14,2)
addq %rax, %r10
movl $0xff, %ebp
jmp 0x5efc
leaq 0x12560(%rip), %rax     # 0x18530
movl %edi, (%rax)
leaq 0x1254f(%rip), %rax     # 0x18528
movq %r10, (%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop