#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 __ffs(unsigned long const);
__attribute__((always_)) int sched_find_first_bit(const unsigned long *b) {
  if (b[0])
    return __ffs(b[0]);
  if (b[1])
    return __ffs(b[1]) + 32;
  if (b[2])
    return __ffs(b[2]) + 64;
  return __ffs(b[3]) + 96;
}


x86 assembly (clang, -O0):
<sched_find_first_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     113e <sched_find_first_bit+0x2e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <__ffs@plt>
mov    %eax,-0x4(%rbp)
jmp    119f <sched_find_first_bit+0x8f>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1165 <sched_find_first_bit+0x55>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <__ffs@plt>
add    $0x20,%eax
mov    %eax,-0x4(%rbp)
jmp    119f <sched_find_first_bit+0x8f>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     118c <sched_find_first_bit+0x7c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <__ffs@plt>
add    $0x40,%eax
mov    %eax,-0x4(%rbp)
jmp    119f <sched_find_first_bit+0x8f>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <__ffs@plt>
add    $0x60,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sched_find_first_bit>:
push   %rax
mov    (%rdi),%rax
test   %rax,%rax
je     1122 <sched_find_first_bit+0x12>
mov    %rax,%rdi
pop    %rax
jmp    1030 <__ffs@plt>
mov    0x8(%rdi),%rax
test   %rax,%rax
je     1138 <sched_find_first_bit+0x28>
mov    %rax,%rdi
call   1030 <__ffs@plt>
add    $0x20,%eax
pop    %rcx
ret
mov    0x10(%rdi),%rax
test   %rax,%rax
je     114e <sched_find_first_bit+0x3e>
mov    %rax,%rdi
call   1030 <__ffs@plt>
add    $0x40,%eax
pop    %rcx
ret
mov    0x18(%rdi),%rdi
call   1030 <__ffs@plt>
add    $0x60,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @sched_find_first_bit(i64* %0) {
%2 = alloca i32
%3 = alloca i64*
store i64* %0, i64** %3
%4 = load i64*, i64** %3
%5 = getelementptr inbounds i64, i64* %4, i64 0
%6 = load i64, i64* %5
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i64*, i64** %3
%10 = getelementptr inbounds i64, i64* %9, i64 0
%11 = load i64, i64* %10
%12 = call i32 @__ffs(i64 %11)
store i32 %12, i32* %2
br label %41
13: ; preds = %1
%14 = load i64*, i64** %3
%15 = getelementptr inbounds i64, i64* %14, i64 1
%16 = load i64, i64* %15
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i64*, i64** %3
%20 = getelementptr inbounds i64, i64* %19, i64 1
%21 = load i64, i64* %20
%22 = call i32 @__ffs(i64 %21)
%23 = add nsw i32 %22, 32
store i32 %23, i32* %2
br label %41
24: ; preds = %13
%25 = load i64*, i64** %3
%26 = getelementptr inbounds i64, i64* %25, i64 2
%27 = load i64, i64* %26
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i64*, i64** %3
%31 = getelementptr inbounds i64, i64* %30, i64 2
%32 = load i64, i64* %31
%33 = call i32 @__ffs(i64 %32)
%34 = add nsw i32 %33, 64
store i32 %34, i32* %2
br label %41
35: ; preds = %24
%36 = load i64*, i64** %3
%37 = getelementptr inbounds i64, i64* %36, i64 3
%38 = load i64, i64* %37
%39 = call i32 @__ffs(i64 %38)
%40 = add nsw i32 %39, 96
store i32 %40, i32* %2
br label %41
41: ; preds = %35, %29, %18, %8
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
define i32 @sched_find_first_bit(i64* nocapture %0) {
%2 = load i64, i64* %0
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @__ffs(i64 %2)
br label %25
6: ; preds = %1
%7 = getelementptr inbounds i64, i64* %0, i64 1
%8 = load i64, i64* %7
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call i32 @__ffs(i64 %8)
%12 = add nsw i32 %11, 32
br label %25
13: ; preds = %6
%14 = getelementptr inbounds i64, i64* %0, i64 2
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = tail call i32 @__ffs(i64 %15)
%19 = add nsw i32 %18, 64
br label %25
20: ; preds = %13
%21 = getelementptr inbounds i64, i64* %0, i64 3
%22 = load i64, i64* %21
%23 = tail call i32 @__ffs(i64 %22)
%24 = add nsw i32 %23, 96
br label %25
25: ; preds = %20, %17, %10, %4
%26 = phi i32 [ %5, %4 ], [ %12, %10 ], [ %19, %17 ], [ %24, %20 ]
ret i32 %26
}