#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
uint8_t an_flsB(uint32_t x) {
  int r = 31;
  assert(x);
  if (!(x & 0xffff0000u)) {
    x <<= 16;
    r -= 16;
  }
  if (!(x & 0xff000000u)) {
    x <<= 8;
    r -= 8;
  }
  if (!(x & 0xf0000000u)) {
    x <<= 4;
    r -= 4;
  }
  if (!(x & 0xc0000000u)) {
    x <<= 2;
    r -= 2;
  }
  if (!(x & 0x80000000u)) {
    x <<= 1;
    r -= 1;
  }
  return r;
}


x86 assembly (clang, -O0):
<an_flsB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1f,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <assert@plt>
mov    -0x4(%rbp),%eax
and    $0xffff0000,%eax
cmp    $0x0,%eax
jne    114d <an_flsB+0x3d>
mov    -0x4(%rbp),%eax
shl    $0x10,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x10,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff000000,%eax
cmp    $0x0,%eax
jne    1170 <an_flsB+0x60>
mov    -0x4(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf0000000,%eax
cmp    $0x0,%eax
jne    1193 <an_flsB+0x83>
mov    -0x4(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xc0000000,%eax
cmp    $0x0,%eax
jne    11b6 <an_flsB+0xa6>
mov    -0x4(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    11d9 <an_flsB+0xc9>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<an_flsB>:
push   %rbx
mov    %edi,%ebx
call   1030 <assert@plt>
mov    %ebx,%eax
shl    $0x10,%eax
xor    %ecx,%ecx
cmp    $0x10000,%ebx
setae  %cl
cmovae %ebx,%eax
shl    $0x4,%ecx
lea    0xf(%rcx),%edx
mov    %eax,%esi
shl    $0x8,%esi
or     $0x7,%ecx
cmp    $0x1000000,%eax
cmovae %eax,%esi
cmovae %edx,%ecx
mov    %esi,%edx
shl    $0x4,%edx
lea    -0x4(%rcx),%edi
cmp    $0x10000000,%esi
cmovae %esi,%edx
cmovae %ecx,%edi
lea    0x0(,%rdx,4),%eax
lea    -0x2(%rdi),%ecx
cmp    $0x40000000,%edx
cmovae %edx,%eax
cmovae %edi,%ecx
sar    $0x1f,%eax
not    %eax
add    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @an_flsB(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 31, i32* %3
%4 = load i32, i32* %2
%5 = call i32 @assert(i32 %4)
%6 = load i32, i32* %2
%7 = and i32 %6, -65536
%8 = icmp ne i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = load i32, i32* %2
%11 = shl i32 %10, 16
store i32 %11, i32* %2
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 16
store i32 %13, i32* %3
br label %14
14: ; preds = %9, %1
%15 = load i32, i32* %2
%16 = and i32 %15, -16777216
%17 = icmp ne i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %14
%19 = load i32, i32* %2
%20 = shl i32 %19, 8
store i32 %20, i32* %2
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 8
store i32 %22, i32* %3
br label %23
23: ; preds = %18, %14
%24 = load i32, i32* %2
%25 = and i32 %24, -268435456
%26 = icmp ne i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = load i32, i32* %2
%29 = shl i32 %28, 4
store i32 %29, i32* %2
%30 = load i32, i32* %3
%31 = sub nsw i32 %30, 4
store i32 %31, i32* %3
br label %32
32: ; preds = %27, %23
%33 = load i32, i32* %2
%34 = and i32 %33, -1073741824
%35 = icmp ne i32 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %32
%37 = load i32, i32* %2
%38 = shl i32 %37, 2
store i32 %38, i32* %2
%39 = load i32, i32* %3
%40 = sub nsw i32 %39, 2
store i32 %40, i32* %3
br label %41
41: ; preds = %36, %32
%42 = load i32, i32* %2
%43 = and i32 %42, -2147483648
%44 = icmp ne i32 %43, 0
br i1 %44, label %50, label %45
45: ; preds = %41
%46 = load i32, i32* %2
%47 = shl i32 %46, 1
store i32 %47, i32* %2
%48 = load i32, i32* %3
%49 = sub nsw i32 %48, 1
store i32 %49, i32* %3
br label %50
50: ; preds = %45, %41
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
define i32 @an_flsB(i32 %0) {
%2 = tail call i32 @assert(i32 %0)
%3 = icmp ult i32 %0, 65536
%4 = shl i32 %0, 16
%5 = select i1 %3, i32 %4, i32 %0
%6 = select i1 %3, i32 15, i32 31
%7 = icmp ult i32 %5, 16777216
%8 = shl i32 %5, 8
%9 = add nsw i32 %6, -8
%10 = select i1 %7, i32 %8, i32 %5
%11 = select i1 %7, i32 %9, i32 %6
%12 = icmp ult i32 %10, 268435456
%13 = shl i32 %10, 4
%14 = add nsw i32 %11, -4
%15 = select i1 %12, i32 %13, i32 %10
%16 = select i1 %12, i32 %14, i32 %11
%17 = icmp ult i32 %15, 1073741824
%18 = shl i32 %15, 2
%19 = add nsw i32 %16, -2
%20 = select i1 %17, i32 %18, i32 %15
%21 = select i1 %17, i32 %19, i32 %16
%22 = ashr i32 %20, 31
%23 = xor i32 %22, -1
%24 = add nsw i32 %21, %23
ret i32 %24
}