#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 Kit_TruthWordNum(int);
int Kit_WordFindFirstBit(unsigned int);
int Kit_TruthFindFirstBit(unsigned *pIn, int nVars) {
  int w;
  for (w = 0; w < Kit_TruthWordNum(nVars); w++)
    if (pIn[w])
      return 32 * w + Kit_WordFindFirstBit(pIn[w]);
  return -1;
}


x86 assembly (clang, -O0):
<Kit_TruthFindFirstBit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <Kit_TruthWordNum@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    119e <Kit_TruthFindFirstBit+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     118b <Kit_TruthFindFirstBit+0x6b>
mov    -0x18(%rbp),%eax
shl    $0x5,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <Kit_WordFindFirstBit@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11a5 <Kit_TruthFindFirstBit+0x85>
jmp    1190 <Kit_TruthFindFirstBit+0x70>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1136 <Kit_TruthFindFirstBit+0x16>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Kit_TruthFindFirstBit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%r15
mov    %esi,%edi
call   1040 <Kit_TruthWordNum@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
jle    117b <Kit_TruthFindFirstBit+0x5b>
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15,%rbp,4),%edi
test   %edi,%edi
jne    1170 <Kit_TruthFindFirstBit+0x50>
add    $0x1,%rbp
mov    %r12d,%edi
call   1040 <Kit_TruthWordNum@plt>
cltq
add    $0x20,%ebx
cmp    %rax,%rbp
jl     1150 <Kit_TruthFindFirstBit+0x30>
jmp    117b <Kit_TruthFindFirstBit+0x5b>
call   1030 <Kit_WordFindFirstBit@plt>
mov    %eax,%r14d
add    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @Kit_TruthFindFirstBit(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @Kit_TruthWordNum(i32 %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %20
5: ; preds = %2, %15
%6 = phi i64 [ %16, %15 ], [ 0, %2 ]
%7 = getelementptr inbounds i32, i32* %0, i64 %6
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = trunc i64 %6 to i32
%12 = shl nsw i32 %11, 5
%13 = tail call i32 @Kit_WordFindFirstBit(i32 %8)
%14 = add nsw i32 %13, %12
br label %20
15: ; preds = %5
%16 = add nuw nsw i64 %6, 1
%17 = tail call i32 @Kit_TruthWordNum(i32 %1)
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %5, label %20
20: ; preds = %15, %2, %10
%21 = phi i32 [ %14, %10 ], [ -1, %2 ], [ -1, %15 ]
ret i32 %21
}