#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*/ bit_set_or_not(unsigned char *, int);
int bitmap_scan(unsigned char *bitmap, int size) {
  int j;
  for (j = 0; j < (size * 8); j++) {
    if (!bit_set_or_not(bitmap, j))
      return j;
  }
  return -1;
}


x86 assembly (clang, -O0):
<bitmap_scan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x3,%ecx
cmp    %ecx,%eax
jge    116a <bitmap_scan+0x5a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <bit_set_or_not@plt>
cmp    $0x0,%eax
jne    1157 <bitmap_scan+0x47>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1171 <bitmap_scan+0x61>
jmp    115c <bitmap_scan+0x4c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1126 <bitmap_scan+0x16>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_scan>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
test   %esi,%esi
jle    115a <bitmap_scan+0x4a>
mov    %rdi,%r15
shl    $0x3,%esi
cmp    $0x2,%esi
mov    $0x1,%ebx
cmovge %esi,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <bit_set_or_not@plt>
test   %eax,%eax
je     1157 <bitmap_scan+0x47>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1140 <bitmap_scan+0x30>
jmp    115a <bitmap_scan+0x4a>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bitmap_scan(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %20, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %5
%10 = mul nsw i32 %9, 8
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %23
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = load i32, i32* %6
%15 = call i32 @bit_set_or_not(i8* %13, i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %24
19: ; preds = %12
br label %20
20: ; preds = %19
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %7
23: ; preds = %7
store i32 -1, i32* %3
br label %24
24: ; preds = %23, %17
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @bitmap_scan(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = shl i32 %1, 3
%6 = call i32 @llvm.smax.i32(i32 %5, i32 1)
br label %7
7: ; preds = %4, %11
%8 = phi i32 [ %12, %11 ], [ 0, %4 ]
%9 = tail call i32 @bit_set_or_not(i8* %0, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = add nuw nsw i32 %8, 1
%13 = icmp eq i32 %12, %6
br i1 %13, label %14, label %7
14: ; preds = %7, %11, %2
%15 = phi i32 [ -1, %2 ], [ -1, %11 ], [ %8, %7 ]
ret i32 %15
}