#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*/);
int /*<<< orphan*/ _mm_loadu_si128(int /*<<< orphan*/ const *);
int /*<<< orphan*/ _mm_madd_epi16(int /*<<< orphan*/ const,
                                  int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_setzero_si128();
unsigned int add32x4_sse2(int /*<<< orphan*/);
unsigned int vpx_get_mb_ss_sse2(const int16_t *src_ptr) {
  __m128i vsum = _mm_setzero_si128();
  int i;
  for (i = 0; i < 32; ++i) {
    const __m128i v = _mm_loadu_si128((const __m128i *)src_ptr);
    vsum = _mm_add_epi32(vsum, _mm_madd_epi16(v, v));
    src_ptr += 8;
  }
  return add32x4_sse2(vsum);
}


x86 assembly (clang, -O0):
<vpx_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    11bb <vpx_get_mb_ss_sse2+0x6b>
mov    -0x8(%rbp),%rdi
call   1060 <_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   1050 <_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    116d <vpx_get_mb_ss_sse2+0x1d>
mov    -0xc(%rbp),%edi
call   1070 <add32x4_sse2@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vpx_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   1060 <_mm_loadu_si128@plt>
mov    %eax,%edi
mov    %eax,%esi
call   1050 <_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    1170 <vpx_get_mb_ss_sse2+0x20>
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <add32x4_sse2@plt>

LLVM IR (-O0):
define i32 @vpx_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 = call i32 @add32x4_sse2(i32 %24)
ret i32 %25
}

LLVM IR (-O2):
define i32 @vpx_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 @add32x4_sse2(i32 %9)
ret i32 %14
}