// File: /workspace/github_c_makefile_star2_O3/jonof[P]jfaudiolib/src/mix.c
// Function: MV_Mix16BitStereo16
void MV_Mix16BitStereo16( 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];
#ifdef BIGENDIAN
        sample0l = sample0 >> 8;
        sample0h = (sample0 & 255) ^ 128;
#else
        sample0l = sample0 & 255;
        sample0h = (sample0 >> 8) ^ 128;
#endif
        sample1l = sample0l;
        sample1h = sample0h;
        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, -0x8(%rsp)
leaq 0x13885(%rip), %rax     # 0x19518
movq (%rax), %r8
testl %ecx, %ecx
je 0x5d91
leaq 0x12793(%rip), %rax     # 0x18438
movq (%rax), %r9
leaq 0x12781(%rip), %rax     # 0x18430
movq (%rax), %r10
leaq 0x137b3(%rip), %rax     # 0x1946c
movl (%rax), %eax
movl %eax, %r11d
shrl $0x1f, %r11d
addl %eax, %r11d
sarl %r11d
movslq %r11d, %r11
leaq 0xa53e(%rip), %rax      # 0x10210
movl (%rax), %eax
movl %eax, %ebx
shrl $0x1f, %ebx
addl %eax, %ebx
sarl %ebx
movslq %ebx, %rbx
addq %rbx, %rbx
movl $0x80, %edx
movl $0xffff8001, %r14d      # imm = 0xFFFF8001
movl %edi, %eax
shrl $0x10, %eax
movq -0x8(%rsp), %r15
movzwl (%r15,%rax,2), %r12d
movzbl %r12b, %r13d
addl %r13d, %r13d
movsbl 0x1(%r9,%r13), %eax
shrl $0x7, %r12d
andl $-0x2, %r12d
xorl $0x100, %r12d           # imm = 0x100
movswl (%r9,%r12), %ebp
movswl (%r8), %r15d
addl %eax, %r15d
addl %ebp, %r15d
addl %edx, %r15d
movl $0x7fff, %eax           # imm = 0x7FFF
cmpl %eax, %r15d
jl 0x5d3b
movl $0x7fff, %r15d          # imm = 0x7FFF
cmpl %r14d, %r15d
jge 0x5d46
movl $0xffff8000, %r15d      # imm = 0xFFFF8000
movsbl 0x1(%r10,%r13), %ebp
movswl (%r10,%r12), %r13d
movswl (%r8,%r11,2), %r12d
addl %ebp, %r12d
addl %r13d, %r12d
addl %edx, %r12d
cmpl %eax, %r12d
jl 0x5d6a
movl $0x7fff, %r12d          # imm = 0x7FFF
cmpl %r14d, %r12d
jge 0x5d75
movl $0xffff8000, %r12d      # imm = 0xFFFF8000
addl %esi, %edi
leaq (%r8,%rbx), %rax
movw %r15w, (%r8)
movw %r12w, (%r8,%r11,2)
movq %rax, %r8
decl %ecx
jne 0x5cee
jmp 0x5d94
movq %r8, %rax
leaq 0x13785(%rip), %rcx     # 0x19520
movl %edi, (%rcx)
leaq 0x13774(%rip), %rcx     # 0x19518
movq %rax, (%rcx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq