int lut_8bit(long v) {
  static int lut[256] = {
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4,
      2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4,
      2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
      4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5,
      3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
      4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
  int count = 0;
  int byte = 0;
  for (byte = 0; byte < sizeof(v) * 2; byte++) {
    count += lut[v & 0xff];
    v >>= 8;
  }
  return count;
}


x86 assembly (clang, -O0):
<lut_8bit>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
cmp    $0x10,%rax
jae    1160 <lut_8bit+0x60>
mov    -0x8(%rbp),%rcx
and    $0xff,%rcx
lea    0x2ef3(%rip),%rax
mov    (%rax,%rcx,4),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
sar    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    111d <lut_8bit+0x1d>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<lut_8bit>:
push   %rbx
mov    %rdi,%rcx
movzbl %cl,%esi
lea    0xef2(%rip),%rdx
movzbl %ch,%eax
mov    (%rdx,%rax,4),%eax
add    (%rdx,%rsi,4),%eax
mov    %rdi,%rsi
shr    $0xe,%rsi
and    $0x3fc,%esi
add    (%rsi,%rdx,1),%eax
mov    %rdi,%rsi
shr    $0x16,%rsi
and    $0x3fc,%esi
add    (%rsi,%rdx,1),%eax
mov    %rdi,%rsi
shr    $0x1e,%rsi
and    $0x3fc,%esi
add    (%rsi,%rdx,1),%eax
mov    %rdi,%rsi
shr    $0x26,%rsi
and    $0x3fc,%esi
add    (%rsi,%rdx,1),%eax
mov    %rdi,%rsi
shr    $0x2e,%rsi
and    $0x3fc,%esi
add    (%rsi,%rdx,1),%eax
mov    %rdi,%rbx
shr    $0x38,%rbx
add    (%rdx,%rbx,4),%eax
sar    $0x3f,%rcx
and    $0x3fc,%ecx
mov    (%rcx,%rdx,1),%ecx
add    %ecx,%eax
add    %ecx,%eax
add    %ecx,%eax
add    %ecx,%eax
add    %ecx,%eax
add    %ecx,%eax
add    %ecx,%eax
add    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@lut_8bit.lut = internal global [256 x i32] [i32 0, i32 1, i32 1, i32 2, i32 1, i32 2, i32 2, i32 3, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 5, i32 6, i32 6, i32 7, i32 6, i32 7, i32 7, i32 8]
define i32 @lut_8bit(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
store i64 %0, i64* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %4
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %4
%7 = sext i32 %6 to i64
%8 = icmp ult i64 %7, 16
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load i64, i64* %2
%11 = and i64 %10, 255
%12 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = load i32, i32* %3
%15 = add nsw i32 %14, %13
store i32 %15, i32* %3
%16 = load i64, i64* %2
%17 = ashr i64 %16, 8
store i64 %17, i64* %2
br label %18
18: ; preds = %9
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %5
21: ; preds = %5
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@lut_8bit.lut = internal unnamed_addr constant [256 x i32] [i32 0, i32 1, i32 1, i32 2, i32 1, i32 2, i32 2, i32 3, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 1, i32 2, i32 2, i32 3, i32 2, i32 3, i32 3, i32 4, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 2, i32 3, i32 3, i32 4, i32 3, i32 4, i32 4, i32 5, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 3, i32 4, i32 4, i32 5, i32 4, i32 5, i32 5, i32 6, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 4, i32 5, i32 5, i32 6, i32 5, i32 6, i32 6, i32 7, i32 5, i32 6, i32 6, i32 7, i32 6, i32 7, i32 7, i32 8]
define i32 @lut_8bit(i64 %0) {
%2 = and i64 %0, 255
%3 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %2
%4 = load i32, i32* %3
%5 = lshr i64 %0, 8
%6 = and i64 %5, 255
%7 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %6
%8 = load i32, i32* %7
%9 = add nsw i32 %8, %4
%10 = lshr i64 %0, 16
%11 = and i64 %10, 255
%12 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = add nsw i32 %13, %9
%15 = lshr i64 %0, 24
%16 = and i64 %15, 255
%17 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = add nsw i32 %18, %14
%20 = lshr i64 %0, 32
%21 = and i64 %20, 255
%22 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = add nsw i32 %23, %19
%25 = lshr i64 %0, 40
%26 = and i64 %25, 255
%27 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = add nsw i32 %28, %24
%30 = lshr i64 %0, 48
%31 = and i64 %30, 255
%32 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = add nsw i32 %33, %29
%35 = lshr i64 %0, 56
%36 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = add nsw i32 %37, %34
%39 = ashr i64 %0, 63
%40 = and i64 %39, 255
%41 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = add nsw i32 %42, %38
%44 = and i64 %39, 255
%45 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = add nsw i32 %46, %43
%48 = and i64 %39, 255
%49 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = add nsw i32 %50, %47
%52 = and i64 %39, 255
%53 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = add nsw i32 %54, %51
%56 = and i64 %39, 255
%57 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = add nsw i32 %58, %55
%60 = and i64 %39, 255
%61 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = add nsw i32 %62, %59
%64 = and i64 %39, 255
%65 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %64
%66 = load i32, i32* %65
%67 = add nsw i32 %66, %63
%68 = and i64 %39, 255
%69 = getelementptr inbounds [256 x i32], [256 x i32]* @lut_8bit.lut, i64 0, i64 %68
%70 = load i32, i32* %69
%71 = add nsw i32 %70, %67
ret i32 %71
}