#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_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_mullo_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set1_epi16(int);
int /*<<< orphan*/ _mm_srli_epi16(int /*<<< orphan*/, int);
__m128i SkMul16ShiftRound_SSE(__m128i a, __m128i b, int shift) {
  __m128i prod = _mm_mullo_epi16(a, b);
  prod = _mm_add_epi16(prod, _mm_set1_epi16(1 << (shift - 1)));
  prod = _mm_add_epi16(prod, _mm_srli_epi16(prod, shift));
  prod = _mm_srli_epi16(prod, shift);
  return prod;
}


x86 assembly (clang, -O0):
<SkMul16ShiftRound_SSE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <_mm_mullo_epi16@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%edi
shl    %cl,%edi
call   1050 <_mm_set1_epi16@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <_mm_srli_epi16@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <_mm_srli_epi16@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SkMul16ShiftRound_SSE>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
call   1060 <_mm_mullo_epi16@plt>
mov    %eax,%ebp
lea    -0x1(%rbx),%ecx
mov    $0x1,%edi
shl    %cl,%edi
call   1050 <_mm_set1_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %ebx,%esi
call   1040 <_mm_srli_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <_mm_srli_epi16@plt>

LLVM IR (-O0):
define i32 @SkMul16ShiftRound_SSE(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = call i32 @_mm_mullo_epi16(i32 %8, i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 1
%14 = shl i32 1, %13
%15 = call i32 @_mm_set1_epi16(i32 %14)
%16 = call i32 @_mm_add_epi16(i32 %11, i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = call i32 @_mm_srli_epi16(i32 %18, i32 %19)
%21 = call i32 @_mm_add_epi16(i32 %17, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = call i32 @_mm_srli_epi16(i32 %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
ret i32 %25
}

LLVM IR (-O2):
define i32 @SkMul16ShiftRound_SSE(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @_mm_mullo_epi16(i32 %0, i32 %1)
%5 = add nsw i32 %2, -1
%6 = shl nuw i32 1, %5
%7 = tail call i32 @_mm_set1_epi16(i32 %6)
%8 = tail call i32 @_mm_add_epi16(i32 %4, i32 %7)
%9 = tail call i32 @_mm_srli_epi16(i32 %8, i32 %2)
%10 = tail call i32 @_mm_add_epi16(i32 %8, i32 %9)
%11 = tail call i32 @_mm_srli_epi16(i32 %10, i32 %2)
ret i32 %11
}