#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 uint64_t;

/* Variables and functions */
__attribute__((always_)) uint8_t iwbits_find_first_sbit64(uint64_t x) {
  uint8_t ret = 0;
  if ((x & 0xffffffffU) == 0) {
    ret += 32;
    x >>= 32;
  }
  if ((x & 0xffffU) == 0) {
    ret += 16;
    x >>= 16;
  }
  if ((x & 0xffU) == 0) {
    ret += 8;
    x >>= 8;
  }
  if ((x & 0xfU) == 0) {
    ret += 4;
    x >>= 4;
  }
  if ((x & 0x3U) == 0) {
    ret += 2;
    x >>= 2;
  }
  if ((x & 0x1U) == 0) {
    ret += 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<iwbits_find_first_sbit64>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffffffff,%eax
cmp    $0x0,%eax
jne    1133 <iwbits_find_first_sbit64+0x33>
mov    -0x8(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffff,%eax
cmp    $0x0,%eax
jne    1156 <iwbits_find_first_sbit64+0x56>
mov    -0x8(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
jne    1179 <iwbits_find_first_sbit64+0x79>
mov    -0x8(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    119a <iwbits_find_first_sbit64+0x9a>
mov    -0x8(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    11bb <iwbits_find_first_sbit64+0xbb>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    11d3 <iwbits_find_first_sbit64+0xd3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<iwbits_find_first_sbit64>:
xor    %eax,%eax
test   %edi,%edi
sete   %al
shl    $0x5,%eax
lea    0x10(%rax),%ecx
mov    %edi,%edx
sar    $0x10,%edx
test   %di,%di
cmovne %edi,%edx
cmovne %eax,%ecx
mov    %edx,%eax
sar    $0x8,%eax
test   %dl,%dl
cmovne %edx,%eax
lea    0x8(%rcx),%edx
cmovne %ecx,%edx
lea    0x4(%rdx),%ecx
mov    %eax,%esi
sar    $0x4,%esi
test   $0xf,%al
cmovne %eax,%esi
cmovne %edx,%ecx
lea    0x2(%rcx),%edx
mov    %esi,%eax
shr    $0x2,%eax
test   $0x3,%sil
cmovne %esi,%eax
not    %eax
cmovne %ecx,%edx
and    $0x1,%eax
add    %edx,%eax
ret

LLVM IR (-O0):
define i32 @iwbits_find_first_sbit64(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = and i32 %4, -1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 32
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = ashr i32 %10, 32
store i32 %11, i32* %2
br label %12
12: ; preds = %7, %1
%13 = load i32, i32* %2
%14 = and i32 %13, 65535
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 16
store i32 %18, i32* %3
%19 = load i32, i32* %2
%20 = ashr i32 %19, 16
store i32 %20, i32* %2
br label %21
21: ; preds = %16, %12
%22 = load i32, i32* %2
%23 = and i32 %22, 255
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 8
store i32 %27, i32* %3
%28 = load i32, i32* %2
%29 = ashr i32 %28, 8
store i32 %29, i32* %2
br label %30
30: ; preds = %25, %21
%31 = load i32, i32* %2
%32 = and i32 %31, 15
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 4
store i32 %36, i32* %3
%37 = load i32, i32* %2
%38 = ashr i32 %37, 4
store i32 %38, i32* %2
br label %39
39: ; preds = %34, %30
%40 = load i32, i32* %2
%41 = and i32 %40, 3
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 2
store i32 %45, i32* %3
%46 = load i32, i32* %2
%47 = ashr i32 %46, 2
store i32 %47, i32* %2
br label %48
48: ; preds = %43, %39
%49 = load i32, i32* %2
%50 = and i32 %49, 1
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %55
55: ; preds = %52, %48
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
define i32 @iwbits_find_first_sbit64(i32 %0) {
%2 = icmp eq i32 %0, 0
%3 = select i1 %2, i32 32, i32 0
%4 = and i32 %0, 65535
%5 = icmp eq i32 %4, 0
%6 = or i32 %3, 16
%7 = ashr i32 %0, 16
%8 = select i1 %5, i32 %7, i32 %0
%9 = select i1 %5, i32 %6, i32 %3
%10 = and i32 %8, 255
%11 = icmp eq i32 %10, 0
%12 = or i32 %9, 8
%13 = ashr i32 %8, 8
%14 = select i1 %11, i32 %13, i32 %8
%15 = select i1 %11, i32 %12, i32 %9
%16 = and i32 %14, 15
%17 = icmp eq i32 %16, 0
%18 = or i32 %15, 4
%19 = ashr i32 %14, 4
%20 = select i1 %17, i32 %19, i32 %14
%21 = select i1 %17, i32 %18, i32 %15
%22 = and i32 %20, 3
%23 = icmp eq i32 %22, 0
%24 = add nsw i32 %21, 2
%25 = lshr i32 %20, 2
%26 = select i1 %23, i32 %25, i32 %20
%27 = select i1 %23, i32 %24, i32 %21
%28 = and i32 %26, 1
%29 = xor i32 %28, 1
%30 = add nsw i32 %29, %27
ret i32 %30
}