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

/* Variables and functions */
int /*<<< orphan*/ _mm_add_epi32(int /*<<< orphan*/, int /*<<< orphan*/);
unsigned int _mm_cvtsi128_si32(int /*<<< orphan*/);
int /*<<< orphan*/ _mm_loadu_si128(int /*<<< orphan*/ const *);
int /*<<< orphan*/ _mm_madd_epi16(int /*<<< orphan*/ const,
                                  int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_setzero_si128();
int /*<<< orphan*/ _mm_srli_si128(int /*<<< orphan*/, int);
unsigned int aom_get_mb_ss_sse2(const int16_t *src) {
  __m128i vsum = _mm_setzero_si128();
  int i;
  for (i = 0; i < 32; ++i) {
    const __m128i v = _mm_loadu_si128((const __m128i *)src);
    vsum = _mm_add_epi32(vsum, _mm_madd_epi16(v, v));
    src += 8;
  }
  vsum = _mm_add_epi32(vsum, _mm_srli_si128(vsum, 8));
  vsum = _mm_add_epi32(vsum, _mm_srli_si128(vsum, 4));
  return _mm_cvtsi128_si32(vsum);
}


x86 assembly (clang, -O0):
<aom_get_mb_ss_sse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <_mm_setzero_si128@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jge    11cb <aom_get_mb_ss_sse2+0x6b>
mov    -0x8(%rbp),%rdi
call   1080 <_mm_loadu_si128@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <_mm_madd_epi16@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_add_epi32@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117d <aom_get_mb_ss_sse2+0x1d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1060 <_mm_srli_si128@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_add_epi32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
call   1060 <_mm_srli_si128@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_add_epi32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <_mm_cvtsi128_si32@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aom_get_mb_ss_sse2>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <_mm_setzero_si128@plt>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r14,%rbx,1),%rdi
call   1080 <_mm_loadu_si128@plt>
mov    %eax,%edi
mov    %eax,%esi
call   1070 <_mm_madd_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <_mm_add_epi32@plt>
mov    %eax,%ebp
add    $0x20,%rbx
cmp    $0x400,%ebx
jne    1180 <aom_get_mb_ss_sse2+0x20>
mov    %ebp,%edi
mov    $0x8,%esi
call   1060 <_mm_srli_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <_mm_add_epi32@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x4,%esi
call   1060 <_mm_srli_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <_mm_add_epi32@plt>
mov    %eax,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <_mm_cvtsi128_si32@plt>

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

LLVM IR (-O2):
define i32 @aom_get_mb_ss_sse2(i32* %0) {
%2 = tail call i32 (...) @_mm_setzero_si128()
br label %3
3: ; preds = %1, %3
%4 = phi i32* [ %0, %1 ], [ %10, %3 ]
%5 = phi i32 [ 0, %1 ], [ %11, %3 ]
%6 = phi i32 [ %2, %1 ], [ %9, %3 ]
%7 = tail call i32 @_mm_loadu_si128(i32* %4)
%8 = tail call i32 @_mm_madd_epi16(i32 %7, i32 %7)
%9 = tail call i32 @_mm_add_epi32(i32 %6, i32 %8)
%10 = getelementptr inbounds i32, i32* %4, i64 8
%11 = add nuw nsw i32 %5, 1
%12 = icmp eq i32 %11, 32
br i1 %12, label %13, label %3
13: ; preds = %3
%14 = tail call i32 @_mm_srli_si128(i32 %9, i32 8)
%15 = tail call i32 @_mm_add_epi32(i32 %9, i32 %14)
%16 = tail call i32 @_mm_srli_si128(i32 %15, i32 4)
%17 = tail call i32 @_mm_add_epi32(i32 %15, i32 %16)
%18 = tail call i32 @_mm_cvtsi128_si32(i32 %17)
ret i32 %18
}