#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;
int bit_num_trailing_zeros(unsigned int n) {
  if (n == 0)
    return (CHAR_BIT * sizeof(unsigned int));
  else {
    int cnt = 0;
    if ((n & 0x0000FFFF) == 0) {
      cnt += 16;
      n >>= 16;
    }
    if ((n & 0x00FF) == 0) {
      cnt += 8;
      n >>= 8;
    }
    if ((n & 0x0F) == 0) {
      cnt += 4;
      n >>= 4;
    }
    if ((n & 0x3) == 0) {
      cnt += 2;
      n >>= 2;
    }
    if ((n & 0x1) == 0) {
      cnt += 1;
      n >>= 1;
    }
    return cnt;
  }
}


x86 assembly (clang, -O0):
<bit_num_trailing_zeros>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1127 <bit_num_trailing_zeros+0x27>
mov    0x2ec8(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,-0x4(%rbp)
jmp    11dd <bit_num_trailing_zeros+0xdd>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0xffff,%eax
cmp    $0x0,%eax
jne    1151 <bit_num_trailing_zeros+0x51>
mov    -0xc(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x10,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
jne    1174 <bit_num_trailing_zeros+0x74>
mov    -0xc(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1195 <bit_num_trailing_zeros+0x95>
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    11b6 <bit_num_trailing_zeros+0xb6>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    11d7 <bit_num_trailing_zeros+0xd7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_num_trailing_zeros>:
test   %edi,%edi
je     1152 <bit_num_trailing_zeros+0x52>
mov    %edi,%eax
shr    $0x10,%eax
xor    %ecx,%ecx
test   %di,%di
sete   %cl
cmovne %edi,%eax
shl    $0x4,%ecx
mov    %eax,%edx
shr    $0x8,%edx
test   %al,%al
cmovne %eax,%edx
lea    0x8(%rcx),%eax
cmovne %ecx,%eax
lea    0x4(%rax),%ecx
mov    %edx,%esi
shr    $0x4,%esi
test   $0xf,%dl
cmovne %edx,%esi
cmovne %eax,%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
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
shl    $0x2,%eax
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
define i32 @bit_num_trailing_zeros(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @CHAR_BIT
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
store i32 %11, i32* %2
br label %59
12: ; preds = %1
store i32 0, i32* %4
%13 = load i32, i32* %3
%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* %4
%18 = add nsw i32 %17, 16
store i32 %18, i32* %4
%19 = load i32, i32* %3
%20 = lshr i32 %19, 16
store i32 %20, i32* %3
br label %21
21: ; preds = %16, %12
%22 = load i32, i32* %3
%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* %4
%27 = add nsw i32 %26, 8
store i32 %27, i32* %4
%28 = load i32, i32* %3
%29 = lshr i32 %28, 8
store i32 %29, i32* %3
br label %30
30: ; preds = %25, %21
%31 = load i32, i32* %3
%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* %4
%36 = add nsw i32 %35, 4
store i32 %36, i32* %4
%37 = load i32, i32* %3
%38 = lshr i32 %37, 4
store i32 %38, i32* %3
br label %39
39: ; preds = %34, %30
%40 = load i32, i32* %3
%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* %4
%45 = add nsw i32 %44, 2
store i32 %45, i32* %4
%46 = load i32, i32* %3
%47 = lshr i32 %46, 2
store i32 %47, i32* %3
br label %48
48: ; preds = %43, %39
%49 = load i32, i32* %3
%50 = and i32 %49, 1
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
%55 = load i32, i32* %3
%56 = lshr i32 %55, 1
store i32 %56, i32* %3
br label %57
57: ; preds = %52, %48
%58 = load i32, i32* %4
store i32 %58, i32* %2
br label %59
59: ; preds = %57, %7
%60 = load i32, i32* %2
ret i32 %60
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
define i32 @bit_num_trailing_zeros(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @CHAR_BIT
%5 = shl i32 %4, 2
br label %33
6: ; preds = %1
%7 = and i32 %0, 65535
%8 = icmp eq i32 %7, 0
%9 = lshr i32 %0, 16
%10 = select i1 %8, i32 %9, i32 %0
%11 = select i1 %8, i32 16, i32 0
%12 = and i32 %10, 255
%13 = icmp eq i32 %12, 0
%14 = or i32 %11, 8
%15 = lshr i32 %10, 8
%16 = select i1 %13, i32 %15, i32 %10
%17 = select i1 %13, i32 %14, i32 %11
%18 = and i32 %16, 15
%19 = icmp eq i32 %18, 0
%20 = or i32 %17, 4
%21 = lshr i32 %16, 4
%22 = select i1 %19, i32 %21, i32 %16
%23 = select i1 %19, i32 %20, i32 %17
%24 = and i32 %22, 3
%25 = icmp eq i32 %24, 0
%26 = or i32 %23, 2
%27 = lshr i32 %22, 2
%28 = select i1 %25, i32 %27, i32 %22
%29 = select i1 %25, i32 %26, i32 %23
%30 = and i32 %28, 1
%31 = xor i32 %30, 1
%32 = add nsw i32 %31, %29
br label %33
33: ; preds = %6, %3
%34 = phi i32 [ %5, %3 ], [ %32, %6 ]
ret i32 %34
}