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


x86 assembly (clang, -O0):
<bitmap_full>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x40,%rax
ja     119c <bitmap_full+0x8c>
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     116b <bitmap_full+0x5b>
movslq -0x14(%rbp),%rcx
and    $0x3f,%rcx
mov    $0x1,%eax
shl    %cl,%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117b <bitmap_full+0x6b>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    117b <bitmap_full+0x6b>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
and    %rcx,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <bitmap_full+0x9b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <slow_bitmap_full@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_full>:
cmp    $0x40,%esi
ja     113f <bitmap_full+0x2f>
mov    (%rdi),%rdx
not    %rdx
and    $0x3f,%esi
mov    $0xffffffffffffffff,%rax
mov    %esi,%ecx
shl    %cl,%rax
not    %rax
cmp    $0x1,%esi
sbb    %rcx,%rcx
or     %rax,%rcx
xor    %eax,%eax
test   %rdx,%rcx
sete   %al
ret
jmp    1030 <slow_bitmap_full@plt>

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

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