#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*/ const __m128i;

/* Variables and functions */
int /*<<< orphan*/ _MM_SHUFFLE(int /*<<< orphan*/, int /*<<< orphan*/, int,
                               int);
int /*<<< orphan*/ const _mm_cmpeq_epi32(int /*<<< orphan*/ const,
                                         int /*<<< orphan*/ const);
int _mm_movemask_epi8(int /*<<< orphan*/ const);
int /*<<< orphan*/ const _mm_set1_epi32(int);
int /*<<< orphan*/ const _mm_shuffle_epi32(int /*<<< orphan*/ const,
                                           int /*<<< orphan*/);
int /*<<< orphan*/ const _mm_slli_epi64(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ const _mm_unpacklo_epi64(int /*<<< orphan*/ const,
                                            int /*<<< orphan*/ const);
int k_check_epi32_overflow_4(const __m128i *preg0, const __m128i *preg1,
                             const __m128i *preg2, const __m128i *preg3,
                             const __m128i *zero) {
  __m128i minus_one = _mm_set1_epi32(-1);
  __m128i reg0_shifted = _mm_slli_epi64(*preg0, 1);
  __m128i reg1_shifted = _mm_slli_epi64(*preg1, 1);
  __m128i reg2_shifted = _mm_slli_epi64(*preg2, 1);
  __m128i reg3_shifted = _mm_slli_epi64(*preg3, 1);
  __m128i reg0_top_dwords =
      _mm_shuffle_epi32(reg0_shifted, _MM_SHUFFLE(0, 0, 3, 1));
  __m128i reg1_top_dwords =
      _mm_shuffle_epi32(reg1_shifted, _MM_SHUFFLE(0, 0, 3, 1));
  __m128i reg2_top_dwords =
      _mm_shuffle_epi32(reg2_shifted, _MM_SHUFFLE(0, 0, 3, 1));
  __m128i reg3_top_dwords =
      _mm_shuffle_epi32(reg3_shifted, _MM_SHUFFLE(0, 0, 3, 1));
  __m128i top_dwords_01 = _mm_unpacklo_epi64(reg0_top_dwords, reg1_top_dwords);
  __m128i top_dwords_23 = _mm_unpacklo_epi64(reg2_top_dwords, reg3_top_dwords);
  __m128i valid_positve_01 = _mm_cmpeq_epi32(top_dwords_01, *zero);
  __m128i valid_positve_23 = _mm_cmpeq_epi32(top_dwords_23, *zero);
  __m128i valid_negative_01 = _mm_cmpeq_epi32(top_dwords_01, minus_one);
  __m128i valid_negative_23 = _mm_cmpeq_epi32(top_dwords_23, minus_one);
  int overflow_01 =
      _mm_movemask_epi8(_mm_cmpeq_epi32(valid_positve_01, valid_negative_01));
  int overflow_23 =
      _mm_movemask_epi8(_mm_cmpeq_epi32(valid_positve_23, valid_negative_23));
  return (overflow_01 + overflow_23);
}


x86 assembly (clang, -O0):
<k_check_epi32_overflow_4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    $0xffffffff,%edi
call   1050 <_mm_set1_epi32@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1090 <_mm_slli_epi64@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1090 <_mm_slli_epi64@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1090 <_mm_slli_epi64@plt>
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1090 <_mm_slli_epi64@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x7c(%rbp)
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
mov    %esi,%edi
call   1030 <_MM_SHUFFLE@plt>
mov    -0x7c(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x78(%rbp)
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
mov    %esi,%edi
call   1030 <_MM_SHUFFLE@plt>
mov    -0x78(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x74(%rbp)
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
mov    %esi,%edi
call   1030 <_MM_SHUFFLE@plt>
mov    -0x74(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,-0x48(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x70(%rbp)
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
mov    %esi,%edi
call   1030 <_MM_SHUFFLE@plt>
mov    -0x70(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x44(%rbp),%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,-0x50(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x4c(%rbp),%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x50(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,-0x60(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,-0x64(%rbp)
mov    -0x58(%rbp),%edi
mov    -0x60(%rbp),%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,%edi
call   1070 <_mm_movemask_epi8@plt>
mov    %eax,-0x68(%rbp)
mov    -0x5c(%rbp),%edi
mov    -0x64(%rbp),%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,%edi
call   1070 <_mm_movemask_epi8@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%eax
add    -0x6c(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<k_check_epi32_overflow_4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    $0xffffffff,%edi
call   1050 <_mm_set1_epi32@plt>
mov    %eax,0xc(%rsp)
mov    0x0(%rbp),%edi
mov    $0x1,%esi
call   1090 <_mm_slli_epi64@plt>
mov    %eax,%r15d
mov    (%rbx),%edi
mov    $0x1,%esi
call   1090 <_mm_slli_epi64@plt>
mov    %eax,%r14d
mov    0x0(%r13),%edi
mov    $0x1,%esi
call   1090 <_mm_slli_epi64@plt>
mov    %eax,%r13d
mov    (%r12),%edi
mov    $0x1,%esi
call   1090 <_mm_slli_epi64@plt>
mov    %eax,%r12d
xor    %edi,%edi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
call   1030 <_MM_SHUFFLE@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,%r15d
xor    %edi,%edi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
call   1030 <_MM_SHUFFLE@plt>
mov    %r14d,%edi
mov    %eax,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,%r14d
xor    %edi,%edi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
call   1030 <_MM_SHUFFLE@plt>
mov    %r13d,%edi
mov    %eax,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,%r13d
xor    %edi,%edi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
call   1030 <_MM_SHUFFLE@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,%ebx
mov    %r15d,%edi
mov    %r14d,%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,%ebp
mov    %r13d,%edi
mov    %ebx,%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,%r13d
mov    0x10(%rsp),%rbx
mov    (%rbx),%esi
mov    %ebp,%edi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,%r14d
mov    (%rbx),%esi
mov    %r13d,%edi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    0xc(%rsp),%ebp
mov    %ebp,%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,%r12d
mov    %r13d,%edi
mov    %ebp,%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %r12d,%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,%edi
call   1070 <_mm_movemask_epi8@plt>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %ebx,%esi
call   1060 <_mm_cmpeq_epi32@plt>
mov    %eax,%edi
call   1070 <_mm_movemask_epi8@plt>
add    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @k_check_epi32_overflow_4(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
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = 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
%28 = call i32 @_mm_set1_epi32(i32 -1)
store i32 %28, i32* %11
%29 = load i32*, i32** %6
%30 = load i32, i32* %29
%31 = call i32 @_mm_slli_epi64(i32 %30, i32 1)
store i32 %31, i32* %12
%32 = load i32*, i32** %7
%33 = load i32, i32* %32
%34 = call i32 @_mm_slli_epi64(i32 %33, i32 1)
store i32 %34, i32* %13
%35 = load i32*, i32** %8
%36 = load i32, i32* %35
%37 = call i32 @_mm_slli_epi64(i32 %36, i32 1)
store i32 %37, i32* %14
%38 = load i32*, i32** %9
%39 = load i32, i32* %38
%40 = call i32 @_mm_slli_epi64(i32 %39, i32 1)
store i32 %40, i32* %15
%41 = load i32, i32* %12
%42 = call i32 @_MM_SHUFFLE(i32 0, i32 0, i32 3, i32 1)
%43 = call i32 @_mm_shuffle_epi32(i32 %41, i32 %42)
store i32 %43, i32* %16
%44 = load i32, i32* %13
%45 = call i32 @_MM_SHUFFLE(i32 0, i32 0, i32 3, i32 1)
%46 = call i32 @_mm_shuffle_epi32(i32 %44, i32 %45)
store i32 %46, i32* %17
%47 = load i32, i32* %14
%48 = call i32 @_MM_SHUFFLE(i32 0, i32 0, i32 3, i32 1)
%49 = call i32 @_mm_shuffle_epi32(i32 %47, i32 %48)
store i32 %49, i32* %18
%50 = load i32, i32* %15
%51 = call i32 @_MM_SHUFFLE(i32 0, i32 0, i32 3, i32 1)
%52 = call i32 @_mm_shuffle_epi32(i32 %50, i32 %51)
store i32 %52, i32* %19
%53 = load i32, i32* %16
%54 = load i32, i32* %17
%55 = call i32 @_mm_unpacklo_epi64(i32 %53, i32 %54)
store i32 %55, i32* %20
%56 = load i32, i32* %18
%57 = load i32, i32* %19
%58 = call i32 @_mm_unpacklo_epi64(i32 %56, i32 %57)
store i32 %58, i32* %21
%59 = load i32, i32* %20
%60 = load i32*, i32** %10
%61 = load i32, i32* %60
%62 = call i32 @_mm_cmpeq_epi32(i32 %59, i32 %61)
store i32 %62, i32* %22
%63 = load i32, i32* %21
%64 = load i32*, i32** %10
%65 = load i32, i32* %64
%66 = call i32 @_mm_cmpeq_epi32(i32 %63, i32 %65)
store i32 %66, i32* %23
%67 = load i32, i32* %20
%68 = load i32, i32* %11
%69 = call i32 @_mm_cmpeq_epi32(i32 %67, i32 %68)
store i32 %69, i32* %24
%70 = load i32, i32* %21
%71 = load i32, i32* %11
%72 = call i32 @_mm_cmpeq_epi32(i32 %70, i32 %71)
store i32 %72, i32* %25
%73 = load i32, i32* %22
%74 = load i32, i32* %24
%75 = call i32 @_mm_cmpeq_epi32(i32 %73, i32 %74)
%76 = call i32 @_mm_movemask_epi8(i32 %75)
store i32 %76, i32* %26
%77 = load i32, i32* %23
%78 = load i32, i32* %25
%79 = call i32 @_mm_cmpeq_epi32(i32 %77, i32 %78)
%80 = call i32 @_mm_movemask_epi8(i32 %79)
store i32 %80, i32* %27
%81 = load i32, i32* %26
%82 = load i32, i32* %27
%83 = add nsw i32 %81, %82
ret i32 %83
}

LLVM IR (-O2):
define i32 @k_check_epi32_overflow_4(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture %3, i32* nocapture %4) {
%6 = tail call i32 @_mm_set1_epi32(i32 -1)
%7 = load i32, i32* %0
%8 = tail call i32 @_mm_slli_epi64(i32 %7, i32 1)
%9 = load i32, i32* %1
%10 = tail call i32 @_mm_slli_epi64(i32 %9, i32 1)
%11 = load i32, i32* %2
%12 = tail call i32 @_mm_slli_epi64(i32 %11, i32 1)
%13 = load i32, i32* %3
%14 = tail call i32 @_mm_slli_epi64(i32 %13, i32 1)
%15 = tail call i32 @_MM_SHUFFLE(i32 0, i32 0, i32 3, i32 1)
%16 = tail call i32 @_mm_shuffle_epi32(i32 %8, i32 %15)
%17 = tail call i32 @_MM_SHUFFLE(i32 0, i32 0, i32 3, i32 1)
%18 = tail call i32 @_mm_shuffle_epi32(i32 %10, i32 %17)
%19 = tail call i32 @_MM_SHUFFLE(i32 0, i32 0, i32 3, i32 1)
%20 = tail call i32 @_mm_shuffle_epi32(i32 %12, i32 %19)
%21 = tail call i32 @_MM_SHUFFLE(i32 0, i32 0, i32 3, i32 1)
%22 = tail call i32 @_mm_shuffle_epi32(i32 %14, i32 %21)
%23 = tail call i32 @_mm_unpacklo_epi64(i32 %16, i32 %18)
%24 = tail call i32 @_mm_unpacklo_epi64(i32 %20, i32 %22)
%25 = load i32, i32* %4
%26 = tail call i32 @_mm_cmpeq_epi32(i32 %23, i32 %25)
%27 = load i32, i32* %4
%28 = tail call i32 @_mm_cmpeq_epi32(i32 %24, i32 %27)
%29 = tail call i32 @_mm_cmpeq_epi32(i32 %23, i32 %6)
%30 = tail call i32 @_mm_cmpeq_epi32(i32 %24, i32 %6)
%31 = tail call i32 @_mm_cmpeq_epi32(i32 %26, i32 %29)
%32 = tail call i32 @_mm_movemask_epi8(i32 %31)
%33 = tail call i32 @_mm_cmpeq_epi32(i32 %28, i32 %30)
%34 = tail call i32 @_mm_movemask_epi8(i32 %33)
%35 = add nsw i32 %34, %32
ret i32 %35
}