#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*/ test_bit(unsigned long *, unsigned long);
unsigned long bitmap_find_next_zero(unsigned long *bitmap, size_t size,
                                    unsigned long start) {
  unsigned long idx;
  for (idx = start; idx < size * (sizeof(unsigned long) * 8); idx++) {
    if (!test_bit(bitmap, idx)) {
      return idx;
    }
  }
  return size * (sizeof(unsigned long) * 8);
}


x86 assembly (clang, -O0):
<bitmap_find_next_zero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x6,%rcx
cmp    %rcx,%rax
jae    117a <bitmap_find_next_zero+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <test_bit@plt>
cmp    $0x0,%eax
jne    1164 <bitmap_find_next_zero+0x54>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1186 <bitmap_find_next_zero+0x76>
jmp    1169 <bitmap_find_next_zero+0x59>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    112c <bitmap_find_next_zero+0x1c>
mov    -0x18(%rbp),%rax
shl    $0x6,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_find_next_zero>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
shl    $0x6,%r14
cmp    %rdx,%r14
jbe    114d <bitmap_find_next_zero+0x3d>
mov    %rdx,%rbx
mov    %rdi,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <test_bit@plt>
test   %eax,%eax
je     114a <bitmap_find_next_zero+0x3a>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <bitmap_find_next_zero+0x20>
jmp    114d <bitmap_find_next_zero+0x3d>
mov    %rbx,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @bitmap_find_next_zero(i64* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i64* %0, i64** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%9 = load i64, i64* %7
store i64 %9, i64* %8
br label %10
10: ; preds = %23, %3
%11 = load i64, i64* %8
%12 = load i64, i64* %6
%13 = mul i64 %12, 64
%14 = icmp ult i64 %11, %13
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i64*, i64** %5
%17 = load i64, i64* %8
%18 = call i32 @test_bit(i64* %16, i64 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = load i64, i64* %8
store i64 %21, i64* %4
br label %29
22: ; preds = %15
br label %23
23: ; preds = %22
%24 = load i64, i64* %8
%25 = add i64 %24, 1
store i64 %25, i64* %8
br label %10
26: ; preds = %10
%27 = load i64, i64* %6
%28 = mul i64 %27, 64
store i64 %28, i64* %4
br label %29
29: ; preds = %26, %20
%30 = load i64, i64* %4
ret i64 %30
}

LLVM IR (-O2):
define i64 @bitmap_find_next_zero(i64* %0, i64 %1, i64 %2) {
%4 = shl i64 %1, 6
%5 = icmp ugt i64 %4, %2
br i1 %5, label %6, label %13
6: ; preds = %3, %10
%7 = phi i64 [ %11, %10 ], [ %2, %3 ]
%8 = tail call i32 @test_bit(i64* %0, i64 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = add i64 %7, 1
%12 = icmp eq i64 %11, %4
br i1 %12, label %13, label %6
13: ; preds = %6, %10, %3
%14 = phi i64 [ %4, %3 ], [ %4, %10 ], [ %7, %6 ]
ret i64 %14
}