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

/* Variables and functions */
int /*<<< orphan*/ _mm256_add_epi32(int /*<<< orphan*/,
                                    int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm256_castsi256_si128(int /*<<< orphan*/);
int /*<<< orphan*/ _mm256_extracti128_si256(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm256_srli_si256(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ _mm_add_epi32(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ _mm_cvtsi128_si32(int /*<<< orphan*/);
int /*<<< orphan*/ _mm_srli_si128(int /*<<< orphan*/, int);
unsigned int get_sad_from_mm256_epi32(const __m256i *v) {
  __m128i lo128, hi128;
  __m256i u = _mm256_srli_si256(*v, 8);
  u = _mm256_add_epi32(u, *v);
  hi128 = _mm256_extracti128_si256(u, 1);
  lo128 = _mm256_castsi256_si128(u);
  lo128 = _mm_add_epi32(hi128, lo128);
  hi128 = _mm_srli_si128(lo128, 4);
  lo128 = _mm_add_epi32(lo128, hi128);
  return (unsigned int)_mm_cvtsi128_si32(lo128);
}


x86 assembly (clang, -O0):
<get_sad_from_mm256_epi32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    $0x8,%esi
call   1060 <_mm256_srli_si256@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
call   1090 <_mm256_add_epi32@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1080 <_mm256_extracti128_si256@plt>
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <_mm256_castsi256_si128@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <_mm_add_epi32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
call   1050 <_mm_srli_si128@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <_mm_add_epi32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <_mm_cvtsi128_si32@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sad_from_mm256_epi32>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%edi
mov    $0x8,%esi
call   1060 <_mm256_srli_si256@plt>
mov    (%rbx),%esi
mov    %eax,%edi
call   1090 <_mm256_add_epi32@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1,%esi
call   1080 <_mm256_extracti128_si256@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1070 <_mm256_castsi256_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <_mm_add_epi32@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x4,%esi
call   1050 <_mm_srli_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <_mm_add_epi32@plt>
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <_mm_cvtsi128_si32@plt>

LLVM IR (-O0):
define i32 @get_sad_from_mm256_epi32(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = load i32, i32* %6
%8 = call i32 @_mm256_srli_si256(i32 %7, i32 8)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i32*, i32** %2
%11 = load i32, i32* %10
%12 = call i32 @_mm256_add_epi32(i32 %9, i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = call i32 @_mm256_extracti128_si256(i32 %13, i32 1)
store i32 %14, i32* %4
%15 = load i32, i32* %5
%16 = call i32 @_mm256_castsi256_si128(i32 %15)
store i32 %16, i32* %3
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = call i32 @_mm_add_epi32(i32 %17, i32 %18)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = call i32 @_mm_srli_si128(i32 %20, i32 4)
store i32 %21, i32* %4
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = call i32 @_mm_add_epi32(i32 %22, i32 %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = call i64 @_mm_cvtsi128_si32(i32 %25)
%27 = trunc i64 %26 to i32
ret i32 %27
}

LLVM IR (-O2):
define i32 @get_sad_from_mm256_epi32(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i32 @_mm256_srli_si256(i32 %2, i32 8)
%4 = load i32, i32* %0
%5 = tail call i32 @_mm256_add_epi32(i32 %3, i32 %4)
%6 = tail call i32 @_mm256_extracti128_si256(i32 %5, i32 1)
%7 = tail call i32 @_mm256_castsi256_si128(i32 %5)
%8 = tail call i32 @_mm_add_epi32(i32 %6, i32 %7)
%9 = tail call i32 @_mm_srli_si128(i32 %8, i32 4)
%10 = tail call i32 @_mm_add_epi32(i32 %8, i32 %9)
%11 = tail call i64 @_mm_cvtsi128_si32(i32 %10)
%12 = trunc i64 %11 to i32
ret i32 %12
}