#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_packs_epi32(int /*<<< orphan*/ const,
                                   int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_srai_epi32(int /*<<< orphan*/ const, int const);
__m128i mult_round_shift(const __m128i *pin0, const __m128i *pin1,
                         const __m128i *pmultiplier, const __m128i *prounding,
                         const int shift) {
  const __m128i u0 = _mm_madd_epi16(*pin0, *pmultiplier);
  const __m128i u1 = _mm_madd_epi16(*pin1, *pmultiplier);
  const __m128i v0 = _mm_add_epi32(u0, *prounding);
  const __m128i v1 = _mm_add_epi32(u1, *prounding);
  const __m128i w0 = _mm_srai_epi32(v0, shift);
  const __m128i w1 = _mm_srai_epi32(v1, shift);
  return _mm_packs_epi32(w0, w1);
}


x86 assembly (clang, -O0):
<mult_round_shift>:
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    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_madd_epi16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%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   1040 <_mm_add_epi32@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1040 <_mm_add_epi32@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1050 <_mm_srai_epi32@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1050 <_mm_srai_epi32@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%esi
call   1030 <_mm_packs_epi32@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mult_round_shift>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,%r15
mov    (%rdi),%edi
mov    (%rdx),%esi
call   1060 <_mm_madd_epi16@plt>
mov    %eax,%r12d
mov    (%r15),%edi
mov    0x0(%rbp),%esi
call   1060 <_mm_madd_epi16@plt>
mov    %eax,%r15d
mov    (%rbx),%esi
mov    %r12d,%edi
call   1040 <_mm_add_epi32@plt>
mov    %eax,%ebp
mov    (%rbx),%esi
mov    %r15d,%edi
call   1040 <_mm_add_epi32@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <_mm_srai_epi32@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14d,%esi
call   1050 <_mm_srai_epi32@plt>
mov    %ebp,%edi
mov    %eax,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_mm_packs_epi32@plt>

LLVM IR (-O0):
define i32 @mult_round_shift(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = load i32*, i32** %8
%20 = load i32, i32* %19
%21 = call i32 @_mm_madd_epi16(i32 %18, i32 %20)
store i32 %21, i32* %11
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = load i32*, i32** %8
%25 = load i32, i32* %24
%26 = call i32 @_mm_madd_epi16(i32 %23, i32 %25)
store i32 %26, i32* %12
%27 = load i32, i32* %11
%28 = load i32*, i32** %9
%29 = load i32, i32* %28
%30 = call i32 @_mm_add_epi32(i32 %27, i32 %29)
store i32 %30, i32* %13
%31 = load i32, i32* %12
%32 = load i32*, i32** %9
%33 = load i32, i32* %32
%34 = call i32 @_mm_add_epi32(i32 %31, i32 %33)
store i32 %34, i32* %14
%35 = load i32, i32* %13
%36 = load i32, i32* %10
%37 = call i32 @_mm_srai_epi32(i32 %35, i32 %36)
store i32 %37, i32* %15
%38 = load i32, i32* %14
%39 = load i32, i32* %10
%40 = call i32 @_mm_srai_epi32(i32 %38, i32 %39)
store i32 %40, i32* %16
%41 = load i32, i32* %15
%42 = load i32, i32* %16
%43 = call i32 @_mm_packs_epi32(i32 %41, i32 %42)
ret i32 %43
}

LLVM IR (-O2):
define i32 @mult_round_shift(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture %3, i32 %4) {
%6 = load i32, i32* %0
%7 = load i32, i32* %2
%8 = tail call i32 @_mm_madd_epi16(i32 %6, i32 %7)
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = tail call i32 @_mm_madd_epi16(i32 %9, i32 %10)
%12 = load i32, i32* %3
%13 = tail call i32 @_mm_add_epi32(i32 %8, i32 %12)
%14 = load i32, i32* %3
%15 = tail call i32 @_mm_add_epi32(i32 %11, i32 %14)
%16 = tail call i32 @_mm_srai_epi32(i32 %13, i32 %4)
%17 = tail call i32 @_mm_srai_epi32(i32 %15, i32 %4)
%18 = tail call i32 @_mm_packs_epi32(i32 %16, i32 %17)
ret i32 %18
}