#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 CHAR_BIT;
unsigned find_first_one(unsigned long x) {
  static const unsigned char table[0x101] = {
      15, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,
      0,  0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,
      0,  0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0,
      0,  0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,
      13, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0,
      11, 0, 0, 0, 10, 0, 9, 8, 0, 0, 1, 0, 2, 0, 0, 0, 3,  0, 0, 0, 0, 0, 0, 0,
      4,  0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,  0, 0, 0, 0, 0, 0, 0,
      0,  0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,
      6,  0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,
      0,  0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,
      0,  0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,
  };
  unsigned i = 0;
  x &= -x;
  if ((CHAR_BIT * sizeof(unsigned long)) > 32)
    while (x >= 0x100000000L) {
      x >>= 32;
      i += 32;
    }
  if (x >= 0x10000) {
    x >>= 16;
    i += 16;
  }
  return i + table[128 + (x & 0xff) - (x >> 8)];
}


x86 assembly (clang, -O0):
<find_first_one>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
sub    -0x8(%rbp),%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    0x2ebc(%rip),%rax
movslq (%rax),%rax
shl    $0x3,%rax
cmp    $0x20,%rax
jbe    116d <find_first_one+0x6d>
jmp    113a <find_first_one+0x3a>
movabs $0x100000000,%rax
cmp    %rax,-0x8(%rbp)
jb     1168 <find_first_one+0x68>
mov    -0x8(%rbp),%rax
shr    $0x20,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <find_first_one+0x3a>
jmp    116d <find_first_one+0x6d>
cmpq   $0x10000,-0x8(%rbp)
jb     1190 <find_first_one+0x90>
mov    -0x8(%rbp),%rax
shr    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%rdx
and    $0xff,%rdx
add    $0x80,%rdx
mov    -0x8(%rbp),%rcx
shr    $0x8,%rcx
sub    %rcx,%rdx
lea    0xe49(%rip),%rcx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_first_one>:
mov    %rdi,%rax
neg    %rax
and    %rdi,%rax
mov    0x2ed0(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x3,%rcx
cmp    $0x21,%rcx
setae  %sil
mov    %rax,%rdx
shr    $0x20,%rdx
setne  %cl
and    %sil,%cl
cmove  %rax,%rdx
movzbl %cl,%eax
shl    $0x5,%eax
mov    %rdx,%rcx
shr    $0x10,%rcx
lea    0x10(%rax),%esi
cmp    $0x10000,%rdx
cmovb  %rdx,%rcx
cmovb  %eax,%esi
movzbl %cl,%eax
shr    $0x8,%rcx
sub    %rcx,%rax
lea    0xea1(%rip),%rcx
movzbl 0x80(%rax,%rcx,1),%eax
add    %esi,%eax
ret

LLVM IR (-O0):
@find_first_one.table = internal constant [257 x i8] c"\0F\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\0E\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\0D\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\0C\00\00\00\00\00\00\00\0B\00\00\00\0A\00\09\08\00\00\01\00\02\00\00\00\03\00\00\00\00\00\00\00\04\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\05\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\06\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\07"
@CHAR_BIT = global i32 0
define i32 @find_first_one(i64 %0) {
%2 = alloca i64
%3 = alloca i32
store i64 %0, i64* %2
store i32 0, i32* %3
%4 = load i64, i64* %2
%5 = sub i64 0, %4
%6 = load i64, i64* %2
%7 = and i64 %6, %5
store i64 %7, i64* %2
%8 = load i32, i32* @CHAR_BIT
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = icmp ugt i64 %10, 32
br i1 %11, label %12, label %22
12: ; preds = %1
br label %13
13: ; preds = %16, %12
%14 = load i64, i64* %2
%15 = icmp uge i64 %14, 4294967296
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i64, i64* %2
%18 = lshr i64 %17, 32
store i64 %18, i64* %2
%19 = load i32, i32* %3
%20 = add i32 %19, 32
store i32 %20, i32* %3
br label %13
21: ; preds = %13
br label %22
22: ; preds = %21, %1
%23 = load i64, i64* %2
%24 = icmp uge i64 %23, 65536
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i64, i64* %2
%27 = lshr i64 %26, 16
store i64 %27, i64* %2
%28 = load i32, i32* %3
%29 = add i32 %28, 16
store i32 %29, i32* %3
br label %30
30: ; preds = %25, %22
%31 = load i32, i32* %3
%32 = load i64, i64* %2
%33 = and i64 %32, 255
%34 = add i64 128, %33
%35 = load i64, i64* %2
%36 = lshr i64 %35, 8
%37 = sub i64 %34, %36
%38 = getelementptr inbounds [257 x i8], [257 x i8]* @find_first_one.table, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = add i32 %31, %40
ret i32 %41
}

LLVM IR (-O2):
@find_first_one.table = internal unnamed_addr constant [257 x i8] c"\0F\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\0E\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\0D\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\0C\00\00\00\00\00\00\00\0B\00\00\00\0A\00\09\08\00\00\01\00\02\00\00\00\03\00\00\00\00\00\00\00\04\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\05\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\06\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\07"
@CHAR_BIT = global i32 0
define i32 @find_first_one(i64 %0) {
%2 = sub i64 0, %0
%3 = and i64 %2, %0
%4 = load i32, i32* @CHAR_BIT
%5 = sext i32 %4 to i64
%6 = shl nsw i64 %5, 3
%7 = icmp ugt i64 %6, 32
%8 = icmp ugt i64 %3, 4294967295
%9 = and i1 %8, %7
%10 = lshr i64 %3, 32
%11 = select i1 %9, i64 %10, i64 %3
%12 = select i1 %9, i32 32, i32 0
%13 = icmp ugt i64 %11, 65535
%14 = lshr i64 %11, 16
%15 = or i32 %12, 16
%16 = select i1 %13, i64 %14, i64 %11
%17 = select i1 %13, i32 %15, i32 %12
%18 = and i64 %16, 255
%19 = add nuw nsw i64 %18, 128
%20 = lshr i64 %16, 8
%21 = sub nsw i64 %19, %20
%22 = getelementptr inbounds [257 x i8], [257 x i8]* @find_first_one.table, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = add nuw nsw i32 %17, %24
ret i32 %25
}