#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int bbz_int_log2(int u) {
  int i = 0;
  int r = 1;
  assert(u > 0);
  while ((i <= 32) && (r < u)) {
    r = 2 * r + 1;
    i = i + 1;
  }
  assert(i <= 32);
  return i;
}


x86 assembly (clang, -O0):
<bbz_int_log2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
cmpl   $0x20,-0x8(%rbp)
mov    %al,-0xd(%rbp)
jg     1155 <bbz_int_log2+0x45>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1165 <bbz_int_log2+0x55>
jmp    117f <bbz_int_log2+0x6f>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113a <bbz_int_log2+0x2a>
cmpl   $0x20,-0x8(%rbp)
setle  %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):
<bbz_int_log2>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %edi,%edi
test   %ebp,%ebp
setg   %dil
call   1030 <assert@plt>
cmp    $0x2,%ebp
jl     114e <bbz_int_log2+0x3e>
xor    %ebx,%ebx
mov    $0x1,%eax
xchg   %ax,%ax
mov    %ebx,%ecx
lea    0x1(%rcx),%ebx
cmp    $0x1f,%ecx
ja     1143 <bbz_int_log2+0x33>
add    %eax,%eax
add    $0x1,%eax
cmp    %ebp,%eax
jl     1130 <bbz_int_log2+0x20>
xor    %edi,%edi
cmp    $0x20,%ecx
setb   %dil
jmp    1155 <bbz_int_log2+0x45>
mov    $0x1,%edi
xor    %ebx,%ebx
call   1030 <assert@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bbz_int_log2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
%5 = load i32, i32* %2
%6 = icmp sgt i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
br label %9
9: ; preds = %18, %1
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 32
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br label %16
16: ; preds = %12, %9
%17 = phi i1 [ false, %9 ], [ %15, %12 ]
br i1 %17, label %18, label %24
18: ; preds = %16
%19 = load i32, i32* %4
%20 = mul nsw i32 2, %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %9
24: ; preds = %16
%25 = load i32, i32* %3
%26 = icmp sle i32 %25, 32
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @bbz_int_log2(i32 %0) {
%2 = icmp sgt i32 %0, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %17
6: ; preds = %1, %6
%7 = phi i32 [ %10, %6 ], [ 1, %1 ]
%8 = phi i32 [ %11, %6 ], [ 0, %1 ]
%9 = shl nsw i32 %7, 1
%10 = or i32 %9, 1
%11 = add nuw nsw i32 %8, 1
%12 = icmp ult i32 %8, 32
%13 = icmp slt i32 %10, %0
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %6, label %15
15: ; preds = %6
%16 = zext i1 %12 to i32
br label %17
17: ; preds = %15, %1
%18 = phi i32 [ 0, %1 ], [ %11, %15 ]
%19 = phi i32 [ 1, %1 ], [ %16, %15 ]
%20 = tail call i32 @assert(i32 %19)
ret i32 %18
}