int BN_num_bits_word(unsigned long l) {
  static const char bits[256] = {
      0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
      5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7,
      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
      7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
      8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
      8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
      8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
      8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
      8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  };
  {
    if (l & 0xffff0000L) {
      if (l & 0xff000000L)
        return (bits[(int)(l >> 24L)] + 24);
      else
        return (bits[(int)(l >> 16L)] + 16);
    } else {
      if (l & 0xff00L)
        return (bits[(int)(l >> 8)] + 8);
      else
        return (bits[(int)(l)]);
    }
  }
}


x86 assembly (clang, -O0):
<BN_num_bits_word>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movabs $0xffff0000,%rax
and    -0x10(%rbp),%rax
cmp    $0x0,%rax
je     117a <BN_num_bits_word+0x7a>
movabs $0xff000000,%rax
and    -0x10(%rbp),%rax
cmp    $0x0,%rax
je     1159 <BN_num_bits_word+0x59>
mov    -0x10(%rbp),%rax
shr    $0x18,%rax
movslq %eax,%rcx
lea    0xeb6(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x18,%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <BN_num_bits_word+0xc4>
mov    -0x10(%rbp),%rax
shr    $0x10,%rax
movslq %eax,%rcx
lea    0xe95(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x10,%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <BN_num_bits_word+0xc4>
mov    -0x10(%rbp),%rax
and    $0xff00,%rax
cmp    $0x0,%rax
je     11af <BN_num_bits_word+0xaf>
mov    -0x10(%rbp),%rax
shr    $0x8,%rax
movslq %eax,%rcx
lea    0xe60(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x8,%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <BN_num_bits_word+0xc4>
mov    -0x10(%rbp),%rax
movslq %eax,%rcx
lea    0xe43(%rip),%rax
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_num_bits_word>:
test   $0xffff0000,%edi
je     1126 <BN_num_bits_word+0x26>
test   $0xff000000,%edi
je     1144 <BN_num_bits_word+0x44>
shr    $0x18,%rdi
movslq %edi,%rax
lea    0xee2(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x18,%eax
ret
test   $0xff00,%edi
je     115a <BN_num_bits_word+0x5a>
shr    $0x8,%rdi
movslq %edi,%rax
lea    0xec4(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x8,%eax
ret
shr    $0x10,%rdi
movslq %edi,%rax
lea    0xeae(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x10,%eax
ret
movslq %edi,%rax
lea    0xe9c(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
ret

LLVM IR (-O0):
@BN_num_bits_word.bits = internal constant [256 x i8] c"\00\01\02\02\03\03\03\03\04\04\04\04\04\04\04\04\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08"
define i32 @BN_num_bits_word(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = and i64 %4, 4294901760
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %29
7: ; preds = %1
%8 = load i64, i64* %3
%9 = and i64 %8, 4278190080
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i64, i64* %3
%13 = lshr i64 %12, 24
%14 = trunc i64 %13 to i32
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* @BN_num_bits_word.bits, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = add nsw i32 %18, 24
store i32 %19, i32* %2
br label %49
20: ; preds = %7
%21 = load i64, i64* %3
%22 = lshr i64 %21, 16
%23 = trunc i64 %22 to i32
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [256 x i8], [256 x i8]* @BN_num_bits_word.bits, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = add nsw i32 %27, 16
store i32 %28, i32* %2
br label %49
29: ; preds = %1
%30 = load i64, i64* %3
%31 = and i64 %30, 65280
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i64, i64* %3
%35 = lshr i64 %34, 8
%36 = trunc i64 %35 to i32
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [256 x i8], [256 x i8]* @BN_num_bits_word.bits, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = add nsw i32 %40, 8
store i32 %41, i32* %2
br label %49
42: ; preds = %29
%43 = load i64, i64* %3
%44 = trunc i64 %43 to i32
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [256 x i8], [256 x i8]* @BN_num_bits_word.bits, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
store i32 %48, i32* %2
br label %49
49: ; preds = %42, %33, %20, %11
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@BN_num_bits_word.bits = internal unnamed_addr constant [256 x i8] c"\00\01\02\02\03\03\03\03\04\04\04\04\04\04\04\04\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08\08"
define i32 @BN_num_bits_word(i64 %0) {
%2 = and i64 %0, 4294901760
%3 = icmp eq i64 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = and i64 %0, 4278190080
%6 = icmp eq i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = shl i64 %0, 8
%9 = ashr i64 %8, 32
%10 = getelementptr inbounds [256 x i8], [256 x i8]* @BN_num_bits_word.bits, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = add nsw i32 %12, 24
br label %37
14: ; preds = %4
%15 = shl i64 %0, 16
%16 = ashr i64 %15, 32
%17 = getelementptr inbounds [256 x i8], [256 x i8]* @BN_num_bits_word.bits, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = add nsw i32 %19, 16
br label %37
21: ; preds = %1
%22 = and i64 %0, 65280
%23 = icmp eq i64 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %21
%25 = shl i64 %0, 24
%26 = ashr i64 %25, 32
%27 = getelementptr inbounds [256 x i8], [256 x i8]* @BN_num_bits_word.bits, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = add nsw i32 %29, 8
br label %37
31: ; preds = %21
%32 = shl i64 %0, 32
%33 = ashr exact i64 %32, 32
%34 = getelementptr inbounds [256 x i8], [256 x i8]* @BN_num_bits_word.bits, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
br label %37
37: ; preds = %31, %24, %14, %7
%38 = phi i32 [ %13, %7 ], [ %20, %14 ], [ %30, %24 ], [ %36, %31 ]
ret i32 %38
}