#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 uint;

/* Variables and functions */
uint log2uni(uint n) {
  uint bit, pow, logn;
  for (bit = 0, pow = 1; bit < 31; bit++, pow <<= 1) {
    if (n == pow)
      logn = bit;
  }
  return (logn);
}


x86 assembly (clang, -O0):
<log2uni>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x1f,-0x8(%rbp)
jge    114d <log2uni+0x4d>
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1131 <log2uni+0x31>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <log2uni+0x36>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1115 <log2uni+0x15>
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<log2uni>:
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
cmp    $0x4,%edi
mov    $0x2,%ecx
cmovne %eax,%ecx
cmp    $0x8,%edi
mov    $0x3,%eax
cmovne %ecx,%eax
cmp    $0x10,%edi
mov    $0x4,%ecx
cmovne %eax,%ecx
cmp    $0x20,%edi
mov    $0x5,%eax
cmovne %ecx,%eax
cmp    $0x40,%edi
mov    $0x6,%ecx
cmovne %eax,%ecx
cmp    $0x80,%edi
mov    $0x7,%eax
cmovne %ecx,%eax
cmp    $0x100,%edi
mov    $0x8,%ecx
cmovne %eax,%ecx
cmp    $0x200,%edi
mov    $0x9,%eax
cmovne %ecx,%eax
cmp    $0x400,%edi
mov    $0xa,%ecx
cmovne %eax,%ecx
cmp    $0x800,%edi
mov    $0xb,%eax
cmovne %ecx,%eax
cmp    $0x1000,%edi
mov    $0xc,%ecx
cmovne %eax,%ecx
cmp    $0x2000,%edi
mov    $0xd,%eax
cmovne %ecx,%eax
cmp    $0x4000,%edi
mov    $0xe,%ecx
cmovne %eax,%ecx
cmp    $0x8000,%edi
mov    $0xf,%eax
cmovne %ecx,%eax
cmp    $0x10000,%edi
mov    $0x10,%ecx
cmovne %eax,%ecx
cmp    $0x20000,%edi
mov    $0x11,%eax
cmovne %ecx,%eax
cmp    $0x40000,%edi
mov    $0x12,%ecx
cmovne %eax,%ecx
cmp    $0x80000,%edi
mov    $0x13,%eax
cmovne %ecx,%eax
cmp    $0x100000,%edi
mov    $0x14,%ecx
cmovne %eax,%ecx
cmp    $0x200000,%edi
mov    $0x15,%eax
cmovne %ecx,%eax
cmp    $0x400000,%edi
mov    $0x16,%ecx
cmovne %eax,%ecx
cmp    $0x800000,%edi
mov    $0x17,%eax
cmovne %ecx,%eax
cmp    $0x1000000,%edi
mov    $0x18,%ecx
cmovne %eax,%ecx
cmp    $0x2000000,%edi
mov    $0x19,%eax
cmovne %ecx,%eax
cmp    $0x4000000,%edi
mov    $0x1a,%ecx
cmovne %eax,%ecx
cmp    $0x8000000,%edi
mov    $0x1b,%eax
cmovne %ecx,%eax
cmp    $0x10000000,%edi
mov    $0x1c,%ecx
cmovne %eax,%ecx
cmp    $0x20000000,%edi
mov    $0x1d,%edx
cmovne %ecx,%edx
cmp    $0x40000000,%edi
mov    $0x1e,%eax
cmovne %edx,%eax
ret

LLVM IR (-O0):
define i32 @log2uni(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %6
6: ; preds = %16, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 31
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = load i32, i32* %2
%11 = load i32, i32* %4
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i32, i32* %3
store i32 %14, i32* %5
br label %15
15: ; preds = %13, %9
br label %16
16: ; preds = %15
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
%19 = load i32, i32* %4
%20 = shl i32 %19, 1
store i32 %20, i32* %4
br label %6
21: ; preds = %6
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
define i32 @log2uni(i32 %0) {
%2 = icmp eq i32 %0, 2
%3 = zext i1 %2 to i32
%4 = icmp eq i32 %0, 4
%5 = select i1 %4, i32 2, i32 %3
%6 = icmp eq i32 %0, 8
%7 = select i1 %6, i32 3, i32 %5
%8 = icmp eq i32 %0, 16
%9 = select i1 %8, i32 4, i32 %7
%10 = icmp eq i32 %0, 32
%11 = select i1 %10, i32 5, i32 %9
%12 = icmp eq i32 %0, 64
%13 = select i1 %12, i32 6, i32 %11
%14 = icmp eq i32 %0, 128
%15 = select i1 %14, i32 7, i32 %13
%16 = icmp eq i32 %0, 256
%17 = select i1 %16, i32 8, i32 %15
%18 = icmp eq i32 %0, 512
%19 = select i1 %18, i32 9, i32 %17
%20 = icmp eq i32 %0, 1024
%21 = select i1 %20, i32 10, i32 %19
%22 = icmp eq i32 %0, 2048
%23 = select i1 %22, i32 11, i32 %21
%24 = icmp eq i32 %0, 4096
%25 = select i1 %24, i32 12, i32 %23
%26 = icmp eq i32 %0, 8192
%27 = select i1 %26, i32 13, i32 %25
%28 = icmp eq i32 %0, 16384
%29 = select i1 %28, i32 14, i32 %27
%30 = icmp eq i32 %0, 32768
%31 = select i1 %30, i32 15, i32 %29
%32 = icmp eq i32 %0, 65536
%33 = select i1 %32, i32 16, i32 %31
%34 = icmp eq i32 %0, 131072
%35 = select i1 %34, i32 17, i32 %33
%36 = icmp eq i32 %0, 262144
%37 = select i1 %36, i32 18, i32 %35
%38 = icmp eq i32 %0, 524288
%39 = select i1 %38, i32 19, i32 %37
%40 = icmp eq i32 %0, 1048576
%41 = select i1 %40, i32 20, i32 %39
%42 = icmp eq i32 %0, 2097152
%43 = select i1 %42, i32 21, i32 %41
%44 = icmp eq i32 %0, 4194304
%45 = select i1 %44, i32 22, i32 %43
%46 = icmp eq i32 %0, 8388608
%47 = select i1 %46, i32 23, i32 %45
%48 = icmp eq i32 %0, 16777216
%49 = select i1 %48, i32 24, i32 %47
%50 = icmp eq i32 %0, 33554432
%51 = select i1 %50, i32 25, i32 %49
%52 = icmp eq i32 %0, 67108864
%53 = select i1 %52, i32 26, i32 %51
%54 = icmp eq i32 %0, 134217728
%55 = select i1 %54, i32 27, i32 %53
%56 = icmp eq i32 %0, 268435456
%57 = select i1 %56, i32 28, i32 %55
%58 = icmp eq i32 %0, 536870912
%59 = select i1 %58, i32 29, i32 %57
%60 = icmp eq i32 %0, 1073741824
%61 = select i1 %60, i32 30, i32 %59
ret i32 %61
}