#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*/);
int /*<<< orphan*/ _mm_srai_epi32(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_srli_si128(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_unpacklo_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
void *add32x4_sse2(int /*<<< orphan*/);
void variance_final_512_pel_sse2(__m128i vsse, __m128i vsum,
                                 unsigned int *const sse, int *const sum) {
  *sse = add32x4_sse2(vsse);
  vsum = _mm_add_epi16(vsum, _mm_srli_si128(vsum, 8));
  vsum = _mm_unpacklo_epi16(vsum, vsum);
  vsum = _mm_srai_epi32(vsum, 16);
  *sum = add32x4_sse2(vsum);
}


x86 assembly (clang, -O0):
<variance_final_512_pel_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
call   1070 <add32x4_sse2@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <_mm_unpacklo_epi16@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x10,%esi
call   1050 <_mm_srai_epi32@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <add32x4_sse2@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance_final_512_pel_sse2>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
call   1070 <add32x4_sse2@plt>
mov    %eax,(%rbx)
mov    %ebp,%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%edi
mov    %eax,%esi
call   1060 <_mm_unpacklo_epi16@plt>
mov    %eax,%edi
mov    $0x10,%esi
call   1050 <_mm_srai_epi32@plt>
mov    %eax,%edi
call   1070 <add32x4_sse2@plt>
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @variance_final_512_pel_sse2(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%9 = load i32, i32* %5
%10 = call i8* @add32x4_sse2(i32 %9)
%11 = ptrtoint i8* %10 to i32
%12 = load i32*, i32** %7
store i32 %11, i32* %12
%13 = load i32, i32* %6
%14 = load i32, i32* %6
%15 = call i32 @_mm_srli_si128(i32 %14, i32 8)
%16 = call i32 @_mm_add_epi16(i32 %13, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = load i32, i32* %6
%19 = call i32 @_mm_unpacklo_epi16(i32 %17, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = call i32 @_mm_srai_epi32(i32 %20, i32 16)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i8* @add32x4_sse2(i32 %22)
%24 = ptrtoint i8* %23 to i32
%25 = load i32*, i32** %8
store i32 %24, i32* %25
ret void
}

LLVM IR (-O2):
define void @variance_final_512_pel_sse2(i32 %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i8* @add32x4_sse2(i32 %0)
%6 = ptrtoint i8* %5 to i64
%7 = trunc i64 %6 to i32
store i32 %7, i32* %2
%8 = tail call i32 @_mm_srli_si128(i32 %1, i32 8)
%9 = tail call i32 @_mm_add_epi16(i32 %1, i32 %8)
%10 = tail call i32 @_mm_unpacklo_epi16(i32 %9, i32 %9)
%11 = tail call i32 @_mm_srai_epi32(i32 %10, i32 16)
%12 = tail call i8* @add32x4_sse2(i32 %11)
%13 = ptrtoint i8* %12 to i64
%14 = trunc i64 %13 to i32
store i32 %14, i32* %3
ret void
}