int _floorlog2(unsigned int x) {
  static const unsigned char log_2[256] = {
      0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
      4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
      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,
      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,
      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};
  int l = 0;
  while (x >= 256) {
    l += 8;
    x >>= 8;
  }
  return l + log_2[x];
}


x86 assembly (clang, -O0):
<_floorlog2>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x100,-0x4(%rbp)
jb     1132 <_floorlog2+0x32>
mov    -0x8(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
mov    %eax,-0x4(%rbp)
jmp    110e <_floorlog2+0xe>
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
mov    %ecx,%edx
lea    0xebf(%rip),%rcx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_floorlog2>:
xor    %ecx,%ecx
cmp    $0x100,%edi
jb     1122 <_floorlog2+0x22>
xor    %ecx,%ecx
mov    %edi,%eax
xchg   %ax,%ax
add    $0x8,%ecx
shr    $0x8,%eax
cmp    $0xffff,%edi
mov    %eax,%edi
ja     1110 <_floorlog2+0x10>
jmp    1124 <_floorlog2+0x24>
mov    %edi,%eax
mov    %eax,%eax
lea    0xed3(%rip),%rdx
movzbl (%rax,%rdx,1),%eax
add    %ecx,%eax
ret

LLVM IR (-O0):
@_floorlog2.log_2 = internal constant [256 x i8] c"\00\00\01\01\02\02\02\02\03\03\03\03\03\03\03\03\04\04\04\04\04\04\04\04\04\04\04\04\04\04\04\04\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\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\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\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"
define i32 @_floorlog2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %7, %1
%5 = load i32, i32* %2
%6 = icmp uge i32 %5, 256
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 8
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = lshr i32 %10, 8
store i32 %11, i32* %2
br label %4
12: ; preds = %4
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* @_floorlog2.log_2, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = add nsw i32 %13, %18
ret i32 %19
}

LLVM IR (-O2):
@_floorlog2.log_2 = internal unnamed_addr constant [256 x i8] c"\00\00\01\01\02\02\02\02\03\03\03\03\03\03\03\03\04\04\04\04\04\04\04\04\04\04\04\04\04\04\04\04\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\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\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\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"
define i32 @_floorlog2(i32 %0) {
%2 = icmp ugt i32 %0, 255
br i1 %2, label %3, label %9
3: ; preds = %1, %3
%4 = phi i32 [ %6, %3 ], [ 0, %1 ]
%5 = phi i32 [ %7, %3 ], [ %0, %1 ]
%6 = add nuw nsw i32 %4, 8
%7 = lshr i32 %5, 8
%8 = icmp ugt i32 %5, 65535
br i1 %8, label %3, label %9
9: ; preds = %3, %1
%10 = phi i32 [ %0, %1 ], [ %7, %3 ]
%11 = phi i32 [ 0, %1 ], [ %6, %3 ]
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds [256 x i8], [256 x i8]* @_floorlog2.log_2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = add nuw nsw i32 %11, %15
ret i32 %16
}