#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 */
uint32_t BF_logTwoOfABaseTwoNumber(uint32_t v) {
  uint32_t i = 0;
  static const uint32_t b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00,
                               0xFFFF0000};
  uint32_t r = (v & b[0]) != 0;
  for (i = 4; i > 0; i--) {
    r |= ((v & b[i]) != 0) << i;
  }
  return r;
}


x86 assembly (clang, -O0):
<BF_logTwoOfABaseTwoNumber>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    0xee9(%rip),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
movl   $0x4,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    116b <BF_logTwoOfABaseTwoNumber+0x6b>
mov    -0x4(%rbp),%eax
movslq -0x8(%rbp),%rdx
lea    0xebc(%rip),%rcx
and    (%rcx,%rdx,4),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x8(%rbp),%ecx
shl    %cl,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    112c <BF_logTwoOfABaseTwoNumber+0x2c>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<BF_logTwoOfABaseTwoNumber>:
xor    %eax,%eax
test   $0xaaaaaaaa,%edi
setne  %al
xor    %ecx,%ecx
cmp    $0x10000,%edi
setae  %cl
shl    $0x4,%ecx
or     %eax,%ecx
xor    %eax,%eax
test   $0xff00ff00,%edi
setne  %al
lea    (%rcx,%rax,8),%eax
xor    %ecx,%ecx
test   $0xf0f0f0f0,%edi
setne  %cl
lea    (%rax,%rcx,4),%eax
xor    %ecx,%ecx
test   $0xcccccccc,%edi
setne  %cl
lea    (%rax,%rcx,2),%eax
ret

LLVM IR (-O0):
@BF_logTwoOfABaseTwoNumber.b = internal constant [5 x i32] [i32 -1431655766, i32 -858993460, i32 -252645136, i32 -16711936, i32 -65536]
define i32 @BF_logTwoOfABaseTwoNumber(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = load i32, i32* %2
%6 = load i32, i32* getelementptr inbounds ([5 x i32], [5 x i32]* @BF_logTwoOfABaseTwoNumber.b, i64 0, i64 0)
%7 = and i32 %5, %6
%8 = icmp ne i32 %7, 0
%9 = zext i1 %8 to i32
store i32 %9, i32* %4
store i32 4, i32* %3
br label %10
10: ; preds = %26, %1
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [5 x i32], [5 x i32]* @BF_logTwoOfABaseTwoNumber.b, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = and i32 %14, %18
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i32
%22 = load i32, i32* %3
%23 = shl i32 %21, %22
%24 = load i32, i32* %4
%25 = or i32 %24, %23
store i32 %25, i32* %4
br label %26
26: ; preds = %13
%27 = load i32, i32* %3
%28 = add nsw i32 %27, -1
store i32 %28, i32* %3
br label %10
29: ; preds = %10
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @BF_logTwoOfABaseTwoNumber(i32 %0) {
%2 = and i32 %0, -1431655766
%3 = icmp ne i32 %2, 0
%4 = zext i1 %3 to i32
%5 = icmp ugt i32 %0, 65535
%6 = select i1 %5, i32 16, i32 0
%7 = or i32 %6, %4
%8 = and i32 %0, -16711936
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 0, i32 8
%11 = or i32 %10, %7
%12 = and i32 %0, -252645136
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 0, i32 4
%15 = or i32 %14, %11
%16 = and i32 %0, -858993460
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i32 0, i32 2
%19 = or i32 %18, %15
ret i32 %19
}