#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_cmpgt_epi8(int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_packs_epi16(int /*<<< orphan*/ const,
                                   int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_setzero_si128();
int /*<<< orphan*/ _mm_srai_epi16(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ _mm_unpackhi_epi8(int /*<<< orphan*/,
                                     int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_unpacklo_epi8(int /*<<< orphan*/,
                                     int /*<<< orphan*/ const);
void SignedShift8b(__m128i *const x) {
  const __m128i zero = _mm_setzero_si128();
  const __m128i signs = _mm_cmpgt_epi8(zero, *x);
  const __m128i lo_0 = _mm_unpacklo_epi8(*x, signs);
  const __m128i hi_0 = _mm_unpackhi_epi8(*x, signs);
  const __m128i lo_1 = _mm_srai_epi16(lo_0, 3);
  const __m128i hi_1 = _mm_srai_epi16(hi_0, 3);
  *x = _mm_packs_epi16(lo_1, hi_1);
}


x86 assembly (clang, -O0):
<SignedShift8b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <_mm_setzero_si128@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_cmpgt_epi8@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%esi
call   1030 <_mm_unpacklo_epi8@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%esi
call   1040 <_mm_unpackhi_epi8@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
call   1070 <_mm_srai_epi16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x3,%esi
call   1070 <_mm_srai_epi16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1080 <_mm_packs_epi16@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SignedShift8b>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <_mm_setzero_si128@plt>
mov    (%rbx),%esi
mov    %eax,%edi
call   1060 <_mm_cmpgt_epi8@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
mov    %eax,%esi
call   1030 <_mm_unpacklo_epi8@plt>
mov    %eax,%r14d
mov    (%rbx),%edi
mov    %ebp,%esi
call   1040 <_mm_unpackhi_epi8@plt>
mov    %eax,%r15d
mov    %r14d,%edi
mov    $0x3,%esi
call   1070 <_mm_srai_epi16@plt>
mov    %eax,%ebp
mov    %r15d,%edi
mov    $0x3,%esi
call   1070 <_mm_srai_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1080 <_mm_packs_epi16@plt>
mov    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @SignedShift8b(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %2
%9 = call i32 (...) @_mm_setzero_si128()
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = load i32*, i32** %2
%12 = load i32, i32* %11
%13 = call i32 @_mm_cmpgt_epi8(i32 %10, i32 %12)
store i32 %13, i32* %4
%14 = load i32*, i32** %2
%15 = load i32, i32* %14
%16 = load i32, i32* %4
%17 = call i32 @_mm_unpacklo_epi8(i32 %15, i32 %16)
store i32 %17, i32* %5
%18 = load i32*, i32** %2
%19 = load i32, i32* %18
%20 = load i32, i32* %4
%21 = call i32 @_mm_unpackhi_epi8(i32 %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %5
%23 = call i32 @_mm_srai_epi16(i32 %22, i32 3)
store i32 %23, i32* %7
%24 = load i32, i32* %6
%25 = call i32 @_mm_srai_epi16(i32 %24, i32 3)
store i32 %25, i32* %8
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = call i32 @_mm_packs_epi16(i32 %26, i32 %27)
%29 = load i32*, i32** %2
store i32 %28, i32* %29
ret void
}

LLVM IR (-O2):
define void @SignedShift8b(i32* nocapture %0) {
%2 = tail call i32 (...) @_mm_setzero_si128()
%3 = load i32, i32* %0
%4 = tail call i32 @_mm_cmpgt_epi8(i32 %2, i32 %3)
%5 = load i32, i32* %0
%6 = tail call i32 @_mm_unpacklo_epi8(i32 %5, i32 %4)
%7 = load i32, i32* %0
%8 = tail call i32 @_mm_unpackhi_epi8(i32 %7, i32 %4)
%9 = tail call i32 @_mm_srai_epi16(i32 %6, i32 3)
%10 = tail call i32 @_mm_srai_epi16(i32 %8, i32 3)
%11 = tail call i32 @_mm_packs_epi16(i32 %9, i32 %10)
store i32 %11, i32* %0
ret void
}