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

/* Variables and functions */
int ceil_log2(uint64_t x) {
  static const uint64_t t[6] = {0xFFFFFFFF00000000ull, 0x00000000FFFF0000ull,
                                0x000000000000FF00ull, 0x00000000000000F0ull,
                                0x000000000000000Cull, 0x0000000000000002ull};
  int y = (((x & (x - 1)) == 0) ? 0 : 1);
  int j = 32;
  int i, k;
  for (i = 0; i < 6; i++) {
    k = (((x & t[i]) == 0) ? 0 : j);
    y += k;
    x >>= k;
    j >>= 1;
  }
  return y;
}


x86 assembly (clang, -O0):
<ceil_log2>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
and    %eax,%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x8(%rbp)
movl   $0x20,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x6,-0x10(%rbp)
jge    1195 <ceil_log2+0x95>
mov    -0x4(%rbp),%eax
movslq -0x10(%rbp),%rdx
lea    0xeb8(%rip),%rcx
and    (%rcx,%rdx,4),%eax
cmp    $0x0,%eax
jne    115e <ceil_log2+0x5e>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    1164 <ceil_log2+0x64>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x4(%rbp),%eax
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <ceil_log2+0x30>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ceil_log2>:
xor    %ecx,%ecx
cmp    $0x10000,%edi
setae  %cl
lea    -0x1(%rdi),%eax
xor    %edx,%edx
test   %eax,%edi
setne  %dl
shl    $0x4,%ecx
sar    %cl,%edi
or     %ecx,%edx
xor    %eax,%eax
test   $0xff00,%edi
setne  %al
mov    %eax,%ecx
shl    $0x3,%ecx
sar    %cl,%edi
lea    (%rdx,%rax,8),%eax
xor    %edx,%edx
test   $0xf0,%dil
setne  %dl
mov    %edx,%ecx
shl    $0x2,%ecx
sar    %cl,%edi
lea    (%rax,%rdx,4),%eax
xor    %edx,%edx
test   $0xc,%dil
setne  %dl
mov    %edx,%ecx
add    %edx,%ecx
sar    %cl,%edi
lea    (%rax,%rdx,2),%eax
shr    %edi
and    $0x1,%edi
add    %edi,%eax
ret

LLVM IR (-O0):
@ceil_log2.t = internal constant [6 x i32] [i32 0, i32 -65536, i32 65280, i32 240, i32 12, i32 2]
define i32 @ceil_log2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = load i32, i32* %2
%9 = sub nsw i32 %8, 1
%10 = and i32 %7, %9
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i32 0, i32 1
store i32 %13, i32* %3
store i32 32, i32* %4
store i32 0, i32* %5
br label %14
14: ; preds = %38, %1
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 6
br i1 %16, label %17, label %41
17: ; preds = %14
%18 = load i32, i32* %2
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [6 x i32], [6 x i32]* @ceil_log2.t, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = and i32 %18, %22
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
br label %28
26: ; preds = %17
%27 = load i32, i32* %4
br label %28
28: ; preds = %26, %25
%29 = phi i32 [ 0, %25 ], [ %27, %26 ]
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = load i32, i32* %3
%32 = add nsw i32 %31, %30
store i32 %32, i32* %3
%33 = load i32, i32* %6
%34 = load i32, i32* %2
%35 = ashr i32 %34, %33
store i32 %35, i32* %2
%36 = load i32, i32* %4
%37 = ashr i32 %36, 1
store i32 %37, i32* %4
br label %38
38: ; preds = %28
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %14
41: ; preds = %14
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @ceil_log2(i32 %0) {
%2 = tail call i32 @llvm.ctpop.i32(i32 %0)
%3 = icmp ugt i32 %2, 1
%4 = zext i1 %3 to i32
%5 = icmp ult i32 %0, 65536
%6 = select i1 %5, i32 0, i32 16
%7 = or i32 %6, %4
%8 = ashr i32 %0, %6
%9 = and i32 %8, 65280
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 0, i32 8
%12 = or i32 %11, %7
%13 = ashr i32 %8, %11
%14 = and i32 %13, 240
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i32 0, i32 4
%17 = or i32 %16, %12
%18 = ashr i32 %13, %16
%19 = and i32 %18, 12
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 0, i32 2
%22 = or i32 %21, %17
%23 = ashr i32 %18, %21
%24 = lshr i32 %23, 1
%25 = and i32 %24, 1
%26 = add nuw nsw i32 %25, %22
ret i32 %26
}