#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
unsigned int __native_popcnt(unsigned int x) {
  x -= ((x >> 1) & 0x55555555U);
  x = (((x >> 2) & 0x33333333U) + (x & 0x33333333U));
  x = (((x >> 4) + x) & 0x0F0F0F0FU);
  x += (x >> 8);
  x += (x >> 16);
  x = x & 0x0000003FU;
  assert(x >= 0 && x <= 32);
  return x;
}


x86 assembly (clang, -O0):
<__native_popcnt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
shr    $0x1,%ecx
and    $0x55555555,%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x2,%eax
and    $0x33333333,%eax
mov    -0x4(%rbp),%ecx
and    $0x33333333,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
add    -0x4(%rbp),%eax
and    $0xf0f0f0f,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x10,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3f,%eax
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x5(%rbp)
jb     1193 <__native_popcnt+0x83>
cmpl   $0x20,-0x4(%rbp)
setbe  %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__native_popcnt>:
push   %rbx
mov    %edi,%eax
shr    %eax
and    $0x55555555,%eax
sub    %eax,%edi
mov    %edi,%eax
shr    $0x2,%eax
and    $0x33333333,%eax
and    $0x33333333,%edi
add    %eax,%edi
mov    %edi,%eax
shr    $0x4,%eax
add    %edi,%eax
and    $0xf0f0f0f,%eax
mov    %eax,%ecx
shr    $0x8,%ecx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x10,%eax
add    %ecx,%eax
movzbl %al,%ebx
xor    %edi,%edi
cmp    $0x21,%ebx
setb   %dil
call   1030 <assert@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @__native_popcnt(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = lshr i32 %3, 1
%5 = and i32 %4, 1431655765
%6 = load i32, i32* %2
%7 = sub i32 %6, %5
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = lshr i32 %8, 2
%10 = and i32 %9, 858993459
%11 = load i32, i32* %2
%12 = and i32 %11, 858993459
%13 = add i32 %10, %12
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = lshr i32 %14, 4
%16 = load i32, i32* %2
%17 = add i32 %15, %16
%18 = and i32 %17, 252645135
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = lshr i32 %19, 8
%21 = load i32, i32* %2
%22 = add i32 %21, %20
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = lshr i32 %23, 16
%25 = load i32, i32* %2
%26 = add i32 %25, %24
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = and i32 %27, 63
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = icmp uge i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %1
%32 = load i32, i32* %2
%33 = icmp ule i32 %32, 32
br label %34
34: ; preds = %31, %1
%35 = phi i1 [ false, %1 ], [ %33, %31 ]
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @__native_popcnt(i32 %0) {
%2 = lshr i32 %0, 1
%3 = and i32 %2, 1431655765
%4 = sub i32 %0, %3
%5 = lshr i32 %4, 2
%6 = and i32 %5, 858993459
%7 = and i32 %4, 858993459
%8 = add nuw nsw i32 %6, %7
%9 = lshr i32 %8, 4
%10 = add nuw nsw i32 %9, %8
%11 = and i32 %10, 252645135
%12 = lshr i32 %11, 8
%13 = add nuw nsw i32 %12, %11
%14 = lshr i32 %13, 16
%15 = add nuw nsw i32 %14, %13
%16 = and i32 %15, 63
%17 = icmp ult i32 %16, 33
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
ret i32 %16
}