#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 slow_bitmap_intersects(unsigned long const *, unsigned long const *, int);
int bitmap_intersects(const unsigned long *src1, const unsigned long *src2,
                      int nbits) {
  if (((nbits) <= (sizeof(unsigned long) * 8))) {
    return ((*src1 & *src2) &
            (((nbits) % (sizeof(unsigned long) * 8))
                 ? (1UL << ((nbits) % (sizeof(unsigned long) * 8))) - 1
                 : ~0UL)) != 0;
  } else {
    return slow_bitmap_intersects(src1, src2, nbits);
  }
}


x86 assembly (clang, -O0):
<bitmap_intersects>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x40,%rax
ja     11a1 <bitmap_intersects+0x91>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
and    (%rcx),%rax
mov    %rax,-0x28(%rbp)
movslq -0x1c(%rbp),%rax
and    $0x3f,%rax
cmp    $0x0,%rax
je     1172 <bitmap_intersects+0x62>
movslq -0x1c(%rbp),%rcx
and    $0x3f,%rcx
mov    $0x1,%eax
shl    %cl,%rax
sub    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1182 <bitmap_intersects+0x72>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1182 <bitmap_intersects+0x72>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
and    %rcx,%rax
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <bitmap_intersects+0xa4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <slow_bitmap_intersects@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_intersects>:
cmp    $0x40,%edx
ja     113c <bitmap_intersects+0x2c>
and    $0x3f,%edx
mov    $0xffffffffffffffff,%rax
mov    %edx,%ecx
shl    %cl,%rax
cmp    $0x1,%edx
sbb    %rcx,%rcx
not    %rax
or     %rax,%rcx
and    (%rdi),%rcx
xor    %eax,%eax
test   %rcx,(%rsi)
setne  %al
ret
jmp    1030 <slow_bitmap_intersects@plt>

LLVM IR (-O0):
define i32 @bitmap_intersects(i64* %0, i64* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i32
store i64* %0, i64** %5
store i64* %1, i64** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = sext i32 %8 to i64
%10 = icmp ule i64 %9, 64
br i1 %10, label %11, label %33
11: ; preds = %3
%12 = load i64*, i64** %5
%13 = load i64, i64* %12
%14 = load i64*, i64** %6
%15 = load i64, i64* %14
%16 = and i64 %13, %15
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = urem i64 %18, 64
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %11
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = urem i64 %23, 64
%25 = shl i64 1, %24
%26 = sub i64 %25, 1
br label %28
27: ; preds = %11
br label %28
28: ; preds = %27, %21
%29 = phi i64 [ %26, %21 ], [ -1, %27 ]
%30 = and i64 %16, %29
%31 = icmp ne i64 %30, 0
%32 = zext i1 %31 to i32
store i32 %32, i32* %4
br label %38
33: ; preds = %3
%34 = load i64*, i64** %5
%35 = load i64*, i64** %6
%36 = load i32, i32* %7
%37 = call i32 @slow_bitmap_intersects(i64* %34, i64* %35, i32 %36)
store i32 %37, i32* %4
br label %38
38: ; preds = %33, %28
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
define i32 @bitmap_intersects(i64* %0, i64* %1, i32 %2) {
%4 = icmp ult i32 %2, 65
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = load i64, i64* %0
%7 = load i64, i64* %1
%8 = and i32 %2, 63
%9 = icmp eq i32 %8, 0
%10 = zext i32 %8 to i64
%11 = shl nsw i64 -1, %10
%12 = xor i64 %11, -1
%13 = select i1 %9, i64 -1, i64 %12
%14 = and i64 %6, %13
%15 = and i64 %14, %7
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i32
br label %20
18: ; preds = %3
%19 = tail call i32 @slow_bitmap_intersects(i64* %0, i64* %1, i32 %2)
br label %20
20: ; preds = %18, %5
%21 = phi i32 [ %17, %5 ], [ %19, %18 ]
ret i32 %21
}