#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 /*<<< orphan*/ x;

/* Variables and functions */
int CHAR_BIT;
int /*<<< orphan*/ assert(int);
unsigned int log2_floor(unsigned int x) {
  unsigned int exp = 0;
  assert(x != 0);
  while (x > 1) {
    exp++;
    x >>= 1;
  }
  assert(exp <= sizeof(x) * CHAR_BIT);
  return exp;
}


x86 assembly (clang, -O0):
<log2_floor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x1,-0x4(%rbp)
jbe    1154 <log2_floor+0x44>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1133 <log2_floor+0x23>
mov    -0x8(%rbp),%eax
mov    0x2e82(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x2,%rcx
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log2_floor>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %edi,%edi
test   %ebp,%ebp
setne  %dil
call   1030 <assert@plt>
xor    %ebx,%ebx
cmp    $0x2,%ebp
jb     113c <log2_floor+0x2c>
xor    %ebx,%ebx
mov    %ebp,%eax
nopl   (%rax)
add    $0x1,%ebx
shr    %eax
cmp    $0x3,%ebp
mov    %eax,%ebp
ja     1130 <log2_floor+0x20>
mov    %ebx,%eax
mov    0x2e9b(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x2,%rcx
xor    %edi,%edi
cmp    %rax,%rcx
setae  %dil
call   1030 <assert@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
define i32 @log2_floor(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
br label %8
8: ; preds = %11, %1
%9 = load i32, i32* %2
%10 = icmp ugt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* %3
%13 = add i32 %12, 1
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = lshr i32 %14, 1
store i32 %15, i32* %2
br label %8
16: ; preds = %8
%17 = load i32, i32* %3
%18 = zext i32 %17 to i64
%19 = load i32, i32* @CHAR_BIT
%20 = sext i32 %19 to i64
%21 = mul i64 4, %20
%22 = icmp ule i64 %18, %21
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
define i32 @log2_floor(i32 %0) {
%2 = icmp ne i32 %0, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = icmp ugt i32 %0, 1
br i1 %5, label %6, label %12
6: ; preds = %1, %6
%7 = phi i32 [ %9, %6 ], [ 0, %1 ]
%8 = phi i32 [ %10, %6 ], [ %0, %1 ]
%9 = add nuw nsw i32 %7, 1
%10 = lshr i32 %8, 1
%11 = icmp ugt i32 %8, 3
br i1 %11, label %6, label %12
12: ; preds = %6, %1
%13 = phi i32 [ 0, %1 ], [ %9, %6 ]
%14 = zext i32 %13 to i64
%15 = load i32, i32* @CHAR_BIT
%16 = sext i32 %15 to i64
%17 = shl nsw i64 %16, 2
%18 = icmp uge i64 %17, %14
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
ret i32 %13
}