// File: /workspace/github_c_makefile_star2_O0/jonof[P]jfaudiolib/src/mixst.c
// Function: MV_Mix16BitMono16Stereo
void MV_Mix16BitMono16Stereo( 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];
        sample0 = sample0l + sample0h + 128;
        sample1l = MV_LeftVolume[sample1l] >> 8;
        sample1h = MV_LeftVolume[sample1h];
        sample1 = sample1l + sample1h + 128;
        
        sample0 = (sample0 + sample1) / 2 + *dest;
        if (sample0 < -32768) sample0 = -32768;
        else if (sample0 > 32767) sample0 = 32767;
        
        *dest = (short) sample0;
        
        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 0x15c18(%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 0x94ad
movq -0x20(%rbp), %rax
movl -0x4(%rbp), %ecx
shrl $0x10, %ecx
shll %ecx
movl %ecx, %ecx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movl -0x4(%rbp), %ecx
shrl $0x10, %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x40(%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 -0x40(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x38(%rbp)
movl -0x40(%rbp), %eax
sarl $0x8, %eax
xorl $0x80, %eax
movl %eax, -0x3c(%rbp)
movl -0x8(%rbp), %eax
addl -0x4(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq 0x14a3e(%rip), %rax     # 0x1de08
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
sarl $0x8, %eax
movl %eax, -0x2c(%rbp)
leaq 0x14a26(%rip), %rax     # 0x1de08
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
addl $0x80, %eax
movl %eax, -0x34(%rbp)
leaq 0x14a03(%rip), %rax     # 0x1de08
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
sarl $0x8, %eax
movl %eax, -0x38(%rbp)
leaq 0x149eb(%rip), %rax     # 0x1de08
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
addl $0x80, %eax
movl %eax, -0x40(%rbp)
movl -0x34(%rbp), %eax
addl -0x40(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movq -0x28(%rbp), %rcx
movswl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x34(%rbp)
cmpl $0xffff8000, -0x34(%rbp) # imm = 0xFFFF8000
jge 0x9465
movl $0xffff8000, -0x34(%rbp) # imm = 0xFFFF8000
jmp 0x9477
cmpl $0x7fff, -0x34(%rbp)    # imm = 0x7FFF
jle 0x9475
movl $0x7fff, -0x34(%rbp)    # imm = 0x7FFF
jmp 0x9477
movl -0x34(%rbp), %eax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, (%rax)
leaq 0xc291(%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 0x9347
movl -0x4(%rbp), %ecx
leaq 0x15aa9(%rip), %rax     # 0x1ef60
movl %ecx, (%rax)
movq -0x28(%rbp), %rcx
leaq 0x15a94(%rip), %rax     # 0x1ef58
movq %rcx, (%rax)
popq %rbp
retq
nopl (%rax)