#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 int8_t;
typedef int /*<<< orphan*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm_andnot_si128(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_shuffle_epi8(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_unpackhi_epi64(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_unpacklo_epi64(int /*<<< orphan*/, int /*<<< orphan*/);
extern __attribute__((__gnu___, __always___, __artificial__)) __m128i
_MM_PACKUS_EPI32(__m128i a, __m128i b) {
  __attribute__((aligned(16))) int8_t mask8_32_even_odd[16] = {
      0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15};
  __m128i a16, b16, res, reshi, cmp, zero;
  zero = _mm_setzero_si128();
  a16 = _mm_shuffle_epi8(a, *(__m128i *)mask8_32_even_odd);
  b16 = _mm_shuffle_epi8(b, *(__m128i *)mask8_32_even_odd);
  res = _mm_unpacklo_epi64(a16, b16);
  reshi = _mm_unpackhi_epi64(a16, b16);
  cmp = _mm_cmpgt_epi16(zero, reshi);
  res = _mm_andnot_si128(cmp, res);
  cmp = _mm_cmpgt_epi16(reshi, zero);
  return _mm_or_si128(res, cmp);
}


x86 assembly (clang, -O0):
<_MM_PACKUS_EPI32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe67(%rip),%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
mov    $0x0,%al
call   1030 <_mm_setzero_si128@plt>
mov    %eax,-0x68(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x50(%rbp),%esi
call   1040 <_mm_shuffle_epi8@plt>
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x50(%rbp),%esi
call   1040 <_mm_shuffle_epi8@plt>
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   10a0 <_mm_unpacklo_epi64@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   1050 <_mm_unpackhi_epi64@plt>
mov    %eax,-0x60(%rbp)
mov    -0x68(%rbp),%edi
mov    -0x60(%rbp),%esi
call   1060 <_mm_cmpgt_epi16@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%edi
mov    -0x5c(%rbp),%esi
call   1090 <_mm_andnot_si128@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x60(%rbp),%edi
mov    -0x68(%rbp),%esi
call   1060 <_mm_cmpgt_epi16@plt>
mov    %eax,-0x64(%rbp)
mov    -0x5c(%rbp),%edi
mov    -0x64(%rbp),%esi
call   1080 <_mm_or_si128@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_MM_PACKUS_EPI32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <_mm_setzero_si128@plt>
mov    %eax,%r14d
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <_mm_shuffle_epi8@plt>
mov    %eax,%ebx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <_mm_shuffle_epi8@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %eax,%esi
call   1090 <_mm_unpacklo_epi64@plt>
mov    %eax,%r15d
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <_mm_unpackhi_epi64@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %eax,%esi
call   1060 <_mm_cmpgt_epi16@plt>
mov    %eax,%edi
mov    %r15d,%esi
call   1080 <_mm_andnot_si128@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14d,%esi
call   1060 <_mm_cmpgt_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <_mm_or_si128@plt>

LLVM IR (-O0):
@__const._MM_PACKUS_EPI32.mask8_32_even_odd = [16 x i32] [i32 0, i32 1, i32 4, i32 5, i32 8, i32 9, i32 12, i32 13, i32 2, i32 3, i32 6, i32 7, i32 10, i32 11, i32 14, i32 15]
define i32 @_MM_PACKUS_EPI32(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%12 = bitcast [16 x i32]* %5 to i8*
%13 = call i32 (...) @_mm_setzero_si128()
store i32 %13, i32* %11
%14 = load i32, i32* %3
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%16 = load i32, i32* %15
%17 = call i32 @_mm_shuffle_epi8(i32 %14, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %4
%19 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%20 = load i32, i32* %19
%21 = call i32 @_mm_shuffle_epi8(i32 %18, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = call i32 @_mm_unpacklo_epi64(i32 %22, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = call i32 @_mm_unpackhi_epi64(i32 %25, i32 %26)
store i32 %27, i32* %9
%28 = load i32, i32* %11
%29 = load i32, i32* %9
%30 = call i32 @_mm_cmpgt_epi16(i32 %28, i32 %29)
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = load i32, i32* %8
%33 = call i32 @_mm_andnot_si128(i32 %31, i32 %32)
store i32 %33, i32* %8
%34 = load i32, i32* %9
%35 = load i32, i32* %11
%36 = call i32 @_mm_cmpgt_epi16(i32 %34, i32 %35)
store i32 %36, i32* %10
%37 = load i32, i32* %8
%38 = load i32, i32* %10
%39 = call i32 @_mm_or_si128(i32 %37, i32 %38)
ret i32 %39
}

LLVM IR (-O2):
define i32 @_MM_PACKUS_EPI32(i32 %0, i32 %1) {
%3 = tail call i32 (...) @_mm_setzero_si128()
%4 = tail call i32 @_mm_shuffle_epi8(i32 %0, i32 0)
%5 = tail call i32 @_mm_shuffle_epi8(i32 %1, i32 0)
%6 = tail call i32 @_mm_unpacklo_epi64(i32 %4, i32 %5)
%7 = tail call i32 @_mm_unpackhi_epi64(i32 %4, i32 %5)
%8 = tail call i32 @_mm_cmpgt_epi16(i32 %3, i32 %7)
%9 = tail call i32 @_mm_andnot_si128(i32 %8, i32 %6)
%10 = tail call i32 @_mm_cmpgt_epi16(i32 %7, i32 %3)
%11 = tail call i32 @_mm_or_si128(i32 %9, i32 %10)
ret i32 %11
}