#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 */
typedef int uint32_t;

/* Variables and functions */
int log2(unsigned v) {
  int r;
  static const int MultiplyDeBruijnBitPosition[32] = {
      0, 9,  1,  10, 13, 21, 2,  29, 11, 14, 16, 18, 22, 25, 3, 30,
      8, 12, 20, 28, 15, 17, 24, 7,  19, 27, 23, 6,  26, 5,  4, 31};
  v |= v >> 1;
  v |= v >> 2;
  v |= v >> 4;
  v |= v >> 8;
  v |= v >> 16;
  r = MultiplyDeBruijnBitPosition[(uint32_t)(v * 0x07C4ACDDU) >> 27];
  return r;
}


x86 assembly (clang, -O0):
<log2>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x2,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x10,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
imul   $0x7c4acdd,-0x4(%rbp),%eax
sar    $0x1b,%eax
movslq %eax,%rcx
lea    0xea9(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<log2>:
mov    %edi,%eax
shr    %eax
or     %edi,%eax
mov    %eax,%ecx
shr    $0x2,%ecx
or     %eax,%ecx
mov    %ecx,%eax
shr    $0x4,%eax
or     %ecx,%eax
mov    %eax,%ecx
shr    $0x8,%ecx
or     %eax,%ecx
mov    %ecx,%eax
shr    $0x10,%eax
or     %ecx,%eax
imul   $0x7c4acdd,%eax,%eax
sar    $0x1b,%eax
cltq
lea    0xecc(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
@log2.MultiplyDeBruijnBitPosition = internal constant [32 x i32] [i32 0, i32 9, i32 1, i32 10, i32 13, i32 21, i32 2, i32 29, i32 11, i32 14, i32 16, i32 18, i32 22, i32 25, i32 3, i32 30, i32 8, i32 12, i32 20, i32 28, i32 15, i32 17, i32 24, i32 7, i32 19, i32 27, i32 23, i32 6, i32 26, i32 5, i32 4, i32 31]
define i32 @log2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = lshr i32 %4, 1
%6 = load i32, i32* %2
%7 = or i32 %6, %5
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = lshr i32 %8, 2
%10 = load i32, i32* %2
%11 = or i32 %10, %9
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = lshr i32 %12, 4
%14 = load i32, i32* %2
%15 = or i32 %14, %13
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = lshr i32 %16, 8
%18 = load i32, i32* %2
%19 = or i32 %18, %17
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = lshr i32 %20, 16
%22 = load i32, i32* %2
%23 = or i32 %22, %21
store i32 %23, i32* %2
%24 = load i32, i32* %2
%25 = mul i32 %24, 130329821
%26 = ashr i32 %25, 27
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [32 x i32], [32 x i32]* @log2.MultiplyDeBruijnBitPosition, i64 0, i64 %27
%29 = load i32, i32* %28
store i32 %29, i32* %3
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@log2.MultiplyDeBruijnBitPosition = internal unnamed_addr constant [32 x i32] [i32 0, i32 9, i32 1, i32 10, i32 13, i32 21, i32 2, i32 29, i32 11, i32 14, i32 16, i32 18, i32 22, i32 25, i32 3, i32 30, i32 8, i32 12, i32 20, i32 28, i32 15, i32 17, i32 24, i32 7, i32 19, i32 27, i32 23, i32 6, i32 26, i32 5, i32 4, i32 31]
define i32 @log2(i32 %0) {
%2 = lshr i32 %0, 1
%3 = or i32 %2, %0
%4 = lshr i32 %3, 2
%5 = or i32 %4, %3
%6 = lshr i32 %5, 4
%7 = or i32 %6, %5
%8 = lshr i32 %7, 8
%9 = or i32 %8, %7
%10 = lshr i32 %9, 16
%11 = or i32 %10, %9
%12 = mul i32 %11, 130329821
%13 = ashr i32 %12, 27
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [32 x i32], [32 x i32]* @log2.MultiplyDeBruijnBitPosition, i64 0, i64 %14
%16 = load i32, i32* %15
ret i32 %16
}