#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 btor_is_power_of_2_util(int);
int btor_log_2_util(int x) {
  int result = 0;
  assert(x > 0);
  assert(btor_is_power_of_2_util(x));
  while (x > 1) {
    x >>= 1;
    result++;
  }
  assert(result >= 0);
  return result;
}


x86 assembly (clang, -O0):
<btor_log_2_util>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x4(%rbp),%edi
call   1040 <btor_is_power_of_2_util@plt>
mov    %eax,%edi
call   1030 <assert@plt>
cmpl   $0x1,-0x4(%rbp)
jle    1173 <btor_log_2_util+0x53>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1152 <btor_log_2_util+0x32>
cmpl   $0x0,-0x8(%rbp)
setge  %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):
<btor_log_2_util>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %edi,%edi
test   %ebx,%ebx
setg   %dil
call   1030 <assert@plt>
mov    %ebx,%edi
call   1040 <btor_is_power_of_2_util@plt>
mov    %eax,%edi
call   1030 <assert@plt>
xor    %ebp,%ebp
cmp    $0x2,%ebx
jl     115c <btor_log_2_util+0x3c>
xor    %ebp,%ebp
mov    %ebx,%eax
nopl   0x0(%rax,%rax,1)
shr    %eax
add    $0x1,%ebp
cmp    $0x3,%ebx
mov    %eax,%ebx
ja     1150 <btor_log_2_util+0x30>
mov    $0x1,%edi
call   1030 <assert@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @btor_log_2_util(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 sgt i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i32, i32* %2
%9 = call i32 @btor_is_power_of_2_util(i32 %8)
%10 = call i32 @assert(i32 %9)
br label %11
11: ; preds = %14, %1
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* %2
%16 = ashr i32 %15, 1
store i32 %16, i32* %2
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %11
19: ; preds = %11
%20 = load i32, i32* %3
%21 = icmp sge i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @btor_log_2_util(i32 %0) {
%2 = icmp sgt i32 %0, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @btor_is_power_of_2_util(i32 %0)
%6 = tail call i32 @assert(i32 %5)
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %14
8: ; preds = %1, %8
%9 = phi i32 [ %12, %8 ], [ 0, %1 ]
%10 = phi i32 [ %11, %8 ], [ %0, %1 ]
%11 = lshr i32 %10, 1
%12 = add nuw nsw i32 %9, 1
%13 = icmp ugt i32 %10, 3
br i1 %13, label %8, label %14
14: ; preds = %8, %1
%15 = phi i32 [ 0, %1 ], [ %12, %8 ]
%16 = tail call i32 @assert(i32 1)
ret i32 %15
}