int __ffs(i)
int i;
{
  static const unsigned char table[] = {
      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};
  unsigned int a;
  unsigned int x = i & -i;
  a = x <= 0xffff ? (x <= 0xff ? 0 : 8) : (x <= 0xffffff ? 16 : 24);
  return table[x >> a] + a;
}


x86 assembly (clang, -O0):
<__ffs>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
xor    %ecx,%ecx
sub    -0x4(%rbp),%ecx
and    %ecx,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xffff,-0xc(%rbp)
ja     113c <__ffs+0x3c>
mov    -0xc(%rbp),%edx
mov    $0x8,%eax
xor    %ecx,%ecx
cmp    $0xff,%edx
cmovbe %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    1155 <__ffs+0x55>
mov    -0xc(%rbp),%edx
mov    $0x18,%eax
mov    $0x10,%ecx
cmp    $0xffffff,%edx
cmovbe %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
shr    %cl,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0xe92(%rip),%rax
movzbl (%rax,%rcx,1),%eax
add    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<__ffs>:
mov    %edi,%eax
neg    %eax
and    %edi,%eax
xor    %edx,%edx
cmp    $0x100,%eax
setae  %dl
shl    $0x3,%edx
xor    %ecx,%ecx
cmp    $0x1000000,%eax
setae  %cl
cmp    $0x10000,%eax
lea    0x10(,%rcx,8),%ecx
cmovb  %edx,%ecx
shr    %cl,%rax
lea    0xeca(%rip),%rdx
movzbl (%rax,%rdx,1),%eax
add    %ecx,%eax
ret

LLVM IR (-O0):
@__ffs.table = 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 @__ffs(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* %2
%7 = sub nsw i32 0, %6
%8 = and i32 %5, %7
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ule i32 %9, 65535
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* %4
%13 = icmp ule i32 %12, 255
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 0, i32 8
br label %21
16: ; preds = %1
%17 = load i32, i32* %4
%18 = icmp ule i32 %17, 16777215
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 16, i32 24
br label %21
21: ; preds = %16, %11
%22 = phi i32 [ %15, %11 ], [ %20, %16 ]
store i32 %22, i32* %3
%23 = load i32, i32* %4
%24 = load i32, i32* %3
%25 = lshr i32 %23, %24
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [256 x i8], [256 x i8]* @__ffs.table, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = load i32, i32* %3
%31 = add i32 %29, %30
ret i32 %31
}

LLVM IR (-O2):
@__ffs.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 @__ffs(i32 %0) {
%2 = sub nsw i32 0, %0
%3 = and i32 %2, %0
%4 = icmp ult i32 %3, 65536
%5 = icmp ult i32 %3, 256
%6 = select i1 %5, i32 0, i32 8
%7 = icmp ult i32 %3, 16777216
%8 = select i1 %7, i32 16, i32 24
%9 = select i1 %4, i32 %6, i32 %8
%10 = lshr i32 %3, %9
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [256 x i8], [256 x i8]* @__ffs.table, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = add nuw nsw i32 %9, %14
ret i32 %15
}