// File: ctSkennerton[P]fxtract/util/msutil.c
// Function: cmpxm
int
cmpxm(void const*_src, void const*_dst, int len)
{
    uint8_t const *src = (uint8_t const*)_src;
    uint8_t const *dst = (uint8_t const*)_dst;
    int ret, srcoff = 15 & (intptr_t)src;

    if (srcoff && len > 31) {
        if ((ret = xm_diff(xm_loud(src), xm_loud(dst))))
            return cmp(ret, src, dst);

        src += 16 - srcoff;
        dst += 16 - srcoff;
        len -= 16 - srcoff;
    }

    // A special case for srcoff==dstoff => xm_load(dst)
    // seems to make no difference.
    // Prefetch windows from 128..512 all do about the same.
#   define PRE (512-64)
    for (; len >= 16; src += 16, dst += 16, len -=16) {
        _mm_prefetch(src+PRE, _MM_HINT_NTA);
        _mm_prefetch(dst+PRE, _MM_HINT_NTA);
        if ((ret = xm_diff(xm_load(src), xm_loud(dst))))
            return cmp(ret, src, dst);
    }

    // xm_loud(dst) can actually go beyond valid mem :-(
    ret = xm_diff(xm_loud(src), xm_loud(dst)) & ~(-1 << len);
    return ret ? cmp(ret,  src, dst) : 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
andq $0xf, %rax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x7c7f
cmpl $0x1f, -0x1c(%rbp)
jle 0x7c7f
movq -0x28(%rbp), %rdi
callq 0x7db0
movaps %xmm0, -0x50(%rbp)
movq -0x30(%rbp), %rdi
callq 0x7db0
movaps %xmm0, %xmm1
movaps -0x50(%rbp), %xmm0
callq 0x7d80
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x7c43
movl -0x34(%rbp), %edi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x7dd0
movl %eax, -0x4(%rbp)
jmp 0x7d6d
movl $0x10, %ecx
subl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x10, %ecx
subl -0x38(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x10, %ecx
subl -0x38(%rbp), %ecx
movl -0x1c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
jmp 0x7c81
cmpl $0x10, -0x1c(%rbp)
jl 0x7d0f
movq -0x28(%rbp), %rax
addq $0x1c0, %rax            # imm = 0x1C0
prefetchnta (%rax)
movq -0x30(%rbp), %rax
addq $0x1c0, %rax            # imm = 0x1C0
prefetchnta (%rax)
movq -0x28(%rbp), %rdi
callq 0x7e20
movaps %xmm0, -0x60(%rbp)
movq -0x30(%rbp), %rdi
callq 0x7db0
movaps %xmm0, %xmm1
movaps -0x60(%rbp), %xmm0
callq 0x7d80
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x7ce7
movl -0x34(%rbp), %edi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x7dd0
movl %eax, -0x4(%rbp)
jmp 0x7d6d
jmp 0x7ce9
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
subl $0x10, %eax
movl %eax, -0x1c(%rbp)
jmp 0x7c81
movq -0x28(%rbp), %rdi
callq 0x7db0
movaps %xmm0, -0x70(%rbp)
movq -0x30(%rbp), %rdi
callq 0x7db0
movaps %xmm0, %xmm1
movaps -0x70(%rbp), %xmm0
callq 0x7d80
movl -0x1c(%rbp), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
movl %edx, %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x7d60
movl -0x34(%rbp), %edi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x7dd0
movl %eax, -0x74(%rbp)
jmp 0x7d67
xorl %eax, %eax
movl %eax, -0x74(%rbp)
jmp 0x7d67
movl -0x74(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)