#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 */
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
int search_bitmap(unsigned char *bitmap, unsigned char *table, int size) {
  int c;
  for (c = 0; c < size; c++) {
    if (memcmp(&table[c * 8], &bitmap[0], 8) == 0)
      return c;
  }
  return size;
}


x86 assembly (clang, -O0):
<search_bitmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    117b <search_bitmap+0x6b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1168 <search_bitmap+0x58>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <search_bitmap+0x71>
jmp    116d <search_bitmap+0x5d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <search_bitmap+0x1a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_bitmap>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
test   %edx,%edx
jle    1157 <search_bitmap+0x47>
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1154 <search_bitmap+0x44>
add    $0x1,%rbx
add    $0x8,%r12
cmp    %rbx,%r14
jne    1130 <search_bitmap+0x20>
jmp    1157 <search_bitmap+0x47>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @search_bitmap(i8* %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %13
%8 = phi i64 [ 0, %5 ], [ %14, %13 ]
%9 = shl nsw i64 %8, 3
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = tail call i64 @memcmp(i8* %10, i8* %0, i32 8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %18, label %7
16: ; preds = %7
%17 = trunc i64 %8 to i32
br label %18
18: ; preds = %13, %16, %3
%19 = phi i32 [ %2, %3 ], [ %17, %16 ], [ %2, %13 ]
ret i32 %19
}