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


x86 assembly (clang, -O0):
<log2ui_pow2>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    0xef0(%rip),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1164 <log2ui_pow2+0x64>
mov    -0x4(%rbp),%eax
movslq -0xc(%rbp),%rdx
lea    0xec3(%rip),%rcx
and    (%rcx,%rdx,4),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    -0xc(%rbp),%ecx
shl    %cl,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1125 <log2ui_pow2+0x25>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<log2ui_pow2>:
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):
@log2ui_pow2.b = internal constant [5 x i32] [i32 -1431655766, i32 -858993460, i32 -252645136, i32 -16711936, i32 -65536]
define i32 @log2ui_pow2(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* getelementptr inbounds ([5 x i32], [5 x i32]* @log2ui_pow2.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* %3
store i32 4, i32* %4
br label %10
10: ; preds = %26, %1
%11 = load i32, i32* %4
%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* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [5 x i32], [5 x i32]* @log2ui_pow2.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* %4
%23 = shl i32 %21, %22
%24 = load i32, i32* %3
%25 = or i32 %24, %23
store i32 %25, i32* %3
br label %26
26: ; preds = %13
%27 = load i32, i32* %4
%28 = add nsw i32 %27, -1
store i32 %28, i32* %4
br label %10
29: ; preds = %10
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @log2ui_pow2(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
}