#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);
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;
  if (b[3])
    return __ffs(b[3]) + 96;
  return __ffs(b[4]) + 128;
}


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    11c8 <sched_find_first_bit+0xb8>
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    11c8 <sched_find_first_bit+0xb8>
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    11c8 <sched_find_first_bit+0xb8>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     11b3 <sched_find_first_bit+0xa3>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <__ffs@plt>
add    $0x60,%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <sched_find_first_bit+0xb8>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1030 <__ffs@plt>
add    $0x80,%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),%rax
test   %rax,%rax
je     1164 <sched_find_first_bit+0x54>
mov    %rax,%rdi
call   1030 <__ffs@plt>
add    $0x60,%eax
pop    %rcx
ret
mov    0x20(%rdi),%rdi
call   1030 <__ffs@plt>
sub    $0xffffff80,%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 %52
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 %52
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 %52
35: ; preds = %24
%36 = load i64*, i64** %3
%37 = getelementptr inbounds i64, i64* %36, i64 3
%38 = load i64, i64* %37
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = load i64*, i64** %3
%42 = getelementptr inbounds i64, i64* %41, i64 3
%43 = load i64, i64* %42
%44 = call i32 @__ffs(i64 %43)
%45 = add nsw i32 %44, 96
store i32 %45, i32* %2
br label %52
46: ; preds = %35
%47 = load i64*, i64** %3
%48 = getelementptr inbounds i64, i64* %47, i64 4
%49 = load i64, i64* %48
%50 = call i32 @__ffs(i64 %49)
%51 = add nsw i32 %50, 128
store i32 %51, i32* %2
br label %52
52: ; preds = %46, %40, %29, %18, %8
%53 = load i32, i32* %2
ret i32 %53
}

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 %32
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 %32
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 %32
20: ; preds = %13
%21 = getelementptr inbounds i64, i64* %0, i64 3
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = tail call i32 @__ffs(i64 %22)
%26 = add nsw i32 %25, 96
br label %32
27: ; preds = %20
%28 = getelementptr inbounds i64, i64* %0, i64 4
%29 = load i64, i64* %28
%30 = tail call i32 @__ffs(i64 %29)
%31 = add nsw i32 %30, 128
br label %32
32: ; preds = %27, %24, %17, %10, %4
%33 = phi i32 [ %5, %4 ], [ %12, %10 ], [ %19, %17 ], [ %26, %24 ], [ %31, %27 ]
ret i32 %33
}