int last_bit(unsigned long long b) {
  const int magic[64] = {63, 0,  58, 1,  59, 47, 53, 2,  60, 39, 48, 27, 54,
                         33, 42, 3,  61, 51, 37, 40, 49, 18, 28, 20, 55, 30,
                         34, 11, 43, 14, 22, 4,  62, 57, 46, 52, 38, 26, 32,
                         41, 50, 36, 17, 19, 29, 10, 13, 21, 56, 45, 25, 31,
                         35, 16, 9,  12, 44, 24, 15, 8,  23, 7,  6,  5};
  b |= b >> 1;
  b |= b >> 2;
  b |= b >> 4;
  b |= b >> 8;
  b |= b >> 16;
  b |= b >> 32;
  b = (b >> 1) + 1;
  return magic[(b * 0x07EDD5E59A4E28C2ULL) >> 58];
}


x86 assembly (clang, -O0):
<last_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xed3(%rip),%rsi
mov    $0x100,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x2,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x4,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x8,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x10,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x20,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movabs $0x7edd5e59a4e28c2,%rax
d5 ed 07
imul   -0x8(%rbp),%rax
shr    $0x3a,%rax
mov    -0x110(%rbp,%rax,4),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_bit>:
mov    %rdi,%rax
shr    %rax
or     %rdi,%rax
mov    %rax,%rcx
shr    $0x2,%rcx
or     %rax,%rcx
mov    %rcx,%rax
shr    $0x4,%rax
or     %rcx,%rax
mov    %rax,%rcx
shr    $0x8,%rcx
or     %rax,%rcx
mov    %rcx,%rax
shr    $0x10,%rax
or     %rcx,%rax
mov    %rax,%rcx
shr    $0x21,%rcx
shr    %rax
or     %rcx,%rax
movabs $0x7edd5e59a4e28c2,%rcx
d5 ed 07
imul   %rcx,%rax
add    %rcx,%rax
shr    $0x38,%rax
and    $0xfffffffc,%eax
lea    0xea3(%rip),%rcx
mov    (%rax,%rcx,1),%eax
ret

LLVM IR (-O0):
@__const.last_bit.magic = [64 x i32] [i32 63, i32 0, i32 58, i32 1, i32 59, i32 47, i32 53, i32 2, i32 60, i32 39, i32 48, i32 27, i32 54, i32 33, i32 42, i32 3, i32 61, i32 51, i32 37, i32 40, i32 49, i32 18, i32 28, i32 20, i32 55, i32 30, i32 34, i32 11, i32 43, i32 14, i32 22, i32 4, i32 62, i32 57, i32 46, i32 52, i32 38, i32 26, i32 32, i32 41, i32 50, i32 36, i32 17, i32 19, i32 29, i32 10, i32 13, i32 21, i32 56, i32 45, i32 25, i32 31, i32 35, i32 16, i32 9, i32 12, i32 44, i32 24, i32 15, i32 8, i32 23, i32 7, i32 6, i32 5]
define i32 @last_bit(i64 %0) {
%2 = alloca i64
%3 = alloca [64 x i32]
store i64 %0, i64* %2
%4 = bitcast [64 x i32]* %3 to i8*
%5 = load i64, i64* %2
%6 = lshr i64 %5, 1
%7 = load i64, i64* %2
%8 = or i64 %7, %6
store i64 %8, i64* %2
%9 = load i64, i64* %2
%10 = lshr i64 %9, 2
%11 = load i64, i64* %2
%12 = or i64 %11, %10
store i64 %12, i64* %2
%13 = load i64, i64* %2
%14 = lshr i64 %13, 4
%15 = load i64, i64* %2
%16 = or i64 %15, %14
store i64 %16, i64* %2
%17 = load i64, i64* %2
%18 = lshr i64 %17, 8
%19 = load i64, i64* %2
%20 = or i64 %19, %18
store i64 %20, i64* %2
%21 = load i64, i64* %2
%22 = lshr i64 %21, 16
%23 = load i64, i64* %2
%24 = or i64 %23, %22
store i64 %24, i64* %2
%25 = load i64, i64* %2
%26 = lshr i64 %25, 32
%27 = load i64, i64* %2
%28 = or i64 %27, %26
store i64 %28, i64* %2
%29 = load i64, i64* %2
%30 = lshr i64 %29, 1
%31 = add i64 %30, 1
store i64 %31, i64* %2
%32 = load i64, i64* %2
%33 = mul i64 %32, 571347909858961602
%34 = lshr i64 %33, 58
%35 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %34
%36 = load i32, i32* %35
ret i32 %36
}

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