#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 /*<<< orphan*/ bitmap_is_bit_clear(unsigned long *, unsigned long);
unsigned long bitmap_find_first_zero_bit(unsigned long *bitmap,
                                         unsigned long num_bits) {
  unsigned long first = 0;
  unsigned long *tmp = bitmap;
  while ((0xFFFFFFFF == *tmp) && (first < num_bits)) {
    tmp++;
    first += 32;
  }
  while (!bitmap_is_bit_clear(bitmap, first) && (first < num_bits))
    first++;
  return first;
}


x86 assembly (clang, -O0):
<bitmap_find_first_zero_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    (%rdx),%rcx
mov    %al,-0x21(%rbp)
jne    1155 <bitmap_find_first_zero_bit+0x45>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1165 <bitmap_find_first_zero_bit+0x55>
jmp    1182 <bitmap_find_first_zero_bit+0x72>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x18(%rbp)
jmp    1130 <bitmap_find_first_zero_bit+0x20>
jmp    1187 <bitmap_find_first_zero_bit+0x77>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <bitmap_is_bit_clear@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x22(%rbp)
jne    11b2 <bitmap_find_first_zero_bit+0xa2>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11c2 <bitmap_find_first_zero_bit+0xb2>
jmp    11d3 <bitmap_find_first_zero_bit+0xc3>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1187 <bitmap_find_first_zero_bit+0x77>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_find_first_zero_bit>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    %rcx,(%rdi)
jne    1164 <bitmap_find_first_zero_bit+0x54>
test   %r15,%r15
je     1164 <bitmap_find_first_zero_bit+0x54>
lea    0x8(%r14),%rcx
xor    %eax,%eax
mov    $0xffffffff,%edx
nopw   0x0(%rax,%rax,1)
add    $0x20,%rax
cmp    %rdx,(%rcx)
jne    1164 <bitmap_find_first_zero_bit+0x54>
add    $0x8,%rcx
cmp    %r15,%rax
jb     1140 <bitmap_find_first_zero_bit+0x30>
jmp    1164 <bitmap_find_first_zero_bit+0x54>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %ecx,%ecx
jne    117d <bitmap_find_first_zero_bit+0x6d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <bitmap_is_bit_clear@plt>
mov    %eax,%ecx
lea    0x1(%rbx),%rax
cmp    %r15,%rbx
jb     1160 <bitmap_find_first_zero_bit+0x50>
add    $0xffffffffffffffff,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @bitmap_find_first_zero_bit(i64* %0, i64 %1) {
%3 = load i64, i64* %0
%4 = icmp eq i64 %3, 4294967295
%5 = icmp ne i64 %1, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %16
7: ; preds = %2, %7
%8 = phi i64* [ %10, %7 ], [ %0, %2 ]
%9 = phi i64 [ %11, %7 ], [ 0, %2 ]
%10 = getelementptr inbounds i64, i64* %8, i64 1
%11 = add i64 %9, 32
%12 = load i64, i64* %10
%13 = icmp eq i64 %12, 4294967295
%14 = icmp ult i64 %11, %1
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %7, label %16
16: ; preds = %7, %2
%17 = phi i64 [ 0, %2 ], [ %11, %7 ]
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ %24, %18 ], [ %17, %16 ]
%20 = tail call i32 @bitmap_is_bit_clear(i64* %0, i64 %19)
%21 = icmp eq i32 %20, 0
%22 = icmp ult i64 %19, %1
%23 = and i1 %22, %21
%24 = add nuw i64 %19, 1
br i1 %23, label %18, label %25
25: ; preds = %18
ret i64 %19
}