#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*/ const _mm256_castsi256_si128(int /*<<< orphan*/);
int /*<<< orphan*/ const _mm256_extractf128_si256(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_add_epi32(int /*<<< orphan*/ const,
                                 int /*<<< orphan*/ const);
int _mm_cvtsi128_si32(int /*<<< orphan*/ const);
int _mm_extract_epi32(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ const _mm_srli_si128(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ _mm_unpackhi_epi32(int /*<<< orphan*/ const,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ _mm_unpacklo_epi32(int /*<<< orphan*/ const,
                                      int /*<<< orphan*/);
void variance_final_from_32bit_sum_avx2(__m256i vsse, __m128i vsum,
                                        unsigned int *const sse,
                                        int *const sum) {
  const __m128i sse_reg_128 = _mm_add_epi32(_mm256_castsi256_si128(vsse),
                                            _mm256_extractf128_si256(vsse, 1));
  const __m128i sse_sum_lo = _mm_unpacklo_epi32(sse_reg_128, vsum);
  const __m128i sse_sum_hi = _mm_unpackhi_epi32(sse_reg_128, vsum);
  const __m128i sse_sum = _mm_add_epi32(sse_sum_lo, sse_sum_hi);
  const __m128i res = _mm_add_epi32(sse_sum, _mm_srli_si128(sse_sum, 8));
  *((int *)sse) = _mm_cvtsi128_si32(res);
  *((int *)sum) = _mm_extract_epi32(res, 1);
}


x86 assembly (clang, -O0):
<variance_final_from_32bit_sum_avx2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1090 <_mm256_castsi256_si128@plt>
mov    %eax,-0x34(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1040 <_mm256_extractf128_si256@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm_add_epi32@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <_mm_unpacklo_epi32@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10a0 <_mm_unpackhi_epi32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1060 <_mm_add_epi32@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
mov    $0x8,%esi
call   1080 <_mm_srli_si128@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm_add_epi32@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <_mm_cvtsi128_si32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%edi
mov    $0x1,%esi
call   1030 <_mm_extract_epi32@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance_final_from_32bit_sum_avx2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r12d
mov    %edi,%ebx
call   1090 <_mm256_castsi256_si128@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0x1,%esi
call   1040 <_mm256_extractf128_si256@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <_mm_add_epi32@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12d,%esi
call   1050 <_mm_unpacklo_epi32@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r12d,%esi
call   10a0 <_mm_unpackhi_epi32@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <_mm_add_epi32@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x8,%esi
call   1080 <_mm_srli_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <_mm_add_epi32@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <_mm_cvtsi128_si32@plt>
mov    %eax,(%r15)
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <_mm_extract_epi32@plt>
mov    %eax,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @variance_final_from_32bit_sum_avx2(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%14 = load i32, i32* %5
%15 = call i32 @_mm256_castsi256_si128(i32 %14)
%16 = load i32, i32* %5
%17 = call i32 @_mm256_extractf128_si256(i32 %16, i32 1)
%18 = call i32 @_mm_add_epi32(i32 %15, i32 %17)
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = load i32, i32* %6
%21 = call i32 @_mm_unpacklo_epi32(i32 %19, i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %9
%23 = load i32, i32* %6
%24 = call i32 @_mm_unpackhi_epi32(i32 %22, i32 %23)
store i32 %24, i32* %11
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = call i32 @_mm_add_epi32(i32 %25, i32 %26)
store i32 %27, i32* %12
%28 = load i32, i32* %12
%29 = load i32, i32* %12
%30 = call i32 @_mm_srli_si128(i32 %29, i32 8)
%31 = call i32 @_mm_add_epi32(i32 %28, i32 %30)
store i32 %31, i32* %13
%32 = load i32, i32* %13
%33 = call i32 @_mm_cvtsi128_si32(i32 %32)
%34 = load i32*, i32** %7
store i32 %33, i32* %34
%35 = load i32, i32* %13
%36 = call i32 @_mm_extract_epi32(i32 %35, i32 1)
%37 = load i32*, i32** %8
store i32 %36, i32* %37
ret void
}

LLVM IR (-O2):
define void @variance_final_from_32bit_sum_avx2(i32 %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i32 @_mm256_castsi256_si128(i32 %0)
%6 = tail call i32 @_mm256_extractf128_si256(i32 %0, i32 1)
%7 = tail call i32 @_mm_add_epi32(i32 %5, i32 %6)
%8 = tail call i32 @_mm_unpacklo_epi32(i32 %7, i32 %1)
%9 = tail call i32 @_mm_unpackhi_epi32(i32 %7, i32 %1)
%10 = tail call i32 @_mm_add_epi32(i32 %8, i32 %9)
%11 = tail call i32 @_mm_srli_si128(i32 %10, i32 8)
%12 = tail call i32 @_mm_add_epi32(i32 %10, i32 %11)
%13 = tail call i32 @_mm_cvtsi128_si32(i32 %12)
store i32 %13, i32* %2
%14 = tail call i32 @_mm_extract_epi32(i32 %12, i32 1)
store i32 %14, i32* %3
ret void
}