// File: fgheng[P]keysound/src/Mixer.cc
// Function: Mixer::mix8(unsigned char*, unsigned int)
void Mixer::mix8(uint8_t *buf, uint32_t size) {
    if (buffer_end - pos < size) {
        // 传入的size要比pos 到 end大		The incoming size is larger than "pos" to "end"
        mtx.lock();
        for (int i = 0; i < buffer_end - pos; i++) {
            uint8_t A = *(pos + i);
            uint8_t B = *(buf + i);
            *(pos+i) = mix_uint8(A, B);
        }

        for (int i = 0; i < size - (buffer_end - pos); i++) {
            uint8_t A = *(buffer_start + i);
            uint8_t B = *(buf + (buffer_end - pos) + i);
            *(buffer_start+i) = mix_uint8(A, B);
        }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x38(%rbp)
movq 0x48(%rcx), %rax
movq 0x40(%rcx), %rcx
subq %rcx, %rax
movl -0x14(%rbp), %ecx
cmpq %rcx, %rax
jge 0xdb3e
movq -0x38(%rbp), %rdi
callq 0xe250
movl $0x0, -0x18(%rbp)
movq -0x38(%rbp), %rdx
movslq -0x18(%rbp), %rax
movq 0x48(%rdx), %rcx
movq 0x40(%rdx), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jge 0xdab5
movq -0x38(%rbp), %rdi
movq 0x40(%rdi), %rax
movslq -0x18(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x1a(%rbp)
movb -0x19(%rbp), %al
movzbl %al, %esi
movzbl -0x1a(%rbp), %edx
callq 0xe280
movb %al, %dl
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x18(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xda52
movl $0x0, -0x20(%rbp)
movq -0x38(%rbp), %rsi
movslq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
movq 0x48(%rsi), %rdx
movq 0x40(%rsi), %rsi
subq %rsi, %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jge 0xdb33
movq -0x38(%rbp), %rdi
movq 0x38(%rdi), %rax
movslq -0x20(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x21(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rdi), %rcx
movq 0x40(%rdi), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x22(%rbp)
movb -0x21(%rbp), %al
movzbl %al, %esi
movzbl -0x22(%rbp), %edx
callq 0xe280
movb %al, %dl
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xdabc
movq -0x38(%rbp), %rdi
callq 0xe2a0
jmp 0xdbaa
movq -0x38(%rbp), %rdi
callq 0xe250
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0xdba1
movq -0x38(%rbp), %rdi
movq 0x40(%rdi), %rax
movslq -0x28(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x29(%rbp)
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x2a(%rbp)
movb -0x29(%rbp), %al
movzbl %al, %esi
movzbl -0x2a(%rbp), %edx
callq 0xe280
movb %al, %dl
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x28(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xdb4e
movq -0x38(%rbp), %rdi
callq 0xe2a0
addq $0x40, %rsp
popq %rbp
retq