#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_and_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_andnot_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cmpeq_epi32(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cmpgt_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_or_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_setzero_si128();
int /*<<< orphan*/ _mm_srli_epi16(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_xor_si128(int /*<<< orphan*/, int /*<<< orphan*/);
__attribute__((always_)) __m128i mm_abs_epi16(__m128i xmm0) {
  __m128i all1 = _mm_cmpeq_epi32(xmm0, xmm0);
  __m128i mask = _mm_cmpgt_epi16(xmm0, _mm_setzero_si128());
  __m128i temp =
      _mm_add_epi16(_mm_xor_si128(xmm0, all1), _mm_srli_epi16(all1, 15));
  return _mm_or_si128(_mm_and_si128(mask, xmm0), _mm_andnot_si128(mask, temp));
}


x86 assembly (clang, -O0):
<mm_abs_epi16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   10a0 <_mm_cmpeq_epi32@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <_mm_setzero_si128@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm_cmpgt_epi16@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <_mm_xor_si128@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xf,%esi
call   1050 <_mm_srli_epi16@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
call   10b0 <_mm_and_si128@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <_mm_andnot_si128@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_or_si128@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mm_abs_epi16>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %edi,%esi
call   10a0 <_mm_cmpeq_epi32@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <_mm_setzero_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <_mm_cmpgt_epi16@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %ebp,%esi
call   1080 <_mm_xor_si128@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    $0xf,%esi
call   1050 <_mm_srli_epi16@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %ebx,%esi
call   10b0 <_mm_and_si128@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %ebp,%esi
call   1090 <_mm_andnot_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <_mm_or_si128@plt>

LLVM IR (-O0):
define i32 @mm_abs_epi16(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @_mm_cmpeq_epi32(i32 %6, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = call i32 (...) @_mm_setzero_si128()
%11 = call i32 @_mm_cmpgt_epi16(i32 %9, i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 @_mm_xor_si128(i32 %12, i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @_mm_srli_epi16(i32 %15, i32 15)
%17 = call i32 @_mm_add_epi16(i32 %14, i32 %16)
store i32 %17, i32* %5
%18 = load i32, i32* %4
%19 = load i32, i32* %2
%20 = call i32 @_mm_and_si128(i32 %18, i32 %19)
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @_mm_andnot_si128(i32 %21, i32 %22)
%24 = call i32 @_mm_or_si128(i32 %20, i32 %23)
ret i32 %24
}

LLVM IR (-O2):
define i32 @mm_abs_epi16(i32 %0) {
%2 = tail call i32 @_mm_cmpeq_epi32(i32 %0, i32 %0)
%3 = tail call i32 (...) @_mm_setzero_si128()
%4 = tail call i32 @_mm_cmpgt_epi16(i32 %0, i32 %3)
%5 = tail call i32 @_mm_xor_si128(i32 %0, i32 %2)
%6 = tail call i32 @_mm_srli_epi16(i32 %2, i32 15)
%7 = tail call i32 @_mm_add_epi16(i32 %5, i32 %6)
%8 = tail call i32 @_mm_and_si128(i32 %4, i32 %0)
%9 = tail call i32 @_mm_andnot_si128(i32 %4, i32 %7)
%10 = tail call i32 @_mm_or_si128(i32 %8, i32 %9)
ret i32 %10
}