#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*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm_madd_epi16(int /*<<< orphan*/ const,
                                  int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_packs_epi32(int /*<<< orphan*/ const,
                                   int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_set1_epi16(int);
void HorizontalAddPack_SSE2(const __m128i *const A, const __m128i *const B,
                            __m128i *const out) {
  const __m128i k2 = _mm_set1_epi16(2);
  const __m128i C = _mm_madd_epi16(*A, k2);
  const __m128i D = _mm_madd_epi16(*B, k2);
  *out = _mm_packs_epi32(C, D);
}


x86 assembly (clang, -O0):
<HorizontalAddPack_SSE2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x2,%edi
call   1040 <_mm_set1_epi16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
call   1050 <_mm_madd_epi16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
call   1050 <_mm_madd_epi16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <_mm_packs_epi32@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HorizontalAddPack_SSE2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x2,%edi
call   1040 <_mm_set1_epi16@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
mov    %eax,%esi
call   1050 <_mm_madd_epi16@plt>
mov    %eax,%ebx
mov    (%r15),%edi
mov    %ebp,%esi
call   1050 <_mm_madd_epi16@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <_mm_packs_epi32@plt>
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @HorizontalAddPack_SSE2(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%10 = call i32 @_mm_set1_epi16(i32 2)
store i32 %10, i32* %7
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = load i32, i32* %7
%14 = call i32 @_mm_madd_epi16(i32 %12, i32 %13)
store i32 %14, i32* %8
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = load i32, i32* %7
%18 = call i32 @_mm_madd_epi16(i32 %16, i32 %17)
store i32 %18, i32* %9
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = call i32 @_mm_packs_epi32(i32 %19, i32 %20)
%22 = load i32*, i32** %6
store i32 %21, i32* %22
ret void
}

LLVM IR (-O2):
define void @HorizontalAddPack_SSE2(i32* nocapture %0, i32* nocapture %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @_mm_set1_epi16(i32 2)
%5 = load i32, i32* %0
%6 = tail call i32 @_mm_madd_epi16(i32 %5, i32 %4)
%7 = load i32, i32* %1
%8 = tail call i32 @_mm_madd_epi16(i32 %7, i32 %4)
%9 = tail call i32 @_mm_packs_epi32(i32 %6, i32 %8)
store i32 %9, i32* %2
ret void
}