#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_epi16(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_add_epi32(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_madd_epi16(int /*<<< orphan*/ const,
                                  int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_sub_epi16(int /*<<< orphan*/ const,
                                 int /*<<< orphan*/ const);
void variance_kernel_sse2(const __m128i src_ptr, const __m128i ref_ptr,
                          __m128i *const sse, __m128i *const sum) {
  const __m128i diff = _mm_sub_epi16(src_ptr, ref_ptr);
  *sse = _mm_add_epi32(*sse, _mm_madd_epi16(diff, diff));
  *sum = _mm_add_epi16(*sum, diff);
}


x86 assembly (clang, -O0):
<variance_kernel_sse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <_mm_sub_epi16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <_mm_madd_epi16@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   1050 <_mm_add_epi32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance_kernel_sse2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
call   1040 <_mm_sub_epi16@plt>
mov    %eax,%ebp
mov    (%rbx),%r15d
mov    %eax,%edi
mov    %eax,%esi
call   1060 <_mm_madd_epi16@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1050 <_mm_add_epi32@plt>
mov    %eax,(%rbx)
mov    (%r14),%edi
mov    %ebp,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @variance_kernel_sse2(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 @_mm_sub_epi16(i32 %10, i32 %11)
store i32 %12, i32* %9
%13 = load i32*, i32** %7
%14 = load i32, i32* %13
%15 = load i32, i32* %9
%16 = load i32, i32* %9
%17 = call i32 @_mm_madd_epi16(i32 %15, i32 %16)
%18 = call i32 @_mm_add_epi32(i32 %14, i32 %17)
%19 = load i32*, i32** %7
store i32 %18, i32* %19
%20 = load i32*, i32** %8
%21 = load i32, i32* %20
%22 = load i32, i32* %9
%23 = call i32 @_mm_add_epi16(i32 %21, i32 %22)
%24 = load i32*, i32** %8
store i32 %23, i32* %24
ret void
}

LLVM IR (-O2):
define void @variance_kernel_sse2(i32 %0, i32 %1, i32* nocapture %2, i32* nocapture %3) {
%5 = tail call i32 @_mm_sub_epi16(i32 %0, i32 %1)
%6 = load i32, i32* %2
%7 = tail call i32 @_mm_madd_epi16(i32 %5, i32 %5)
%8 = tail call i32 @_mm_add_epi32(i32 %6, i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %3
%10 = tail call i32 @_mm_add_epi16(i32 %9, i32 %5)
store i32 %10, i32* %3
ret void
}