// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq 0x16578(%rip), %rax     # 0x1ef58
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x14(%rbp)
cmpl $0x0, %eax
je 0x8b90
movq -0x20(%rbp), %rax
movl -0x4(%rbp), %ecx
shrl $0x10, %ecx
movl %ecx, %ecx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x2c(%rbp)
movl -0x34(%rbp), %eax
sarl $0x8, %eax
xorl $0x80, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x8(%rbp), %eax
addl -0x4(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq 0x153c5(%rip), %rax     # 0x1de08
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
sarl $0x8, %eax
movl %eax, -0x2c(%rbp)
leaq 0x153ad(%rip), %rax     # 0x1de08
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x30(%rbp)
leaq 0x15390(%rip), %rax     # 0x1de00
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
sarl $0x8, %eax
movl %eax, -0x38(%rbp)
leaq 0x15378(%rip), %rax     # 0x1de00
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
addl $0x80, %eax
movq -0x28(%rbp), %rcx
movswl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
addl $0x80, %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rcx
leaq 0x1637a(%rip), %rax     # 0x1ee40
movl (%rax), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movl -0x44(%rbp), %eax
movslq %edx, %rdx
movswl (%rcx,%rdx,2), %ecx
addl %ecx, %eax
movl %eax, -0x40(%rbp)
cmpl $0xffff8000, -0x34(%rbp) # imm = 0xFFFF8000
jge 0x8af3
movl $0xffff8000, -0x34(%rbp) # imm = 0xFFFF8000
jmp 0x8b05
cmpl $0x7fff, -0x34(%rbp)    # imm = 0x7FFF
jle 0x8b03
movl $0x7fff, -0x34(%rbp)    # imm = 0x7FFF
jmp 0x8b05
cmpl $0xffff8000, -0x40(%rbp) # imm = 0xFFFF8000
jge 0x8b17
movl $0xffff8000, -0x40(%rbp) # imm = 0xFFFF8000
jmp 0x8b29
cmpl $0x7fff, -0x40(%rbp)    # imm = 0x7FFF
jle 0x8b27
movl $0x7fff, -0x40(%rbp)    # imm = 0x7FFF
jmp 0x8b29
movl -0x34(%rbp), %eax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, (%rax)
movl -0x40(%rbp), %eax
movw %ax, -0x52(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x162f4(%rip), %rax     # 0x1ee40
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movw -0x52(%rbp), %dx
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
leaq 0xcbae(%rip), %rax      # 0x1571c
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x89e7
movl -0x4(%rbp), %ecx
leaq 0x163c6(%rip), %rax     # 0x1ef60
movl %ecx, (%rax)
movq -0x28(%rbp), %rcx
leaq 0x163b1(%rip), %rax     # 0x1ef58
movq %rcx, (%rax)
popq %rbp
retq
nopl (%rax)