int extractPhs(unsigned int *mem, unsigned short *phs_) {
  int k;
  for (k = 0; k < 32; k++) {
    phs_[k] = (mem[k] & 0xffff);
  }
}


x86 assembly (clang, -O0):
<extractPhs>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jge    114a <extractPhs+0x4a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    $0xffff,%eax
mov    %ax,%dx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1113 <extractPhs+0x13>
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractPhs>:
movdqu (%rdi),%xmm0
pshuflw $0xe8,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
movq   %xmm0,(%rsi)
movdqu 0x10(%rdi),%xmm0
pshuflw $0xe8,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
movq   %xmm0,0x8(%rsi)
movdqu 0x20(%rdi),%xmm0
pshuflw $0xe8,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
movq   %xmm0,0x10(%rsi)
movdqu 0x30(%rdi),%xmm0
pshuflw $0xe8,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
movq   %xmm0,0x18(%rsi)
movdqu 0x40(%rdi),%xmm0
pshuflw $0xe8,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
movq   %xmm0,0x20(%rsi)
movdqu 0x50(%rdi),%xmm0
pshuflw $0xe8,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
movq   %xmm0,0x28(%rsi)
movdqu 0x60(%rdi),%xmm0
pshuflw $0xe8,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
movq   %xmm0,0x30(%rsi)
movdqu 0x70(%rdi),%xmm0
pshuflw $0xe8,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
movq   %xmm0,0x38(%rsi)
ret

LLVM IR (-O0):
define i32 @extractPhs(i32* %0, i16* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i16*
%6 = alloca i32
store i32* %0, i32** %4
store i16* %1, i16** %5
store i32 0, i32* %6
br label %7
7: ; preds = %22, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 32
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i32*, i32** %4
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = load i32, i32* %14
%16 = and i32 %15, 65535
%17 = trunc i32 %16 to i16
%18 = load i16*, i16** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i16, i16* %18, i64 %20
store i16 %17, i16* %21
br label %22
22: ; preds = %10
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %7
25: ; preds = %7
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @extractPhs(i32* nocapture %0, i16* nocapture writeonly %1) {
%3 = bitcast i32* %0 to <4 x i32>*
%4 = load <4 x i32>, <4 x i32>* %3
%5 = trunc <4 x i32> %4 to <4 x i16>
%6 = bitcast i16* %1 to <4 x i16>*
store <4 x i16> %5, <4 x i16>* %6
%7 = getelementptr inbounds i32, i32* %0, i64 4
%8 = getelementptr inbounds i16, i16* %1, i64 4
%9 = bitcast i32* %7 to <4 x i32>*
%10 = load <4 x i32>, <4 x i32>* %9
%11 = trunc <4 x i32> %10 to <4 x i16>
%12 = bitcast i16* %8 to <4 x i16>*
store <4 x i16> %11, <4 x i16>* %12
%13 = getelementptr inbounds i32, i32* %0, i64 8
%14 = getelementptr inbounds i16, i16* %1, i64 8
%15 = bitcast i32* %13 to <4 x i32>*
%16 = load <4 x i32>, <4 x i32>* %15
%17 = trunc <4 x i32> %16 to <4 x i16>
%18 = bitcast i16* %14 to <4 x i16>*
store <4 x i16> %17, <4 x i16>* %18
%19 = getelementptr inbounds i32, i32* %0, i64 12
%20 = getelementptr inbounds i16, i16* %1, i64 12
%21 = bitcast i32* %19 to <4 x i32>*
%22 = load <4 x i32>, <4 x i32>* %21
%23 = trunc <4 x i32> %22 to <4 x i16>
%24 = bitcast i16* %20 to <4 x i16>*
store <4 x i16> %23, <4 x i16>* %24
%25 = getelementptr inbounds i32, i32* %0, i64 16
%26 = getelementptr inbounds i16, i16* %1, i64 16
%27 = bitcast i32* %25 to <4 x i32>*
%28 = load <4 x i32>, <4 x i32>* %27
%29 = trunc <4 x i32> %28 to <4 x i16>
%30 = bitcast i16* %26 to <4 x i16>*
store <4 x i16> %29, <4 x i16>* %30
%31 = getelementptr inbounds i32, i32* %0, i64 20
%32 = getelementptr inbounds i16, i16* %1, i64 20
%33 = bitcast i32* %31 to <4 x i32>*
%34 = load <4 x i32>, <4 x i32>* %33
%35 = trunc <4 x i32> %34 to <4 x i16>
%36 = bitcast i16* %32 to <4 x i16>*
store <4 x i16> %35, <4 x i16>* %36
%37 = getelementptr inbounds i32, i32* %0, i64 24
%38 = getelementptr inbounds i16, i16* %1, i64 24
%39 = bitcast i32* %37 to <4 x i32>*
%40 = load <4 x i32>, <4 x i32>* %39
%41 = trunc <4 x i32> %40 to <4 x i16>
%42 = bitcast i16* %38 to <4 x i16>*
store <4 x i16> %41, <4 x i16>* %42
%43 = getelementptr inbounds i32, i32* %0, i64 28
%44 = getelementptr inbounds i16, i16* %1, i64 28
%45 = bitcast i32* %43 to <4 x i32>*
%46 = load <4 x i32>, <4 x i32>* %45
%47 = trunc <4 x i32> %46 to <4 x i16>
%48 = bitcast i16* %44 to <4 x i16>*
store <4 x i16> %47, <4 x i16>* %48
ret i32 undef
}