#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 _mm_extract_epi16(int /*<<< orphan*/, int);
int /*<<< orphan*/ abort();
void sse2_test(void) {
  union {
    __m128i x;
    int i[4];
    short s[8];
  } val1;
  int res[8], masks[8];
  int i;
  val1.i[0] = 0x04030201;
  val1.i[1] = 0x08070605;
  val1.i[2] = 0x0C0B0A09;
  val1.i[3] = 0x100F0E0D;
  res[0] = _mm_extract_epi16(val1.x, 0);
  res[1] = _mm_extract_epi16(val1.x, 1);
  res[2] = _mm_extract_epi16(val1.x, 2);
  res[3] = _mm_extract_epi16(val1.x, 3);
  res[4] = _mm_extract_epi16(val1.x, 4);
  res[5] = _mm_extract_epi16(val1.x, 5);
  res[6] = _mm_extract_epi16(val1.x, 6);
  res[7] = _mm_extract_epi16(val1.x, 7);
  masks[0] = 0;
  masks[1] = 1;
  masks[2] = 2;
  masks[3] = 3;
  masks[4] = 4;
  masks[5] = 5;
  masks[6] = 6;
  masks[7] = 7;
  for (i = 0; i < 8; i++)
    if (res[i] != val1.s[masks[i]])
      abort();
}


x86 assembly (clang, -O0):
<sse2_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x4030201,-0x10(%rbp)
movl   $0x8070605,-0xc(%rbp)
movl   $0xc0b0a09,-0x8(%rbp)
movl   $0x100f0e0d,-0x4(%rbp)
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x2,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x3,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x4,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x5,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x6,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x7,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x1,-0x4c(%rbp)
movl   $0x2,-0x48(%rbp)
movl   $0x3,-0x44(%rbp)
movl   $0x4,-0x40(%rbp)
movl   $0x5,-0x3c(%rbp)
movl   $0x6,-0x38(%rbp)
movl   $0x7,-0x34(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x8,-0x54(%rbp)
jge    1242 <sse2_test+0x122>
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
movslq -0x54(%rbp),%rcx
movslq -0x50(%rbp,%rcx,4),%rcx
movswl -0x10(%rbp,%rcx,2),%ecx
cmp    %ecx,%eax
je     122f <sse2_test+0x10f>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1234 <sse2_test+0x114>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1200 <sse2_test+0xe0>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sse2_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x4030201,%edi
xor    %esi,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,0x4(%rsp)
mov    $0x4030201,%edi
mov    $0x1,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,%r15d
mov    $0x4030201,%edi
mov    $0x2,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,%r12d
mov    $0x4030201,%edi
mov    $0x3,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,%r13d
mov    $0x4030201,%edi
mov    $0x4,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,%ebx
mov    $0x4030201,%edi
mov    $0x5,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,%ebp
mov    $0x4030201,%edi
mov    $0x6,%esi
call   1040 <_mm_extract_epi16@plt>
mov    %eax,%r14d
mov    $0x4030201,%edi
mov    $0x7,%esi
call   1040 <_mm_extract_epi16@plt>
cmpl   $0x201,0x4(%rsp)
jne    1208 <sse2_test+0xe8>
cmp    $0x403,%r15d
jne    1208 <sse2_test+0xe8>
cmp    $0x605,%r12d
jne    1208 <sse2_test+0xe8>
cmp    $0x807,%r13d
jne    1208 <sse2_test+0xe8>
cmp    $0xa09,%ebx
jne    1208 <sse2_test+0xe8>
cmp    $0xc0b,%ebp
jne    1208 <sse2_test+0xe8>
cmp    $0xe0d,%r14d
jne    1208 <sse2_test+0xe8>
cmp    $0x100f,%eax
jne    1208 <sse2_test+0xe8>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%union.anon = type { [4 x i32] }
define void @sse2_test() {
%1 = alloca %union.anon
%2 = alloca [8 x i32]
%3 = alloca [8 x i32]
%4 = alloca i32
%5 = bitcast %union.anon* %1 to [4 x i32]*
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
store i32 67305985, i32* %6
%7 = bitcast %union.anon* %1 to [4 x i32]*
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 1
store i32 134678021, i32* %8
%9 = bitcast %union.anon* %1 to [4 x i32]*
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 2
store i32 202050057, i32* %10
%11 = bitcast %union.anon* %1 to [4 x i32]*
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
store i32 269422093, i32* %12
%13 = bitcast %union.anon* %1 to i32*
%14 = load i32, i32* %13
%15 = call i32 @_mm_extract_epi16(i32 %14, i32 0)
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
store i32 %15, i32* %16
%17 = bitcast %union.anon* %1 to i32*
%18 = load i32, i32* %17
%19 = call i32 @_mm_extract_epi16(i32 %18, i32 1)
%20 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 1
store i32 %19, i32* %20
%21 = bitcast %union.anon* %1 to i32*
%22 = load i32, i32* %21
%23 = call i32 @_mm_extract_epi16(i32 %22, i32 2)
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 2
store i32 %23, i32* %24
%25 = bitcast %union.anon* %1 to i32*
%26 = load i32, i32* %25
%27 = call i32 @_mm_extract_epi16(i32 %26, i32 3)
%28 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 3
store i32 %27, i32* %28
%29 = bitcast %union.anon* %1 to i32*
%30 = load i32, i32* %29
%31 = call i32 @_mm_extract_epi16(i32 %30, i32 4)
%32 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 4
store i32 %31, i32* %32
%33 = bitcast %union.anon* %1 to i32*
%34 = load i32, i32* %33
%35 = call i32 @_mm_extract_epi16(i32 %34, i32 5)
%36 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 5
store i32 %35, i32* %36
%37 = bitcast %union.anon* %1 to i32*
%38 = load i32, i32* %37
%39 = call i32 @_mm_extract_epi16(i32 %38, i32 6)
%40 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 6
store i32 %39, i32* %40
%41 = bitcast %union.anon* %1 to i32*
%42 = load i32, i32* %41
%43 = call i32 @_mm_extract_epi16(i32 %42, i32 7)
%44 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 7
store i32 %43, i32* %44
%45 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
store i32 0, i32* %45
%46 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 1
store i32 1, i32* %46
%47 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 2
store i32 2, i32* %47
%48 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 3
store i32 3, i32* %48
%49 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 4
store i32 4, i32* %49
%50 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 5
store i32 5, i32* %50
%51 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 6
store i32 6, i32* %51
%52 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 7
store i32 7, i32* %52
store i32 0, i32* %4
br label %53
53: ; preds = %74, %0
%54 = load i32, i32* %4
%55 = icmp slt i32 %54, 8
br i1 %55, label %56, label %77
56: ; preds = %53
%57 = load i32, i32* %4
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = bitcast %union.anon* %1 to [8 x i16]*
%62 = load i32, i32* %4
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [8 x i16], [8 x i16]* %61, i64 0, i64 %66
%68 = load i16, i16* %67
%69 = sext i16 %68 to i32
%70 = icmp ne i32 %60, %69
br i1 %70, label %71, label %73
71: ; preds = %56
%72 = call i32 (...) @abort()
unreachable
73: ; preds = %56
br label %74
74: ; preds = %73
%75 = load i32, i32* %4
%76 = add nsw i32 %75, 1
store i32 %76, i32* %4
br label %53
77: ; preds = %53
ret void
}

LLVM IR (-O2):
define void @sse2_test() {
%1 = tail call i32 @_mm_extract_epi16(i32 67305985, i32 0)
%2 = tail call i32 @_mm_extract_epi16(i32 67305985, i32 1)
%3 = tail call i32 @_mm_extract_epi16(i32 67305985, i32 2)
%4 = tail call i32 @_mm_extract_epi16(i32 67305985, i32 3)
%5 = tail call i32 @_mm_extract_epi16(i32 67305985, i32 4)
%6 = tail call i32 @_mm_extract_epi16(i32 67305985, i32 5)
%7 = tail call i32 @_mm_extract_epi16(i32 67305985, i32 6)
%8 = tail call i32 @_mm_extract_epi16(i32 67305985, i32 7)
%9 = icmp eq i32 %1, 513
%10 = icmp eq i32 %2, 1027
%11 = select i1 %9, i1 %10, i1 false
%12 = icmp eq i32 %3, 1541
%13 = select i1 %11, i1 %12, i1 false
%14 = icmp eq i32 %4, 2055
%15 = select i1 %13, i1 %14, i1 false
%16 = icmp eq i32 %5, 2569
%17 = select i1 %15, i1 %16, i1 false
%18 = icmp eq i32 %6, 3083
%19 = select i1 %17, i1 %18, i1 false
%20 = icmp eq i32 %7, 3597
%21 = select i1 %19, i1 %20, i1 false
%22 = icmp eq i32 %8, 4111
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %24, label %25
24: ; preds = %0
ret void
25: ; preds = %0
%26 = tail call i32 (...) @abort()
unreachable
}