#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
size_t emma_log2(size_t v) {
  size_t r;
  static const int MultiplyDeBruijnBitPosition[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};
  v |= v >> 1;
  v |= v >> 2;
  v |= v >> 4;
  v |= v >> 8;
  v |= v >> 16;
  v |= v >> 32;
  r = MultiplyDeBruijnBitPosition[((size_t)((v - (v >> 1)) *
                                            0x07EDD5E59A4E28C2)) >>
                                  58];
  return r;
}


x86 assembly (clang, -O0):
<emma_log2>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
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),%rcx
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
sub    %rax,%rcx
movabs $0x7edd5e59a4e28c2,%rax
d5 ed 07
imul   %rax,%rcx
shr    $0x3a,%rcx
lea    0xe70(%rip),%rax
movslq (%rax,%rcx,4),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<emma_log2>:
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    $0x20,%rcx
or     %rax,%rcx
mov    %rcx,%rax
shr    %rax
sub    %rax,%rcx
movabs $0x7edd5e59a4e28c2,%rax
d5 ed 07
imul   %rcx,%rax
shr    $0x38,%rax
and    $0xfffffffc,%eax
lea    0xea0(%rip),%rcx
movslq (%rax,%rcx,1),%rax
ret

LLVM IR (-O0):
@emma_log2.MultiplyDeBruijnBitPosition = internal constant [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 i64 @emma_log2(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = lshr i64 %4, 1
%6 = load i64, i64* %2
%7 = or i64 %6, %5
store i64 %7, i64* %2
%8 = load i64, i64* %2
%9 = lshr i64 %8, 2
%10 = load i64, i64* %2
%11 = or i64 %10, %9
store i64 %11, i64* %2
%12 = load i64, i64* %2
%13 = lshr i64 %12, 4
%14 = load i64, i64* %2
%15 = or i64 %14, %13
store i64 %15, i64* %2
%16 = load i64, i64* %2
%17 = lshr i64 %16, 8
%18 = load i64, i64* %2
%19 = or i64 %18, %17
store i64 %19, i64* %2
%20 = load i64, i64* %2
%21 = lshr i64 %20, 16
%22 = load i64, i64* %2
%23 = or i64 %22, %21
store i64 %23, i64* %2
%24 = load i64, i64* %2
%25 = lshr i64 %24, 32
%26 = load i64, i64* %2
%27 = or i64 %26, %25
store i64 %27, i64* %2
%28 = load i64, i64* %2
%29 = load i64, i64* %2
%30 = lshr i64 %29, 1
%31 = sub i64 %28, %30
%32 = mul i64 %31, 571347909858961602
%33 = lshr i64 %32, 58
%34 = getelementptr inbounds [64 x i32], [64 x i32]* @emma_log2.MultiplyDeBruijnBitPosition, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = sext i32 %35 to i64
store i64 %36, i64* %3
%37 = load i64, i64* %3
ret i64 %37
}

LLVM IR (-O2):
@emma_log2.MultiplyDeBruijnBitPosition = internal unnamed_addr constant [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 i64 @emma_log2(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, 32
%13 = or i64 %12, %11
%14 = lshr i64 %13, 1
%15 = sub i64 %13, %14
%16 = mul i64 %15, 571347909858961602
%17 = lshr i64 %16, 58
%18 = getelementptr inbounds [64 x i32], [64 x i32]* @emma_log2.MultiplyDeBruijnBitPosition, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = sext i32 %19 to i64
ret i64 %20
}