#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 scalar_t__ x;

/* Variables and functions */
unsigned int countbits(unsigned int);
unsigned int ceillog2(unsigned int x) {
  unsigned int y;
  y = !(((x) & ((x)-1)) == 0);
  x |= x >> 1;
  x |= x >> 2;
  x |= x >> 4;
  x |= x >> 8;
  x |= x >> 16;
  return countbits(x >> 1) + y;
}


x86 assembly (clang, -O0):
<ceillog2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
sete   %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x2,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x10,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
shr    $0x1,%edi
call   1030 <countbits@plt>
add    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ceillog2>:
push   %rbx
lea    -0x1(%rdi),%ebx
and    %edi,%ebx
mov    %edi,%eax
shr    %eax
or     %eax,%edi
mov    %edi,%eax
shr    $0x2,%eax
or     %eax,%edi
mov    %edi,%eax
shr    $0x4,%eax
or     %eax,%edi
mov    %edi,%eax
shr    $0x8,%eax
or     %eax,%edi
mov    %edi,%eax
shr    $0x11,%eax
shr    %edi
or     %eax,%edi
call   1030 <countbits@plt>
cmp    $0x1,%ebx
sbb    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @ceillog2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* %2
%6 = sub i32 %5, 1
%7 = and i32 %4, %6
%8 = icmp eq i32 %7, 0
%9 = xor i1 %8, true
%10 = zext i1 %9 to i32
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = lshr i32 %11, 1
%13 = load i32, i32* %2
%14 = or i32 %13, %12
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = lshr i32 %15, 2
%17 = load i32, i32* %2
%18 = or i32 %17, %16
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = lshr i32 %19, 4
%21 = load i32, i32* %2
%22 = or i32 %21, %20
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = lshr i32 %23, 8
%25 = load i32, i32* %2
%26 = or i32 %25, %24
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = lshr i32 %27, 16
%29 = load i32, i32* %2
%30 = or i32 %29, %28
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = lshr i32 %31, 1
%33 = call i32 @countbits(i32 %32)
%34 = load i32, i32* %3
%35 = add i32 %33, %34
ret i32 %35
}

LLVM IR (-O2):
define i32 @ceillog2(i32 %0) {
%2 = tail call i32 @llvm.ctpop.i32(i32 %0)
%3 = icmp ugt i32 %2, 1
%4 = zext i1 %3 to i32
%5 = lshr i32 %0, 1
%6 = or i32 %5, %0
%7 = lshr i32 %6, 2
%8 = or i32 %7, %6
%9 = lshr i32 %8, 4
%10 = or i32 %9, %8
%11 = lshr i32 %10, 8
%12 = or i32 %11, %10
%13 = lshr i32 %12, 17
%14 = lshr i32 %12, 1
%15 = or i32 %13, %14
%16 = tail call i32 @countbits(i32 %15)
%17 = add i32 %16, %4
ret i32 %17
}