#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 */
typedef unsigned long index;

/* Variables and functions */
unsigned long find_next_bit(unsigned long *, unsigned long, unsigned long);
unsigned long find_next_zero_bit(unsigned long *, unsigned long, unsigned long);
unsigned long bitmap_find_next_zero_area(unsigned long *map, unsigned long size,
                                         unsigned long start, unsigned int nr,
                                         unsigned long align_mask) {
  unsigned long index, end, i;
again:
  index = find_next_zero_bit(map, size, start);
  index = (((index) + (align_mask)) & ~(align_mask));
  end = index + nr;
  if (end > size)
    return end;
  i = find_next_bit(map, end, index);
  if (i < end) {
    start = i + 1;
    goto again;
  }
  return index;
}


x86 assembly (clang, -O0):
<bitmap_find_next_zero_area>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <find_next_zero_bit@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
mov    -0x30(%rbp),%rcx
xor    $0xffffffffffffffff,%rcx
and    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1190 <bitmap_find_next_zero_area+0x70>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <bitmap_find_next_zero_area+0xac>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <find_next_bit@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    11c4 <bitmap_find_next_zero_area+0xa4>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113b <bitmap_find_next_zero_area+0x1b>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_find_next_zero_area>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r13d
mov    %rsi,%r12
mov    %rdi,%r15
call   1040 <find_next_zero_bit@plt>
mov    %rax,%rbx
add    %r14,%rbx
mov    %r14,(%rsp)
not    %r14
and    %r14,%rbx
mov    %r13d,%ebp
nop
lea    (%rbx,%rbp,1),%r13
cmp    %r12,%r13
ja     118d <bitmap_find_next_zero_area+0x6d>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1030 <find_next_bit@plt>
cmp    %r13,%rax
mov    %rbx,%r13
jae    118d <bitmap_find_next_zero_area+0x6d>
add    $0x1,%rax
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1040 <find_next_zero_bit@plt>
mov    %rax,%rbx
add    (%rsp),%rbx
and    %r14,%rbx
jmp    1150 <bitmap_find_next_zero_area+0x30>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @bitmap_find_next_zero_area(i64* %0, i64 %1, i64 %2, i32 %3, i64 %4) {
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
store i64* %0, i64** %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i64 %4, i64* %11
br label %15
15: ; preds = %43, %5
%16 = load i64*, i64** %7
%17 = load i64, i64* %8
%18 = load i64, i64* %9
%19 = call i64 @find_next_zero_bit(i64* %16, i64 %17, i64 %18)
store i64 %19, i64* %12
%20 = load i64, i64* %12
%21 = load i64, i64* %11
%22 = add i64 %20, %21
%23 = load i64, i64* %11
%24 = xor i64 %23, -1
%25 = and i64 %22, %24
store i64 %25, i64* %12
%26 = load i64, i64* %12
%27 = load i32, i32* %10
%28 = zext i32 %27 to i64
%29 = add i64 %26, %28
store i64 %29, i64* %13
%30 = load i64, i64* %13
%31 = load i64, i64* %8
%32 = icmp ugt i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %15
%34 = load i64, i64* %13
store i64 %34, i64* %6
br label %48
35: ; preds = %15
%36 = load i64*, i64** %7
%37 = load i64, i64* %13
%38 = load i64, i64* %12
%39 = call i64 @find_next_bit(i64* %36, i64 %37, i64 %38)
store i64 %39, i64* %14
%40 = load i64, i64* %14
%41 = load i64, i64* %13
%42 = icmp ult i64 %40, %41
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = load i64, i64* %14
%45 = add i64 %44, 1
store i64 %45, i64* %9
br label %15
46: ; preds = %35
%47 = load i64, i64* %12
store i64 %47, i64* %6
br label %48
48: ; preds = %46, %33
%49 = load i64, i64* %6
ret i64 %49
}

LLVM IR (-O2):
define i64 @bitmap_find_next_zero_area(i64* %0, i64 %1, i64 %2, i32 %3, i64 %4) {
%6 = tail call i64 @find_next_zero_bit(i64* %0, i64 %1, i64 %2)
%7 = add i64 %6, %4
%8 = xor i64 %4, -1
%9 = and i64 %7, %8
%10 = zext i32 %3 to i64
%11 = add i64 %9, %10
%12 = icmp ugt i64 %11, %1
br i1 %12, label %25, label %20
13: ; preds = %20
%14 = add nuw i64 %23, 1
%15 = tail call i64 @find_next_zero_bit(i64* %0, i64 %1, i64 %14)
%16 = add i64 %15, %4
%17 = and i64 %16, %8
%18 = add i64 %17, %10
%19 = icmp ugt i64 %18, %1
br i1 %19, label %25, label %20
20: ; preds = %5, %13
%21 = phi i64 [ %18, %13 ], [ %11, %5 ]
%22 = phi i64 [ %17, %13 ], [ %9, %5 ]
%23 = tail call i64 @find_next_bit(i64* %0, i64 %21, i64 %22)
%24 = icmp ult i64 %23, %21
br i1 %24, label %13, label %25
25: ; preds = %13, %20, %5
%26 = phi i64 [ %11, %5 ], [ %22, %20 ], [ %18, %13 ]
ret i64 %26
}