// File: fgheng[P]keysound/src/Mixer.cc
// Function: Mixer::mix32(unsigned char*, unsigned int)
void Mixer::mix32(uint8_t *buf, uint32_t size) {
    // 传入的buffer比较大，		The incoming buffer is relatively large,
    // 超过了剩余的内存			Exceeded the remaining memory
    if (buffer_end - pos < size) {
        mtx.lock();
        for (int i = 0; i < (buffer_end-pos) / 4; i++) {
            int32_t A = *((int32_t *)pos + i);
            int32_t B = *((int32_t *)buf + i);
            *((int32_t *)pos + i) = mix_int32(A, B);
        }

        for (int i = 0; i < (size-(buffer_end-pos)) / 4; i++) {
            int32_t A = *((int32_t *)buffer_start + i);
            int32_t B = *((int32_t *)(buf + (buffer_end - pos)) + i);

            *((int32_t *)buffer_start + i) = mix_int32(A, B);
        }

        mtx.unlock();
    } else {
        mtx.lock();
        for (int i = 0; i < size / 4; i++) {
            int32_t A = *((int32_t *)pos + i);
            int32_t B = *((int32_t *)buf + i);
            *((int32_t *)pos + i) = mix_int32(A, B);
        }

        mtx.unlock();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movq 0x48(%rcx), %rax
movq 0x40(%rcx), %rcx
subq %rcx, %rax
movl -0x14(%rbp), %ecx
cmpq %rcx, %rax
jge 0xdef3
movq -0x40(%rbp), %rdi
callq 0xe250
movl $0x0, -0x18(%rbp)
movq -0x40(%rbp), %rcx
movslq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x48(%rcx), %rax
movq 0x40(%rcx), %rcx
subq %rcx, %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jge 0xde56
movq -0x40(%rbp), %rdi
movq 0x40(%rdi), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0xe330
movl %eax, %edx
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xdde2
movl $0x0, -0x24(%rbp)
movq -0x40(%rbp), %rdx
movslq -0x24(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x14(%rbp), %eax
movq 0x48(%rdx), %rcx
movq 0x40(%rdx), %rdx
subq %rdx, %rcx
subq %rcx, %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jge 0xdee8
movq -0x40(%rbp), %rdi
movq 0x38(%rdi), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rdi), %rcx
movq 0x40(%rdi), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %esi
movl -0x2c(%rbp), %edx
callq 0xe330
movl %eax, %edx
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xde5d
movq -0x40(%rbp), %rdi
callq 0xe2a0
jmp 0xdf60
movq -0x40(%rbp), %rdi
callq 0xe250
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x14(%rbp), %ecx
shrl $0x2, %ecx
cmpl %ecx, %eax
jae 0xdf57
movq -0x40(%rbp), %rdi
movq 0x40(%rdi), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
callq 0xe330
movl %eax, %edx
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xdf03
movq -0x40(%rbp), %rdi
callq 0xe2a0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)