#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_add_epi32(int /*<<< orphan*/ const,
                                 int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_madd_epi16(int /*<<< orphan*/ const,
                                  int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_setzero_si128();
int /*<<< orphan*/ _mm_unpacklo_epi8(int /*<<< orphan*/ const,
                                     int /*<<< orphan*/);
__m128i mm_madd_add_epi8_sse2(const __m128i *const src_1,
                              const __m128i *const src_2,
                              const __m128i *const ker_1,
                              const __m128i *const ker_2) {
  const __m128i src_1_half = _mm_unpacklo_epi8(*src_1, _mm_setzero_si128());
  const __m128i src_2_half = _mm_unpacklo_epi8(*src_2, _mm_setzero_si128());
  const __m128i madd_1 = _mm_madd_epi16(src_1_half, *ker_1);
  const __m128i madd_2 = _mm_madd_epi16(src_2_half, *ker_2);
  return _mm_add_epi32(madd_1, madd_2);
}


x86 assembly (clang, -O0):
<mm_madd_add_epi8_sse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <_mm_setzero_si128@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_unpacklo_epi8@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1040 <_mm_setzero_si128@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_unpacklo_epi8@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_madd_epi16@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_madd_epi16@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1050 <_mm_add_epi32@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mm_madd_add_epi8_sse2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    (%rdi),%ebp
xor    %eax,%eax
call   1040 <_mm_setzero_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <_mm_unpacklo_epi8@plt>
mov    %eax,%ebp
mov    (%rbx),%ebx
xor    %eax,%eax
call   1040 <_mm_setzero_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <_mm_unpacklo_epi8@plt>
mov    %eax,%ebx
mov    (%r15),%esi
mov    %ebp,%edi
call   1060 <_mm_madd_epi16@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %ebx,%edi
call   1060 <_mm_madd_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <_mm_add_epi32@plt>

LLVM IR (-O0):
define i32 @mm_madd_add_epi8_sse2(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
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%13 = load i32*, i32** %5
%14 = load i32, i32* %13
%15 = call i32 (...) @_mm_setzero_si128()
%16 = call i32 @_mm_unpacklo_epi8(i32 %14, i32 %15)
store i32 %16, i32* %9
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = call i32 (...) @_mm_setzero_si128()
%20 = call i32 @_mm_unpacklo_epi8(i32 %18, i32 %19)
store i32 %20, i32* %10
%21 = load i32, i32* %9
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = call i32 @_mm_madd_epi16(i32 %21, i32 %23)
store i32 %24, i32* %11
%25 = load i32, i32* %10
%26 = load i32*, i32** %8
%27 = load i32, i32* %26
%28 = call i32 @_mm_madd_epi16(i32 %25, i32 %27)
store i32 %28, i32* %12
%29 = load i32, i32* %11
%30 = load i32, i32* %12
%31 = call i32 @_mm_add_epi32(i32 %29, i32 %30)
ret i32 %31
}

LLVM IR (-O2):
define i32 @mm_madd_add_epi8_sse2(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture %3) {
%5 = load i32, i32* %0
%6 = tail call i32 (...) @_mm_setzero_si128()
%7 = tail call i32 @_mm_unpacklo_epi8(i32 %5, i32 %6)
%8 = load i32, i32* %1
%9 = tail call i32 (...) @_mm_setzero_si128()
%10 = tail call i32 @_mm_unpacklo_epi8(i32 %8, i32 %9)
%11 = load i32, i32* %2
%12 = tail call i32 @_mm_madd_epi16(i32 %7, i32 %11)
%13 = load i32, i32* %3
%14 = tail call i32 @_mm_madd_epi16(i32 %10, i32 %13)
%15 = tail call i32 @_mm_add_epi32(i32 %12, i32 %14)
ret i32 %15
}