int main() {
  volatile int a = 0x00000000;
  if (__builtin_popcount(a) != 0) {
    return 1;
  }
  volatile int b = 0x12345678;
  if (__builtin_popcount(b) != 13) {
    return 1;
  }
  volatile int c = 0xFFFFFFFF;
  if (__builtin_popcount(c) != 32) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
mov    %ecx,%eax
shr    %eax
and    $0x55555555,%eax
sub    %eax,%ecx
mov    %ecx,%eax
and    $0x33333333,%eax
shr    $0x2,%ecx
and    $0x33333333,%ecx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x4,%ecx
add    %ecx,%eax
and    $0xf0f0f0f,%eax
imul   $0x1010101,%eax,%eax
shr    $0x18,%eax
cmp    $0x0,%eax
je     115c <main+0x5c>
movl   $0x1,-0x4(%rbp)
jmp    1205 <main+0x105>
movl   $0x12345678,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
mov    %ecx,%eax
shr    %eax
and    $0x55555555,%eax
sub    %eax,%ecx
mov    %ecx,%eax
and    $0x33333333,%eax
shr    $0x2,%ecx
and    $0x33333333,%ecx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x4,%ecx
add    %ecx,%eax
and    $0xf0f0f0f,%eax
imul   $0x1010101,%eax,%eax
shr    $0x18,%eax
cmp    $0xd,%eax
je     11ad <main+0xad>
movl   $0x1,-0x4(%rbp)
jmp    1205 <main+0x105>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    %ecx,%eax
shr    %eax
and    $0x55555555,%eax
sub    %eax,%ecx
mov    %ecx,%eax
and    $0x33333333,%eax
shr    $0x2,%ecx
and    $0x33333333,%ecx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x4,%ecx
add    %ecx,%eax
and    $0xf0f0f0f,%eax
imul   $0x1010101,%eax,%eax
shr    $0x18,%eax
cmp    $0x20,%eax
je     11fe <main+0xfe>
movl   $0x1,-0x4(%rbp)
jmp    1205 <main+0x105>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
movl   $0x0,-0x4(%rsp)
mov    $0x1,%eax
cmpl   $0x0,-0x4(%rsp)
je     1115 <main+0x15>
ret
movl   $0x12345678,-0x8(%rsp)
12
mov    -0x8(%rsp),%eax
mov    %eax,%ecx
shr    %ecx
and    $0x55555555,%ecx
sub    %ecx,%eax
mov    %eax,%ecx
and    $0x33333333,%ecx
shr    $0x2,%eax
and    $0x33333333,%eax
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x4,%ecx
add    %eax,%ecx
and    $0xf0f0f0f,%ecx
imul   $0x1010101,%ecx,%ecx
shr    $0x18,%ecx
mov    $0x1,%eax
cmp    $0xd,%ecx
jne    1114 <main+0x14>
movl   $0xffffffff,-0xc(%rsp)
ff
mov    -0xc(%rsp),%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
setne  %al
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store volatile i32 0, i32* %2
%5 = load volatile i32, i32* %2
%6 = call i32 @llvm.ctpop.i32(i32 %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %20
9: ; preds = %0
store volatile i32 305419896, i32* %3
%10 = load volatile i32, i32* %3
%11 = call i32 @llvm.ctpop.i32(i32 %10)
%12 = icmp ne i32 %11, 13
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 1, i32* %1
br label %20
14: ; preds = %9
store volatile i32 -1, i32* %4
%15 = load volatile i32, i32* %4
%16 = call i32 @llvm.ctpop.i32(i32 %15)
%17 = icmp ne i32 %16, 32
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 1, i32* %1
br label %20
19: ; preds = %14
store i32 0, i32* %1
br label %20
20: ; preds = %19, %18, %13, %8
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
store volatile i32 0, i32* %1
%5 = load volatile i32, i32* %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %0
%8 = bitcast i32* %2 to i8*
store volatile i32 305419896, i32* %2
%9 = load volatile i32, i32* %2
%10 = tail call i32 @llvm.ctpop.i32(i32 %9)
%11 = icmp eq i32 %10, 13
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = bitcast i32* %3 to i8*
store volatile i32 -1, i32* %3
%14 = load volatile i32, i32* %3
%15 = icmp ne i32 %14, -1
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %7, %12
%18 = phi i32 [ %16, %12 ], [ 1, %7 ]
br label %19
19: ; preds = %0, %17
%20 = phi i32 [ %18, %17 ], [ 1, %0 ]
ret i32 %20
}