int l2(unsigned long x) {
  static char table[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 (x >> 16)
    if (x >> 24)
      return table[x >> 24] + 24;
    else
      return table[x >> 16] + 16;
  else if (x >> 8)
    return table[x >> 8] + 8;
  else
    return table[x];
}


x86 assembly (clang, -O0):
<l2>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x10,%rax
cmp    $0x0,%rax
je     1168 <l2+0x68>
mov    -0x10(%rbp),%rax
shr    $0x18,%rax
cmp    $0x0,%rax
je     114a <l2+0x4a>
mov    -0x10(%rbp),%rcx
shr    $0x18,%rcx
lea    0x2ef5(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x18,%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <l2+0xaa>
mov    -0x10(%rbp),%rcx
shr    $0x10,%rcx
lea    0x2ed7(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x10,%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <l2+0xaa>
mov    -0x10(%rbp),%rax
shr    $0x8,%rax
cmp    $0x0,%rax
je     1198 <l2+0x98>
mov    -0x10(%rbp),%rcx
shr    $0x8,%rcx
lea    0x2ea7(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x8,%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <l2+0xaa>
mov    -0x10(%rbp),%rcx
lea    0x2e8d(%rip),%rax
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<l2>:
cmp    $0x10000,%rdi
jae    111e <l2+0x1e>
cmp    $0x100,%rdi
jae    113a <l2+0x3a>
lea    0xee7(%rip),%rax
movsbl (%rdi,%rax,1),%eax
ret
cmp    $0x1000000,%rdi
jae    114d <l2+0x4d>
shr    $0x10,%rdi
lea    0xece(%rip),%rax
movsbl (%rdi,%rax,1),%eax
add    $0x10,%eax
ret
shr    $0x8,%rdi
lea    0xebb(%rip),%rax
movsbl (%rdi,%rax,1),%eax
add    $0x8,%eax
ret
shr    $0x18,%rdi
lea    0xea8(%rip),%rax
movsbl (%rdi,%rax,1),%eax
add    $0x18,%eax
ret

LLVM IR (-O0):
@l2.table = internal global [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 @l2(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = lshr i64 %4, 16
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %25
7: ; preds = %1
%8 = load i64, i64* %3
%9 = lshr i64 %8, 24
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load i64, i64* %3
%13 = lshr i64 %12, 24
%14 = getelementptr inbounds [256 x i8], [256 x i8]* @l2.table, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = add nsw i32 %16, 24
store i32 %17, i32* %2
br label %41
18: ; preds = %7
%19 = load i64, i64* %3
%20 = lshr i64 %19, 16
%21 = getelementptr inbounds [256 x i8], [256 x i8]* @l2.table, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = add nsw i32 %23, 16
store i32 %24, i32* %2
br label %41
25: ; preds = %1
%26 = load i64, i64* %3
%27 = lshr i64 %26, 8
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load i64, i64* %3
%31 = lshr i64 %30, 8
%32 = getelementptr inbounds [256 x i8], [256 x i8]* @l2.table, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = add nsw i32 %34, 8
store i32 %35, i32* %2
br label %41
36: ; preds = %25
%37 = load i64, i64* %3
%38 = getelementptr inbounds [256 x i8], [256 x i8]* @l2.table, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
store i32 %40, i32* %2
br label %41
41: ; preds = %36, %29, %18, %11
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@l2.table = 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 @l2(i64 %0) {
%2 = lshr i64 %0, 16
%3 = icmp ult i64 %0, 65536
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = icmp ult i64 %0, 16777216
br i1 %5, label %12, label %6
6: ; preds = %4
%7 = lshr i64 %0, 24
%8 = getelementptr inbounds [256 x i8], [256 x i8]* @l2.table, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = add nsw i32 %10, 24
br label %29
12: ; preds = %4
%13 = getelementptr inbounds [256 x i8], [256 x i8]* @l2.table, i64 0, i64 %2
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = add nsw i32 %15, 16
br label %29
17: ; preds = %1
%18 = icmp ult i64 %0, 256
br i1 %18, label %25, label %19
19: ; preds = %17
%20 = lshr i64 %0, 8
%21 = getelementptr inbounds [256 x i8], [256 x i8]* @l2.table, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = add nsw i32 %23, 8
br label %29
25: ; preds = %17
%26 = getelementptr inbounds [256 x i8], [256 x i8]* @l2.table, i64 0, i64 %0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
br label %29
29: ; preds = %25, %19, %12, %6
%30 = phi i32 [ %11, %6 ], [ %16, %12 ], [ %24, %19 ], [ %28, %25 ]
ret i32 %30
}