#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 int16_t;
typedef int /*<<< orphan*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ _mm_extract_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_srli_si128(int /*<<< orphan*/, int);
unsigned int add32x4_sse2(int /*<<< orphan*/);
void variance_final_128_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_add_epi16(vsum, _mm_srli_si128(vsum, 4));
  vsum = _mm_add_epi16(vsum, _mm_srli_si128(vsum, 2));
  *sum = (int16_t)_mm_extract_epi16(vsum, 0);
}


x86 assembly (clang, -O0):
<variance_final_128_pel_sse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <add32x4_sse2@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1040 <_mm_srli_si128@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x2,%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
xor    %esi,%esi
call   1050 <_mm_extract_epi16@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance_final_128_pel_sse2>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
call   1060 <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,%ebx
mov    %eax,%edi
mov    $0x4,%esi
call   1040 <_mm_srli_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x2,%esi
call   1040 <_mm_srli_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1050 <_mm_extract_epi16@plt>
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @variance_final_128_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 i32 @add32x4_sse2(i32 %9)
%11 = load i32*, i32** %7
store i32 %10, i32* %11
%12 = load i32, i32* %6
%13 = load i32, i32* %6
%14 = call i32 @_mm_srli_si128(i32 %13, i32 8)
%15 = call i32 @_mm_add_epi16(i32 %12, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = load i32, i32* %6
%18 = call i32 @_mm_srli_si128(i32 %17, i32 4)
%19 = call i32 @_mm_add_epi16(i32 %16, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = load i32, i32* %6
%22 = call i32 @_mm_srli_si128(i32 %21, i32 2)
%23 = call i32 @_mm_add_epi16(i32 %20, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = call i64 @_mm_extract_epi16(i32 %24, i32 0)
%26 = trunc i64 %25 to i32
%27 = load i32*, i32** %8
store i32 %26, i32* %27
ret void
}

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