int countingBits1(int value) {
  int tmp = value;
  tmp = (tmp & 0x55555555) + ((tmp >> 1) & 0x55555555);
  tmp = (tmp & 0x33333333) + ((tmp >> 2) & 0x33333333);
  tmp = (tmp & 0x0F0F0F0F) + ((tmp >> 4) & 0x0F0F0F0F);
  tmp = (tmp & 0x00FF00FF) + ((tmp >> 8) & 0x00FF00FF);
  tmp = (tmp & 0x0000FFFF) + ((tmp >> 16) & 0x0000FFFF);
  return tmp;
}


x86 assembly (clang, -O0):
<countingBits1>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x55555555,%eax
mov    -0x8(%rbp),%ecx
sar    $0x1,%ecx
and    $0x55555555,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x33333333,%eax
mov    -0x8(%rbp),%ecx
sar    $0x2,%ecx
and    $0x33333333,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf0f0f0f,%eax
mov    -0x8(%rbp),%ecx
sar    $0x4,%ecx
and    $0xf0f0f0f,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff00ff,%eax
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff00ff,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xffff,%eax
mov    -0x8(%rbp),%ecx
sar    $0x10,%ecx
and    $0xffff,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<countingBits1>:
mov    %edi,%eax
and    $0x55555555,%eax
shr    %edi
and    $0x55555555,%edi
add    %edi,%eax
mov    %eax,%ecx
and    $0x33333333,%ecx
shr    $0x2,%eax
and    $0x13333333,%eax
add    %ecx,%eax
mov    %eax,%ecx
and    $0x7070707,%ecx
shr    $0x4,%eax
and    $0x7070707,%eax
add    %ecx,%eax
mov    %eax,%ecx
and    $0xf000f,%ecx
shr    $0x8,%eax
and    $0xf000f,%eax
add    %ecx,%eax
movzwl %ax,%ecx
shr    $0x10,%eax
add    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @countingBits1(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = and i32 %5, 1431655765
%7 = load i32, i32* %3
%8 = ashr i32 %7, 1
%9 = and i32 %8, 1431655765
%10 = add nsw i32 %6, %9
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = and i32 %11, 858993459
%13 = load i32, i32* %3
%14 = ashr i32 %13, 2
%15 = and i32 %14, 858993459
%16 = add nsw i32 %12, %15
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = and i32 %17, 252645135
%19 = load i32, i32* %3
%20 = ashr i32 %19, 4
%21 = and i32 %20, 252645135
%22 = add nsw i32 %18, %21
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = and i32 %23, 16711935
%25 = load i32, i32* %3
%26 = ashr i32 %25, 8
%27 = and i32 %26, 16711935
%28 = add nsw i32 %24, %27
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = and i32 %29, 65535
%31 = load i32, i32* %3
%32 = ashr i32 %31, 16
%33 = and i32 %32, 65535
%34 = add nsw i32 %30, %33
store i32 %34, i32* %3
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @countingBits1(i32 %0) {
%2 = and i32 %0, 1431655765
%3 = lshr i32 %0, 1
%4 = and i32 %3, 1431655765
%5 = add nuw nsw i32 %4, %2
%6 = and i32 %5, 858993459
%7 = lshr i32 %5, 2
%8 = and i32 %7, 322122547
%9 = add nuw nsw i32 %8, %6
%10 = and i32 %9, 117901063
%11 = lshr i32 %9, 4
%12 = and i32 %11, 117901063
%13 = add nuw nsw i32 %12, %10
%14 = and i32 %13, 983055
%15 = lshr i32 %13, 8
%16 = and i32 %15, 983055
%17 = add nuw nsw i32 %16, %14
%18 = and i32 %17, 31
%19 = lshr i32 %17, 16
%20 = add nuw nsw i32 %18, %19
ret i32 %20
}