#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_bitmap_find_free_region(struct rte_bitmap *bmap,
                                           unsigned int size,
                                           unsigned int num) {
  unsigned int idx, j, free = 0;
  if (num > size)
    return size;
  for (idx = 0; idx < size; idx += num) {
    for (j = 0; j < num; j++) {
      if (!rte_bitmap_get(bmap, idx + j)) {
        free++;
      } else {
        free = 0;
        break;
      }
    }
    if (free == num)
      break;
    if ((idx + num) > size) {
      idx = size;
      break;
    }
  }
  return idx;
}


x86 assembly (clang, -O0):
<cxgbe_bitmap_find_free_region>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jbe    1140 <cxgbe_bitmap_find_free_region+0x30>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ef <cxgbe_bitmap_find_free_region+0xdf>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11e9 <cxgbe_bitmap_find_free_region+0xd9>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11ab <cxgbe_bitmap_find_free_region+0x9b>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    -0x20(%rbp),%esi
call   1030 <rte_bitmap_get@plt>
cmp    $0x0,%eax
jne    118c <cxgbe_bitmap_find_free_region+0x7c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1198 <cxgbe_bitmap_find_free_region+0x88>
movl   $0x0,-0x24(%rbp)
jmp    11ab <cxgbe_bitmap_find_free_region+0x9b>
jmp    119d <cxgbe_bitmap_find_free_region+0x8d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115a <cxgbe_bitmap_find_free_region+0x4a>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11bc <cxgbe_bitmap_find_free_region+0xac>
jmp    11e9 <cxgbe_bitmap_find_free_region+0xd9>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jbe    11d6 <cxgbe_bitmap_find_free_region+0xc6>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11e9 <cxgbe_bitmap_find_free_region+0xd9>
jmp    11db <cxgbe_bitmap_find_free_region+0xcb>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1147 <cxgbe_bitmap_find_free_region+0x37>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cxgbe_bitmap_find_free_region>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
cmp    %esi,%edx
ja     1175 <cxgbe_bitmap_find_free_region+0x65>
mov    %edx,%r13d
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %r12d,%r12d
nopl   (%rax)
cmp    %r14d,%ebx
jae    1172 <cxgbe_bitmap_find_free_region+0x62>
test   %r13d,%r13d
je     1163 <cxgbe_bitmap_find_free_region+0x53>
add    %r13d,%r12d
xor    %ebp,%ebp
nop
lea    (%rbx,%rbp,1),%esi
mov    %r15,%rdi
call   1030 <rte_bitmap_get@plt>
test   %eax,%eax
jne    1160 <cxgbe_bitmap_find_free_region+0x50>
add    $0x1,%ebp
cmp    %ebp,%r13d
jne    1140 <cxgbe_bitmap_find_free_region+0x30>
jmp    1163 <cxgbe_bitmap_find_free_region+0x53>
nopl   0x0(%rax)
xor    %r12d,%r12d
cmp    %r13d,%r12d
je     1172 <cxgbe_bitmap_find_free_region+0x62>
add    %r13d,%ebx
cmp    %r14d,%ebx
jbe    1130 <cxgbe_bitmap_find_free_region+0x20>
jmp    1175 <cxgbe_bitmap_find_free_region+0x65>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rte_bitmap = type { i32 }
define i32 @cxgbe_bitmap_find_free_region(%struct.rte_bitmap* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.rte_bitmap*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.rte_bitmap* %0, %struct.rte_bitmap** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %10
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp ugt i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i32, i32* %6
store i32 %15, i32* %4
br label %61
16: ; preds = %3
store i32 0, i32* %8
br label %17
17: ; preds = %55, %16
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %59
21: ; preds = %17
store i32 0, i32* %9
br label %22
22: ; preds = %38, %21
%23 = load i32, i32* %9
%24 = load i32, i32* %7
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = load %struct.rte_bitmap*, %struct.rte_bitmap** %5
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = add i32 %28, %29
%31 = call i32 @rte_bitmap_get(%struct.rte_bitmap* %27, i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %26
%34 = load i32, i32* %10
%35 = add i32 %34, 1
store i32 %35, i32* %10
br label %37
36: ; preds = %26
store i32 0, i32* %10
br label %41
37: ; preds = %33
br label %38
38: ; preds = %37
%39 = load i32, i32* %9
%40 = add i32 %39, 1
store i32 %40, i32* %9
br label %22
41: ; preds = %36, %22
%42 = load i32, i32* %10
%43 = load i32, i32* %7
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %41
br label %59
46: ; preds = %41
%47 = load i32, i32* %8
%48 = load i32, i32* %7
%49 = add i32 %47, %48
%50 = load i32, i32* %6
%51 = icmp ugt i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = load i32, i32* %6
store i32 %53, i32* %8
br label %59
54: ; preds = %46
br label %55
55: ; preds = %54
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = add i32 %57, %56
store i32 %58, i32* %8
br label %17
59: ; preds = %52, %45, %17
%60 = load i32, i32* %8
store i32 %60, i32* %4
br label %61
61: ; preds = %59, %14
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
%struct.rte_bitmap = type { i32 }
define i32 @cxgbe_bitmap_find_free_region(%struct.rte_bitmap* %0, i32 %1, i32 %2) {
%4 = icmp ugt i32 %2, %1
br i1 %4, label %28, label %5
5: ; preds = %3
%6 = icmp eq i32 %2, 0
br label %7
7: ; preds = %5, %25
%8 = phi i32 [ %26, %25 ], [ 0, %5 ]
%9 = phi i32 [ %23, %25 ], [ 0, %5 ]
%10 = icmp ult i32 %8, %1
br i1 %10, label %11, label %28
11: ; preds = %7
br i1 %6, label %22, label %12
12: ; preds = %11
%13 = add i32 %9, %2
br label %14
14: ; preds = %12, %19
%15 = phi i32 [ %20, %19 ], [ 0, %12 ]
%16 = add i32 %15, %8
%17 = tail call i32 @rte_bitmap_get(%struct.rte_bitmap* %0, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = add nuw i32 %15, 1
%21 = icmp eq i32 %20, %2
br i1 %21, label %22, label %14
22: ; preds = %19, %14, %11
%23 = phi i32 [ %9, %11 ], [ 0, %14 ], [ %13, %19 ]
%24 = icmp eq i32 %23, %2
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = add i32 %8, %2
%27 = icmp ugt i32 %26, %1
br i1 %27, label %28, label %7
28: ; preds = %7, %22, %25, %3
%29 = phi i32 [ %1, %3 ], [ %1, %25 ], [ %8, %7 ], [ %8, %22 ]
ret i32 %29
}