int asm_sumsqr_784(const unsigned char *p1, const unsigned char *p2) {
  int i;
  int s = 0;
  asm("pxor %%xmm6,%%xmm6\n\t"
      "pxor %%xmm7,%%xmm7"
      :
      :
      : "memory");
  for (i = 0; i < 784; i += 16) {
    asm("movdqa %0,%%xmm0\n\t"
        "movdqa %1,%%xmm1\n\t"
        "prefetcht1 %2\n\t"
        "prefetcht1 %3\n\t"
        "movdqa %%xmm0,%%xmm2\n\t"
        "movdqa %%xmm1,%%xmm3\n\t"
        "punpcklbw %%xmm7,%%xmm2\n\t"
        "punpcklbw %%xmm7,%%xmm3\n\t"
        "punpckhbw %%xmm7,%%xmm0\n\t"
        "punpckhbw %%xmm7,%%xmm1\n\t"
        "psubw %%xmm2,%%xmm3\n\t"
        "psubw %%xmm0,%%xmm1\n\t"
        "pmaddwd %%xmm3,%%xmm3\n\t"
        "pmaddwd %%xmm1,%%xmm1\n\t"
        "paddd %%xmm3,%%xmm6\n\t"
        "paddd %%xmm1,%%xmm6"
        :
        : "m"(p1[i]), "m"(p2[i]), "m"(p1[i + 64]), "m"(p2[i + 64]));
  }
  asm("pshufd %1,%%xmm6,%%xmm7\n\t"
      "paddd %%xmm7,%%xmm6\n\t"
      "pshufd %2,%%xmm6,%%xmm7\n\t"
      "paddd %%xmm7,%%xmm6\n\t"
      "movd  %%xmm6,%0"
      : "=m"(s)
      : "i"(0x4e), "i"(0x93)
      : "memory");
  return s;
}


x86 assembly (clang, -O0):
<asm_sumsqr_784>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
pxor   %xmm6,%xmm6
pxor   %xmm7,%xmm7
movl   $0x0,-0x14(%rbp)
cmpl   $0x310,-0x14(%rbp)
jge    11b1 <asm_sumsqr_784+0xb1>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
add    %rdx,%rcx
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%esi
add    $0x40,%esi
movslq %esi,%rsi
add    %rsi,%rdx
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edi
add    $0x40,%edi
movslq %edi,%rdi
add    %rdi,%rsi
movdqa (%rax),%xmm0
movdqa (%rcx),%xmm1
prefetcht1 (%rdx)
prefetcht1 (%rsi)
movdqa %xmm0,%xmm2
movdqa %xmm1,%xmm3
punpcklbw %xmm7,%xmm2
punpcklbw %xmm7,%xmm3
punpckhbw %xmm7,%xmm0
punpckhbw %xmm7,%xmm1
psubw  %xmm2,%xmm3
psubw  %xmm0,%xmm1
pmaddwd %xmm3,%xmm3
pmaddwd %xmm1,%xmm1
paddd  %xmm3,%xmm6
paddd  %xmm1,%xmm6
mov    -0x14(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x14(%rbp)
jmp    1122 <asm_sumsqr_784+0x22>
pshufd $0x4e,%xmm6,%xmm7
paddd  %xmm7,%xmm6
pshufd $0x93,%xmm6,%xmm7
paddd  %xmm7,%xmm6
movd   %xmm6,-0x18(%rbp)
mov    -0x18(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<asm_sumsqr_784>:
movl   $0x0,-0x4(%rsp)
pxor   %xmm6,%xmm6
pxor   %xmm7,%xmm7
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqa (%rdi,%rax,1),%xmm0
movdqa (%rsi,%rax,1),%xmm1
prefetcht1 0x40(%rdi,%rax,1)
prefetcht1 0x40(%rsi,%rax,1)
movdqa %xmm0,%xmm2
movdqa %xmm1,%xmm3
punpcklbw %xmm7,%xmm2
punpcklbw %xmm7,%xmm3
punpckhbw %xmm7,%xmm0
punpckhbw %xmm7,%xmm1
psubw  %xmm2,%xmm3
psubw  %xmm0,%xmm1
pmaddwd %xmm3,%xmm3
pmaddwd %xmm1,%xmm1
paddd  %xmm3,%xmm6
paddd  %xmm1,%xmm6
lea    0x10(%rax),%rcx
cmp    $0x300,%rax
mov    %rcx,%rax
jb     1120 <asm_sumsqr_784+0x20>
pshufd $0x4e,%xmm6,%xmm7
paddd  %xmm7,%xmm6
pshufd $0x93,%xmm6,%xmm7
paddd  %xmm7,%xmm6
movd   %xmm6,-0x4(%rsp)
mov    -0x4(%rsp),%eax
ret

LLVM IR (-O0):
define i32 @asm_sumsqr_784(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %29, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 784
br i1 %9, label %10, label %32
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 64
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 64
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
br label %29
29: ; preds = %10
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 16
store i32 %31, i32* %5
br label %7
32: ; preds = %7
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
define i32 @asm_sumsqr_784(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
tail call void asm sideeffect "pxor %xmm6,%xmm6\0A\09pxor %xmm7,%xmm7", "~{memory},~{dirflag},~{fpsr},~{flags}"()
br label %5
5: ; preds = %2, %5
%6 = phi i64 [ 0, %2 ], [ %12, %5 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds i8, i8* %1, i64 %6
%9 = add nuw nsw i64 %6, 64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = getelementptr inbounds i8, i8* %1, i64 %9
tail call void asm sideeffect "movdqa $0,%xmm0\0A\09movdqa $1,%xmm1\0A\09prefetcht1 $2\0A\09prefetcht1 $3\0A\09movdqa %xmm0,%xmm2\0A\09movdqa %xmm1,%xmm3\0A\09punpcklbw %xmm7,%xmm2\0A\09punpcklbw %xmm7,%xmm3\0A\09punpckhbw %xmm7,%xmm0\0A\09punpckhbw %xmm7,%xmm1\0A\09psubw %xmm2,%xmm3\0A\09psubw %xmm0,%xmm1\0A\09pmaddwd %xmm3,%xmm3\0A\09pmaddwd %xmm1,%xmm1\0A\09paddd %xmm3,%xmm6\0A\09paddd %xmm1,%xmm6", "*m,*m,*m,*m,~{dirflag},~{fpsr},~{flags}"(i8* elementtype(i8) %7, i8* elementtype(i8) %8, i8* elementtype(i8) %10, i8* elementtype(i8) %11)
%12 = add nuw nsw i64 %6, 16
%13 = icmp ult i64 %6, 768
br i1 %13, label %5, label %14
14: ; preds = %5
%15 = load i32, i32* %3
ret i32 %15
}