#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 */
unsigned u32log2(uint32_t v) {
  static const char LogTable256[256] = {
      -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
      4,  4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
      5,  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
      6,  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
      6,  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
      6,  6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
      7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
      7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
      7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
      7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
      7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
  unsigned r;
  register uint32_t t, tt;
  if ((tt = v >> 16)) {
    r = (t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt];
  } else {
    r = (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v];
  }
  return r;
}


x86 assembly (clang, -O0):
<u32log2>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     1165 <u32log2+0x65>
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1145 <u32log2+0x45>
movslq -0xc(%rbp),%rcx
lea    0xeca(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x18,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <u32log2+0x5a>
movslq -0x10(%rbp),%rcx
lea    0xeb0(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11a9 <u32log2+0xa9>
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1191 <u32log2+0x91>
movslq -0xc(%rbp),%rcx
lea    0xe7e(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x8,%eax
mov    %eax,-0x18(%rbp)
jmp    11a3 <u32log2+0xa3>
movslq -0x4(%rbp),%rcx
lea    0xe64(%rip),%rax
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<u32log2>:
cmp    $0x10000,%edi
jae    111e <u32log2+0x1e>
mov    %edi,%eax
cmp    $0x100,%edi
jae    113b <u32log2+0x3b>
lea    0xee7(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
ret
cmp    $0x1000000,%edi
jae    114e <u32log2+0x4e>
sar    $0x10,%edi
movslq %edi,%rax
lea    0xecd(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x10,%eax
ret
shr    $0x8,%rax
lea    0xeba(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x8,%eax
ret
sar    $0x18,%edi
movslq %edi,%rax
lea    0xea5(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x18,%eax
ret

LLVM IR (-O0):
@u32log2.LogTable256 = internal constant [256 x i8] c"\FF\00\01\01\02\02\02\02\03\03\03\03\03\03\03\03\04\04\04\04\04\04\04\04\04\04\04\04\04\04\04\04\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07"
define i32 @u32log2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = ashr i32 %6, 16
store i32 %7, i32* %5
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %1
%10 = load i32, i32* %5
%11 = ashr i32 %10, 8
store i32 %11, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* @u32log2.LogTable256, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = add nsw i32 24, %18
br label %27
20: ; preds = %9
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [256 x i8], [256 x i8]* @u32log2.LogTable256, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = add nsw i32 16, %25
br label %27
27: ; preds = %20, %13
%28 = phi i32 [ %19, %13 ], [ %26, %20 ]
store i32 %28, i32* %3
br label %48
29: ; preds = %1
%30 = load i32, i32* %2
%31 = ashr i32 %30, 8
store i32 %31, i32* %4
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %29
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [256 x i8], [256 x i8]* @u32log2.LogTable256, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = add nsw i32 8, %38
br label %46
40: ; preds = %29
%41 = load i32, i32* %2
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [256 x i8], [256 x i8]* @u32log2.LogTable256, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
br label %46
46: ; preds = %40, %33
%47 = phi i32 [ %39, %33 ], [ %45, %40 ]
store i32 %47, i32* %3
br label %48
48: ; preds = %46, %27
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@u32log2.LogTable256 = internal unnamed_addr constant [256 x i8] c"\FF\00\01\01\02\02\02\02\03\03\03\03\03\03\03\03\04\04\04\04\04\04\04\04\04\04\04\04\04\04\04\04\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\05\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\06\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07\07"
define i32 @u32log2(i32 %0) {
%2 = ashr i32 %0, 16
%3 = icmp ult i32 %0, 65536
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = icmp ult i32 %0, 16777216
br i1 %5, label %13, label %6
6: ; preds = %4
%7 = ashr i32 %0, 24
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [256 x i8], [256 x i8]* @u32log2.LogTable256, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = add nsw i32 %11, 24
br label %33
13: ; preds = %4
%14 = sext i32 %2 to i64
%15 = getelementptr inbounds [256 x i8], [256 x i8]* @u32log2.LogTable256, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = add nsw i32 %17, 16
br label %33
19: ; preds = %1
%20 = icmp ult i32 %0, 256
br i1 %20, label %28, label %21
21: ; preds = %19
%22 = lshr i32 %0, 8
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [256 x i8], [256 x i8]* @u32log2.LogTable256, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = add nsw i32 %26, 8
br label %33
28: ; preds = %19
%29 = zext i32 %0 to i64
%30 = getelementptr inbounds [256 x i8], [256 x i8]* @u32log2.LogTable256, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
br label %33
33: ; preds = %21, %28, %6, %13
%34 = phi i32 [ %12, %6 ], [ %18, %13 ], [ %27, %21 ], [ %32, %28 ]
ret i32 %34
}