#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*/ _mm256_extractf128_si256(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_add_epi16(int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cvtepi16_epi32(int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_srli_si128(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ variance_final_from_32bit_sum_avx2(int /*<<< orphan*/,
                                                      int /*<<< orphan*/ const,
                                                      unsigned int *const,
                                                      int *const);
void variance_final_from_16bit_sum_avx2(__m256i vsse, __m256i vsum,
                                        unsigned int *const sse,
                                        int *const sum) {
  const __m128i sum_reg_128 = _mm_add_epi16(_mm256_castsi256_si128(vsum),
                                            _mm256_extractf128_si256(vsum, 1));
  const __m128i sum_reg_64 =
      _mm_add_epi16(sum_reg_128, _mm_srli_si128(sum_reg_128, 8));
  const __m128i sum_int32 = _mm_cvtepi16_epi32(sum_reg_64);
  variance_final_from_32bit_sum_avx2(vsse, sum_int32, sse, sum);
}


x86 assembly (clang, -O0):
<variance_final_from_16bit_sum_avx2>:
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    -0x8(%rbp),%edi
call   1080 <_mm256_castsi256_si128@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <_mm256_extractf128_si256@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1060 <_mm_srli_si128@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1070 <_mm_cvtepi16_epi32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1050 <variance_final_from_32bit_sum_avx2@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance_final_from_16bit_sum_avx2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebx
mov    %edi,%r12d
mov    %esi,%edi
call   1080 <_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   1030 <_mm_add_epi16@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x8,%esi
call   1060 <_mm_srli_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%edi
call   1070 <_mm_cvtepi16_epi32@plt>
mov    %r12d,%edi
mov    %eax,%esi
mov    %r15,%rdx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <variance_final_from_32bit_sum_avx2@plt>

LLVM IR (-O0):
define void @variance_final_from_16bit_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
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%12 = load i32, i32* %6
%13 = call i32 @_mm256_castsi256_si128(i32 %12)
%14 = load i32, i32* %6
%15 = call i32 @_mm256_extractf128_si256(i32 %14, i32 1)
%16 = call i32 @_mm_add_epi16(i32 %13, i32 %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = load i32, i32* %9
%19 = call i32 @_mm_srli_si128(i32 %18, i32 8)
%20 = call i32 @_mm_add_epi16(i32 %17, i32 %19)
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = call i32 @_mm_cvtepi16_epi32(i32 %21)
store i32 %22, i32* %11
%23 = load i32, i32* %5
%24 = load i32, i32* %11
%25 = load i32*, i32** %7
%26 = load i32*, i32** %8
%27 = call i32 @variance_final_from_32bit_sum_avx2(i32 %23, i32 %24, i32* %25, i32* %26)
ret void
}

LLVM IR (-O2):
define void @variance_final_from_16bit_sum_avx2(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = tail call i32 @_mm256_castsi256_si128(i32 %1)
%6 = tail call i32 @_mm256_extractf128_si256(i32 %1, i32 1)
%7 = tail call i32 @_mm_add_epi16(i32 %5, i32 %6)
%8 = tail call i32 @_mm_srli_si128(i32 %7, i32 8)
%9 = tail call i32 @_mm_add_epi16(i32 %7, i32 %8)
%10 = tail call i32 @_mm_cvtepi16_epi32(i32 %9)
%11 = tail call i32 @variance_final_from_32bit_sum_avx2(i32 %0, i32 %10, i32* %2, i32* %3)
ret void
}