#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_slow(unsigned int x) {
  x = (x & 0x55555555UL) + ((x >> 1) & 0x55555555UL);
  x = (x & 0x33333333UL) + ((x >> 2) & 0x33333333UL);
  x = (x & 0x0F0F0F0FUL) + ((x >> 4) & 0x0F0F0F0FUL);
  x = (x & 0x00FF00FFUL) + ((x >> 8) & 0x00FF00FFUL);
  x = (x & 0x0000FFFFUL) + ((x >> 16) & 0x0000FFFFUL);
  assert(x >= 0 && x <= 32);
  return x;
}


x86 assembly (clang, -O0):
<__native_popcnt_slow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x55555555,%rax
mov    -0x4(%rbp),%ecx
shr    $0x1,%ecx
mov    %ecx,%ecx
and    $0x55555555,%rcx
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x33333333,%rax
mov    -0x4(%rbp),%ecx
shr    $0x2,%ecx
mov    %ecx,%ecx
and    $0x33333333,%rcx
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf0f0f0f,%rax
mov    -0x4(%rbp),%ecx
shr    $0x4,%ecx
mov    %ecx,%ecx
and    $0xf0f0f0f,%rcx
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff00ff,%rax
mov    -0x4(%rbp),%ecx
shr    $0x8,%ecx
mov    %ecx,%ecx
and    $0xff00ff,%rcx
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffff,%rax
mov    -0x4(%rbp),%ecx
shr    $0x10,%ecx
mov    %ecx,%ecx
and    $0xffff,%rcx
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x5(%rbp)
jb     11ca <__native_popcnt_slow+0xba>
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_slow>:
push   %rbx
mov    %edi,%ebx
and    $0x55555555,%ebx
shr    %edi
and    $0x55555555,%edi
add    %edi,%ebx
mov    %ebx,%eax
and    $0x33333333,%eax
shr    $0x2,%ebx
and    $0x33333333,%ebx
add    %eax,%ebx
mov    %ebx,%eax
and    $0x7070707,%eax
shr    $0x4,%ebx
and    $0x7070707,%ebx
add    %eax,%ebx
mov    %ebx,%eax
and    $0xf000f,%eax
shr    $0x8,%ebx
and    $0xf000f,%ebx
add    %eax,%ebx
movzwl %bx,%eax
shr    $0x10,%ebx
add    %eax,%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_slow(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = zext i32 %3 to i64
%5 = and i64 %4, 1431655765
%6 = load i32, i32* %2
%7 = lshr i32 %6, 1
%8 = zext i32 %7 to i64
%9 = and i64 %8, 1431655765
%10 = add i64 %5, %9
%11 = trunc i64 %10 to i32
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = and i64 %13, 858993459
%15 = load i32, i32* %2
%16 = lshr i32 %15, 2
%17 = zext i32 %16 to i64
%18 = and i64 %17, 858993459
%19 = add i64 %14, %18
%20 = trunc i64 %19 to i32
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = zext i32 %21 to i64
%23 = and i64 %22, 252645135
%24 = load i32, i32* %2
%25 = lshr i32 %24, 4
%26 = zext i32 %25 to i64
%27 = and i64 %26, 252645135
%28 = add i64 %23, %27
%29 = trunc i64 %28 to i32
store i32 %29, i32* %2
%30 = load i32, i32* %2
%31 = zext i32 %30 to i64
%32 = and i64 %31, 16711935
%33 = load i32, i32* %2
%34 = lshr i32 %33, 8
%35 = zext i32 %34 to i64
%36 = and i64 %35, 16711935
%37 = add i64 %32, %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %2
%39 = load i32, i32* %2
%40 = zext i32 %39 to i64
%41 = and i64 %40, 65535
%42 = load i32, i32* %2
%43 = lshr i32 %42, 16
%44 = zext i32 %43 to i64
%45 = and i64 %44, 65535
%46 = add i64 %41, %45
%47 = trunc i64 %46 to i32
store i32 %47, i32* %2
%48 = load i32, i32* %2
%49 = icmp uge i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %1
%51 = load i32, i32* %2
%52 = icmp ule i32 %51, 32
br label %53
53: ; preds = %50, %1
%54 = phi i1 [ false, %1 ], [ %52, %50 ]
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
define i32 @__native_popcnt_slow(i32 %0) {
%2 = and i32 %0, 1431655765
%3 = lshr i32 %0, 1
%4 = and i32 %3, 1431655765
%5 = add nuw i32 %4, %2
%6 = and i32 %5, 858993459
%7 = lshr i32 %5, 2
%8 = and i32 %7, 858993459
%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
%21 = icmp ult i32 %20, 33
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
ret i32 %20
}