#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 */
struct rte_bitmap {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ rte_bitmap_get(struct rte_bitmap *, unsigned int);
unsigned int cxgbe_find_first_zero_bit(struct rte_bitmap *bmap,
                                       unsigned int size) {
  unsigned int idx;
  for (idx = 0; idx < size; idx++)
    if (!rte_bitmap_get(bmap, idx))
      break;
  return idx;
}


x86 assembly (clang, -O0):
<cxgbe_find_first_zero_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    115f <cxgbe_find_first_zero_bit+0x4f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <rte_bitmap_get@plt>
cmp    $0x0,%eax
jne    114c <cxgbe_find_first_zero_bit+0x3c>
jmp    115f <cxgbe_find_first_zero_bit+0x4f>
jmp    1151 <cxgbe_find_first_zero_bit+0x41>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <cxgbe_find_first_zero_bit+0x16>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cxgbe_find_first_zero_bit>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
je     1139 <cxgbe_find_first_zero_bit+0x29>
mov    %esi,%ebp
mov    %rdi,%r14
xor    %ebx,%ebx
nop
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <rte_bitmap_get@plt>
test   %eax,%eax
je     113b <cxgbe_find_first_zero_bit+0x2b>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1120 <cxgbe_find_first_zero_bit+0x10>
mov    %ebp,%ebx
jmp    113b <cxgbe_find_first_zero_bit+0x2b>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.rte_bitmap = type { i32 }
define i32 @cxgbe_find_first_zero_bit(%struct.rte_bitmap* %0, i32 %1) {
%3 = alloca %struct.rte_bitmap*
%4 = alloca i32
%5 = alloca i32
store %struct.rte_bitmap* %0, %struct.rte_bitmap** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %17, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp ult i32 %7, %8
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = load %struct.rte_bitmap*, %struct.rte_bitmap** %3
%12 = load i32, i32* %5
%13 = call i32 @rte_bitmap_get(%struct.rte_bitmap* %11, i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %10
br label %20
16: ; preds = %10
br label %17
17: ; preds = %16
%18 = load i32, i32* %5
%19 = add i32 %18, 1
store i32 %19, i32* %5
br label %6
20: ; preds = %15, %6
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
%struct.rte_bitmap = type { i32 }
define i32 @cxgbe_find_first_zero_bit(%struct.rte_bitmap* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %11, label %4
4: ; preds = %2, %8
%5 = phi i32 [ %9, %8 ], [ 0, %2 ]
%6 = tail call i32 @rte_bitmap_get(%struct.rte_bitmap* %0, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = add nuw i32 %5, 1
%10 = icmp eq i32 %9, %1
br i1 %10, label %11, label %4
11: ; preds = %8, %4, %2
%12 = phi i32 [ 0, %2 ], [ %5, %4 ], [ %1, %8 ]
ret i32 %12
}