int popcount5(unsigned *array) {
  int i, res, count = 0;
  static const int SSE_mask[] __attribute__((aligned(16))) = {
      0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f};
  static const int SSE_LUTb[] __attribute__((aligned(16))) = {
      0x02010100, 0x03020201, 0x03020201, 0x04030302};
  for (i = 0; i < (1 << 20); i += 4) {
    asm("movdqa		%[x], %%xmm0		\n"
        "			 movdqa    	%%xmm0, %%xmm1		\n"
        "			 psrlw		$4, %%xmm1		"
        "	\n"
        "			 pand      	%%xmm6, %%xmm0		\n"
        "			 pand      	%%xmm6, %%xmm1		\n"
        "			 movdqa    	%%xmm7, %%xmm2		\n"
        "			 movdqa    	%%xmm7, %%xmm3		\n"
        "			 pshufb    	%%xmm0, %%xmm2		\n"
        "			 pshufb    	%%xmm1, %%xmm3		\n"
        "			 paddb     	%%xmm2, %%xmm4		\n"
        "			 paddb     	%%xmm3, %%xmm4		\n"
        "			 pxor		%%xmm0, %%xmm0		\n"
        "			 psadbw		%%xmm0, %%xmm4		\n"
        "			 paddd		%%xmm4, %%xmm5		\n"
        "			 movhlps   	%%xmm5, %%xmm0		\n"
        "			 paddd     	%%xmm5, %%xmm0		\n"
        "			 movd      	%%xmm0, %[res]		\n"
        : [res] "=m"(res)
        : [x] "m"(array[i]), [m] "m"(SSE_mask[0]), [l] "m"(SSE_LUTb[0]));
    count += res;
  }
  return count;
}


x86 assembly (clang, -O0):
<popcount5>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x100000,-0xc(%rbp)
jge    1190 <popcount5+0x90>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movdqa (%rax),%xmm0
movdqa %xmm0,%xmm1
psrlw  $0x4,%xmm1
pand   %xmm6,%xmm0
pand   %xmm6,%xmm1
movdqa %xmm7,%xmm2
movdqa %xmm7,%xmm3
pshufb %xmm0,%xmm2
pshufb %xmm1,%xmm3
paddb  %xmm2,%xmm4
paddb  %xmm3,%xmm4
pxor   %xmm0,%xmm0
psadbw %xmm0,%xmm4
paddd  %xmm4,%xmm5
movhlps %xmm5,%xmm0
paddd  %xmm5,%xmm0
movd   %xmm0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    1116 <popcount5+0x16>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<popcount5>:
xor    %eax,%eax
mov    $0xfffffffffffffffc,%rcx
nopl   0x0(%rax)
movdqa (%rdi),%xmm0
movdqa %xmm0,%xmm1
psrlw  $0x4,%xmm1
pand   %xmm6,%xmm0
pand   %xmm6,%xmm1
movdqa %xmm7,%xmm2
movdqa %xmm7,%xmm3
pshufb %xmm0,%xmm2
pshufb %xmm1,%xmm3
paddb  %xmm2,%xmm4
paddb  %xmm3,%xmm4
pxor   %xmm0,%xmm0
psadbw %xmm0,%xmm4
paddd  %xmm4,%xmm5
movhlps %xmm5,%xmm0
paddd  %xmm5,%xmm0
movd   %xmm0,-0x4(%rsp)
add    -0x4(%rsp),%eax
add    $0x4,%rcx
add    $0x10,%rdi
cmp    $0xffffc,%rcx
jb     1110 <popcount5+0x10>
ret

LLVM IR (-O0):
@popcount5.SSE_mask = internal constant [4 x i32] [i32 252645135, i32 252645135, i32 252645135, i32 252645135]
@popcount5.SSE_LUTb = internal constant [4 x i32] [i32 33620224, i32 50463233, i32 50463233, i32 67306242]
define i32 @popcount5(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %5
store i32 0, i32* %3
br label %6
6: ; preds = %17, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1048576
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = load i32*, i32** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %10, i64 %12
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = add nsw i32 %15, %14
store i32 %16, i32* %5
br label %17
17: ; preds = %9
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 4
store i32 %19, i32* %3
br label %6
20: ; preds = %6
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
@popcount5.SSE_mask = internal constant [4 x i32] [i32 252645135, i32 252645135, i32 252645135, i32 252645135]
@popcount5.SSE_LUTb = internal constant [4 x i32] [i32 33620224, i32 50463233, i32 50463233, i32 67306242]
define i32 @popcount5(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %1, %4
%5 = phi i64 [ 0, %1 ], [ %10, %4 ]
%6 = phi i32 [ 0, %1 ], [ %9, %4 ]
%7 = getelementptr inbounds i32, i32* %0, i64 %5
%8 = load i32, i32* %2
%9 = add nsw i32 %8, %6
%10 = add nuw nsw i64 %5, 4
%11 = icmp ult i64 %5, 1048572
br i1 %11, label %4, label %12
12: ; preds = %4
ret i32 %9
}