#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*/ slow_bitmap_complement(unsigned long *,
                                          unsigned long const *, int);
void bitmap_complement(unsigned long *dst, const unsigned long *src,
                       int nbits) {
  if (((nbits) <= (sizeof(unsigned long) * 8))) {
    *dst = ~(*src) & (((nbits) % (sizeof(unsigned long) * 8))
                          ? (1UL << ((nbits) % (sizeof(unsigned long) * 8))) - 1
                          : ~0UL);
  } else {
    slow_bitmap_complement(dst, src, nbits);
  }
}


x86 assembly (clang, -O0):
<bitmap_complement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x40,%rax
ja     1196 <bitmap_complement+0x86>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
xor    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
movslq -0x14(%rbp),%rax
and    $0x3f,%rax
cmp    $0x0,%rax
je     116f <bitmap_complement+0x5f>
movslq -0x14(%rbp),%rcx
and    $0x3f,%rcx
mov    $0x1,%eax
shl    %cl,%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117f <bitmap_complement+0x6f>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    117f <bitmap_complement+0x6f>
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
and    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11a6 <bitmap_complement+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <slow_bitmap_complement@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_complement>:
cmp    $0x40,%edx
ja     113d <bitmap_complement+0x2d>
mov    (%rsi),%rax
and    $0x3f,%edx
mov    $0xffffffffffffffff,%rsi
mov    %edx,%ecx
shl    %cl,%rsi
not    %rax
cmp    $0x1,%edx
sbb    %rcx,%rcx
not    %rsi
or     %rsi,%rcx
and    %rax,%rcx
mov    %rcx,(%rdi)
ret
jmp    1030 <slow_bitmap_complement@plt>

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

LLVM IR (-O2):
define void @bitmap_complement(i64* %0, i64* %1, i32 %2) {
%4 = icmp ult i32 %2, 65
br i1 %4, label %5, label %15
5: ; preds = %3
%6 = load i64, i64* %1
%7 = xor i64 %6, -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 %13, %7
store i64 %14, i64* %0
br label %17
15: ; preds = %3
%16 = tail call i32 @slow_bitmap_complement(i64* %0, i64* %1, i32 %2)
br label %17
17: ; preds = %15, %5
ret void
}