#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_epi8(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_and_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cmpgt_epi32(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cmplt_epi32(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_or_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set1_epi32(int);
int /*<<< orphan*/ _mm_setzero_si128();
int /*<<< orphan*/ _mm_xor_si128(int /*<<< orphan*/, int /*<<< orphan*/);
__m128i _mm_sign_epi32_sse2(__m128i a, __m128i b) {
  __m128i ap, an, c, d, one;
  d = _mm_cmpgt_epi32(b, _mm_setzero_si128());
  ap = _mm_and_si128(a, d);
  c = _mm_cmplt_epi32(b, _mm_setzero_si128());
  one = _mm_set1_epi32(1);
  an = _mm_and_si128(a, c);
  an = _mm_xor_si128(an, c);
  one = _mm_and_si128(one, c);
  an = _mm_add_epi8(an, one);
  return (_mm_or_si128(an, ap));
}


x86 assembly (clang, -O0):
<_mm_sign_epi32_sse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <_mm_setzero_si128@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_cmpgt_epi32@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1090 <_mm_and_si128@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <_mm_setzero_si128@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   10a0 <_mm_cmplt_epi32@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
call   1050 <_mm_set1_epi32@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <_mm_and_si128@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <_mm_and_si128@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1080 <_mm_add_epi8@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <_mm_or_si128@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mm_sign_epi32_sse2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %edi,%r15d
xor    %eax,%eax
call   1040 <_mm_setzero_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <_mm_cmpgt_epi32@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1090 <_mm_and_si128@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1040 <_mm_setzero_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   10a0 <_mm_cmplt_epi32@plt>
mov    %eax,%ebx
mov    $0x1,%edi
call   1050 <_mm_set1_epi32@plt>
mov    %eax,%r12d
mov    %r15d,%edi
mov    %ebx,%esi
call   1090 <_mm_and_si128@plt>
mov    %eax,%edi
mov    %ebx,%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,%ebp
mov    %r12d,%edi
mov    %ebx,%esi
call   1090 <_mm_and_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1080 <_mm_add_epi8@plt>
mov    %eax,%edi
mov    %r14d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <_mm_or_si128@plt>

LLVM IR (-O0):
define i32 @_mm_sign_epi32_sse2(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = call i32 (...) @_mm_setzero_si128()
%12 = call i32 @_mm_cmpgt_epi32(i32 %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %3
%14 = load i32, i32* %8
%15 = call i32 @_mm_and_si128(i32 %13, i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %4
%17 = call i32 (...) @_mm_setzero_si128()
%18 = call i32 @_mm_cmplt_epi32(i32 %16, i32 %17)
store i32 %18, i32* %7
%19 = call i32 @_mm_set1_epi32(i32 1)
store i32 %19, i32* %9
%20 = load i32, i32* %3
%21 = load i32, i32* %7
%22 = call i32 @_mm_and_si128(i32 %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = call i32 @_mm_xor_si128(i32 %23, i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %9
%27 = load i32, i32* %7
%28 = call i32 @_mm_and_si128(i32 %26, i32 %27)
store i32 %28, i32* %9
%29 = load i32, i32* %6
%30 = load i32, i32* %9
%31 = call i32 @_mm_add_epi8(i32 %29, i32 %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = call i32 @_mm_or_si128(i32 %32, i32 %33)
ret i32 %34
}

LLVM IR (-O2):
define i32 @_mm_sign_epi32_sse2(i32 %0, i32 %1) {
%3 = tail call i32 (...) @_mm_setzero_si128()
%4 = tail call i32 @_mm_cmpgt_epi32(i32 %1, i32 %3)
%5 = tail call i32 @_mm_and_si128(i32 %0, i32 %4)
%6 = tail call i32 (...) @_mm_setzero_si128()
%7 = tail call i32 @_mm_cmplt_epi32(i32 %1, i32 %6)
%8 = tail call i32 @_mm_set1_epi32(i32 1)
%9 = tail call i32 @_mm_and_si128(i32 %0, i32 %7)
%10 = tail call i32 @_mm_xor_si128(i32 %9, i32 %7)
%11 = tail call i32 @_mm_and_si128(i32 %8, i32 %7)
%12 = tail call i32 @_mm_add_epi8(i32 %10, i32 %11)
%13 = tail call i32 @_mm_or_si128(i32 %12, i32 %5)
ret i32 %13
}