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

/* Variables and functions */
uint16_t TRDB_D5M_log2(uint16_t power_of_2) {
  if (power_of_2 == 0x0001)
    return 0;
  else if (power_of_2 == 0x0002)
    return 1;
  else if (power_of_2 == 0x0004)
    return 2;
  else if (power_of_2 == 0x0008)
    return 3;
  else if (power_of_2 == 0x0010)
    return 4;
  else if (power_of_2 == 0x0020)
    return 5;
  else if (power_of_2 == 0x0040)
    return 6;
  else if (power_of_2 == 0x0080)
    return 7;
  else if (power_of_2 == 0x0100)
    return 8;
  else if (power_of_2 == 0x0200)
    return 9;
  else if (power_of_2 == 0x0400)
    return 10;
  else if (power_of_2 == 0x0800)
    return 11;
  else if (power_of_2 == 0x1000)
    return 12;
  else if (power_of_2 == 0x2000)
    return 13;
  else if (power_of_2 == 0x4000)
    return 14;
  else
    return 15;
}


x86 assembly (clang, -O0):
<TRDB_D5M_log2>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    111d <TRDB_D5M_log2+0x1d>
movl   $0x0,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x2,-0x8(%rbp)
jne    1133 <TRDB_D5M_log2+0x33>
movl   $0x1,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x4,-0x8(%rbp)
jne    1149 <TRDB_D5M_log2+0x49>
movl   $0x2,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x8,-0x8(%rbp)
jne    115f <TRDB_D5M_log2+0x5f>
movl   $0x3,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x10,-0x8(%rbp)
jne    1175 <TRDB_D5M_log2+0x75>
movl   $0x4,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x20,-0x8(%rbp)
jne    118b <TRDB_D5M_log2+0x8b>
movl   $0x5,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x40,-0x8(%rbp)
jne    11a1 <TRDB_D5M_log2+0xa1>
movl   $0x6,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x80,-0x8(%rbp)
jne    11ba <TRDB_D5M_log2+0xba>
movl   $0x7,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x100,-0x8(%rbp)
jne    11d3 <TRDB_D5M_log2+0xd3>
movl   $0x8,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x200,-0x8(%rbp)
jne    11ec <TRDB_D5M_log2+0xec>
movl   $0x9,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x400,-0x8(%rbp)
jne    1205 <TRDB_D5M_log2+0x105>
movl   $0xa,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x800,-0x8(%rbp)
jne    121e <TRDB_D5M_log2+0x11e>
movl   $0xb,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x1000,-0x8(%rbp)
jne    1237 <TRDB_D5M_log2+0x137>
movl   $0xc,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x2000,-0x8(%rbp)
jne    1250 <TRDB_D5M_log2+0x150>
movl   $0xd,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
cmpl   $0x4000,-0x8(%rbp)
jne    1269 <TRDB_D5M_log2+0x169>
movl   $0xe,-0x4(%rbp)
jmp    1270 <TRDB_D5M_log2+0x170>
movl   $0xf,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<TRDB_D5M_log2>:
cmp    $0x7f,%edi
jle    1133 <TRDB_D5M_log2+0x33>
cmp    $0x7ff,%edi
jg     1157 <TRDB_D5M_log2+0x57>
cmp    $0x1ff,%edi
jg     1175 <TRDB_D5M_log2+0x75>
cmp    $0x80,%edi
je     11a1 <TRDB_D5M_log2+0xa1>
cmp    $0x100,%edi
jne    11d7 <TRDB_D5M_log2+0xd7>
mov    $0x8,%eax
ret
add    $0xffffffff,%edi
cmp    $0x3f,%edi
ja     11d7 <TRDB_D5M_log2+0xd7>
xor    %eax,%eax
lea    0xeb8(%rip),%rcx
movslq (%rcx,%rdi,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    $0x1,%eax
ret
cmp    $0x1fff,%edi
jg     118b <TRDB_D5M_log2+0x8b>
cmp    $0x800,%edi
je     11c5 <TRDB_D5M_log2+0xc5>
cmp    $0x1000,%edi
jne    11d7 <TRDB_D5M_log2+0xd7>
mov    $0xc,%eax
ret
cmp    $0x200,%edi
je     11cb <TRDB_D5M_log2+0xcb>
cmp    $0x400,%edi
jne    11d7 <TRDB_D5M_log2+0xd7>
mov    $0xa,%eax
ret
cmp    $0x2000,%edi
je     11d1 <TRDB_D5M_log2+0xd1>
cmp    $0x4000,%edi
jne    11d7 <TRDB_D5M_log2+0xd7>
mov    $0xe,%eax
ret
mov    $0x7,%eax
ret
mov    $0x2,%eax
ret
mov    $0x3,%eax
ret
mov    $0x4,%eax
ret
mov    $0x5,%eax
ret
mov    $0x6,%eax
ret
mov    $0xb,%eax
ret
mov    $0x9,%eax
ret
mov    $0xd,%eax
ret
mov    $0xf,%eax
ret

LLVM IR (-O0):
define i32 @TRDB_D5M_log2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 0, i32* %2
br label %64
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 1, i32* %2
br label %64
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 4
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 2, i32* %2
br label %64
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 8
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 3, i32* %2
br label %64
19: ; preds = %15
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 16
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 4, i32* %2
br label %64
23: ; preds = %19
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 32
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 5, i32* %2
br label %64
27: ; preds = %23
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 64
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 6, i32* %2
br label %64
31: ; preds = %27
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, 128
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 7, i32* %2
br label %64
35: ; preds = %31
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 256
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 8, i32* %2
br label %64
39: ; preds = %35
%40 = load i32, i32* %3
%41 = icmp eq i32 %40, 512
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 9, i32* %2
br label %64
43: ; preds = %39
%44 = load i32, i32* %3
%45 = icmp eq i32 %44, 1024
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 10, i32* %2
br label %64
47: ; preds = %43
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, 2048
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 11, i32* %2
br label %64
51: ; preds = %47
%52 = load i32, i32* %3
%53 = icmp eq i32 %52, 4096
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 12, i32* %2
br label %64
55: ; preds = %51
%56 = load i32, i32* %3
%57 = icmp eq i32 %56, 8192
br i1 %57, label %58, label %59
58: ; preds = %55
store i32 13, i32* %2
br label %64
59: ; preds = %55
%60 = load i32, i32* %3
%61 = icmp eq i32 %60, 16384
br i1 %61, label %62, label %63
62: ; preds = %59
store i32 14, i32* %2
br label %64
63: ; preds = %59
store i32 15, i32* %2
br label %64
64: ; preds = %63, %62, %58, %54, %50, %46, %42, %38, %34, %30, %26, %22, %18, %14, %10, %6
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
define i32 @TRDB_D5M_log2(i32 %0) {
switch i32 %0, label %16 [
i32 1, label %17
i32 2, label %2
i32 4, label %3
i32 8, label %4
i32 16, label %5
i32 32, label %6
i32 64, label %7
i32 128, label %8
i32 256, label %9
i32 512, label %10
i32 1024, label %11
i32 2048, label %12
i32 4096, label %13
i32 8192, label %14
i32 16384, label %15
]
2: ; preds = %1
br label %17
3: ; preds = %1
br label %17
4: ; preds = %1
br label %17
5: ; preds = %1
br label %17
6: ; preds = %1
br label %17
7: ; preds = %1
br label %17
8: ; preds = %1
br label %17
9: ; preds = %1
br label %17
10: ; preds = %1
br label %17
11: ; preds = %1
br label %17
12: ; preds = %1
br label %17
13: ; preds = %1
br label %17
14: ; preds = %1
br label %17
15: ; preds = %1
br label %17
16: ; preds = %1
br label %17
17: ; preds = %1, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5, %4, %3, %2
%18 = phi i32 [ 1, %2 ], [ 2, %3 ], [ 3, %4 ], [ 4, %5 ], [ 5, %6 ], [ 6, %7 ], [ 7, %8 ], [ 8, %9 ], [ 9, %10 ], [ 10, %11 ], [ 11, %12 ], [ 12, %13 ], [ 13, %14 ], [ 14, %15 ], [ 15, %16 ], [ 0, %1 ]
ret i32 %18
}