#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__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ _critbit_has_tag(uintptr_t const);
scalar_t__ _critbit_is_set(uintptr_t const, scalar_t__);
int /*<<< orphan*/ assert(int);
uint8_t _critbit_get_crit_bit(const uintptr_t v1, const uintptr_t v2) {
  assert(v1 != v2);
  assert(!_critbit_has_tag(v1));
  assert(!_critbit_has_tag(v2));
  const uintptr_t x = v1 ^ v2;
  uint8_t crit_bit = 0;
  for (;;) {
    if (_critbit_is_set(x, crit_bit)) {
      break;
    }
    ++crit_bit;
  }
  return crit_bit;
}


x86 assembly (clang, -O0):
<_critbit_get_crit_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <_critbit_has_tag@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <_critbit_has_tag@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
xor    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <_critbit_is_set@plt>
cmp    $0x0,%rax
je     11bb <_critbit_get_crit_bit+0x8b>
jmp    11cc <_critbit_get_crit_bit+0x9c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    119f <_critbit_get_crit_bit+0x6f>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_critbit_get_crit_bit>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
cmp    %rsi,%r14
setne  %dil
call   1050 <assert@plt>
mov    %r14,%rdi
call   1030 <_critbit_has_tag@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    %r15,%rdi
call   1030 <_critbit_has_tag@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
xor    %r14,%r15
mov    $0xffffffffffffffff,%rbx
nopl   (%rax)
add    $0x1,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <_critbit_is_set@plt>
test   %rax,%rax
je     1180 <_critbit_get_crit_bit+0x50>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @_critbit_get_crit_bit(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = load i64, i64* %3
%8 = load i64, i64* %4
%9 = icmp ne i64 %7, %8
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i64, i64* %3
%13 = call i32 @_critbit_has_tag(i64 %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i64, i64* %4
%19 = call i32 @_critbit_has_tag(i64 %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i64, i64* %3
%25 = load i64, i64* %4
%26 = xor i64 %24, %25
store i64 %26, i64* %5
store i64 0, i64* %6
br label %27
27: ; preds = %33, %2
%28 = load i64, i64* %5
%29 = load i64, i64* %6
%30 = call i64 @_critbit_is_set(i64 %28, i64 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
br label %36
33: ; preds = %27
%34 = load i64, i64* %6
%35 = add nsw i64 %34, 1
store i64 %35, i64* %6
br label %27
36: ; preds = %32
%37 = load i64, i64* %6
ret i64 %37
}

LLVM IR (-O2):
define i64 @_critbit_get_crit_bit(i64 %0, i64 %1) {
%3 = icmp ne i64 %0, %1
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @_critbit_has_tag(i64 %0)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @_critbit_has_tag(i64 %1)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = xor i64 %1, %0
br label %15
15: ; preds = %15, %2
%16 = phi i64 [ 0, %2 ], [ %19, %15 ]
%17 = tail call i64 @_critbit_is_set(i64 %14, i64 %16)
%18 = icmp eq i64 %17, 0
%19 = add nuw nsw i64 %16, 1
br i1 %18, label %15, label %20
20: ; preds = %15
ret i64 %16
}