#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 get_bitmap(unsigned char *, int, int);
int find_free_bit(unsigned char *map, int size) {
  int index = 0;
  int testBit = 1;
  for (index = 0; index <= size; index++) {
    testBit = get_bitmap(map, index, size);
    if (testBit == 0)
      break;
  }
  if (testBit == -1)
    return testBit;
  else
    return index;
}


x86 assembly (clang, -O0):
<find_free_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1174 <find_free_bit+0x64>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <get_bitmap@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1161 <find_free_bit+0x51>
jmp    1174 <find_free_bit+0x64>
jmp    1166 <find_free_bit+0x56>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1134 <find_free_bit+0x24>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1189 <find_free_bit+0x79>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <find_free_bit+0x7f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_free_bit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
js     1152 <find_free_bit+0x42>
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x1(%r14),%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1030 <get_bitmap@plt>
test   %eax,%eax
je     1154 <find_free_bit+0x44>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1130 <find_free_bit+0x20>
cmp    $0xffffffff,%eax
cmove  %eax,%ebp
mov    %ebp,%ebx
jmp    1154 <find_free_bit+0x44>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_free_bit(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 1, i32* %7
store i32 0, i32* %6
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %5
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = call i32 @get_bitmap(i8* %13, i32 %14, i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
br label %24
20: ; preds = %12
br label %21
21: ; preds = %20
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %8
24: ; preds = %19, %8
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i32, i32* %7
store i32 %28, i32* %3
br label %31
29: ; preds = %24
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %31
31: ; preds = %29, %27
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @find_free_bit(i8* %0, i32 %1) {
%3 = icmp slt i32 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = add nuw i32 %1, 1
br label %6
6: ; preds = %4, %10
%7 = phi i32 [ %11, %10 ], [ 0, %4 ]
%8 = tail call i32 @get_bitmap(i8* %0, i32 %7, i32 %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %6
%11 = add nuw i32 %7, 1
%12 = icmp eq i32 %7, %1
br i1 %12, label %13, label %6
13: ; preds = %10
%14 = icmp eq i32 %8, -1
%15 = select i1 %14, i32 -1, i32 %5
br label %16
16: ; preds = %6, %2, %13
%17 = phi i32 [ 0, %2 ], [ %15, %13 ], [ %7, %6 ]
ret i32 %17
}