#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint64_t;

/* Variables and functions */
int UINT64_C(int);
uint8_t hw(uint64_t u) {
  u = (u & UINT64_C(0x5555555555555555)) +
      ((u & UINT64_C(0xaaaaaaaaaaaaaaaa)) >> 1);
  u = (u & UINT64_C(0x3333333333333333)) +
      ((u & UINT64_C(0xcccccccccccccccc)) >> 2);
  u += (u >> 4);
  u &= UINT64_C(0x0f0f0f0f0f0f0f0f);
  u += (u >> 8);
  u += (u >> 16);
  u += (u >> 32);
  u &= UINT64_C(0x7f);
  return (uint8_t)u;
}


x86 assembly (clang, -O0):
<hw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x55555555,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0xaaaaaaaa,%edi
call   1030 <UINT64_C@plt>
mov    -0x18(%rbp),%ecx
mov    %eax,%edx
mov    -0x14(%rbp),%eax
and    %edx,%ecx
sar    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x33333333,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0xcccccccc,%edi
call   1030 <UINT64_C@plt>
mov    -0xc(%rbp),%ecx
mov    %eax,%edx
mov    -0x8(%rbp),%eax
and    %edx,%ecx
sar    $0x2,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x4,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    $0xf0f0f0f,%edi
call   1030 <UINT64_C@plt>
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    $0x7f,%edi
call   1030 <UINT64_C@plt>
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hw>:
push   %rax
mov    $0x55555555,%edi
call   1030 <UINT64_C@plt>
mov    $0xaaaaaaaa,%edi
call   1030 <UINT64_C@plt>
mov    $0x33333333,%edi
call   1030 <UINT64_C@plt>
mov    $0xcccccccc,%edi
call   1030 <UINT64_C@plt>
mov    $0xf0f0f0f,%edi
call   1030 <UINT64_C@plt>
mov    $0x7f,%edi
pop    %rax
jmp    1030 <UINT64_C@plt>

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

LLVM IR (-O2):
define i32 @hw(i32 %0) {
%2 = tail call i32 @UINT64_C(i32 1431655765)
%3 = tail call i32 @UINT64_C(i32 -1431655766)
%4 = tail call i32 @UINT64_C(i32 858993459)
%5 = tail call i32 @UINT64_C(i32 -858993460)
%6 = tail call i32 @UINT64_C(i32 252645135)
%7 = tail call i32 @UINT64_C(i32 127)
ret i32 poison
}