#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 __WORDSIZE;
int /*<<< orphan*/ memset(unsigned long *, int, int);
void bitmap_fill(unsigned long *dst, int nbits) {
  size_t nlongs = ((nbits + __WORDSIZE - 1) / __WORDSIZE);
  if (nlongs > 1) {
    int len = (nlongs - 1) * sizeof(unsigned long);
    memset(dst, 0xff, len);
  }
  dst[nlongs - 1] =
      (((nbits) % __WORDSIZE) ? (1UL << ((nbits) % __WORDSIZE)) - 1 : ~0UL);
}


x86 assembly (clang, -O0):
<bitmap_fill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ebf(%rip),%rcx
add    (%rcx),%eax
sub    $0x1,%eax
mov    0x2eb3(%rip),%rcx
cltd
idivl  (%rcx)
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jbe    1169 <bitmap_fill+0x59>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
shl    $0x3,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0xff,%esi
call   1030 <memset@plt>
mov    -0xc(%rbp),%eax
mov    0x2e75(%rip),%rcx
cltd
idivl  (%rcx)
cmp    $0x0,%edx
je     11a5 <bitmap_fill+0x95>
mov    -0xc(%rbp),%eax
mov    0x2e5f(%rip),%rcx
cltd
idivl  (%rcx)
mov    %edx,%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11b5 <bitmap_fill+0xa5>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    11b5 <bitmap_fill+0xa5>
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
mov    %rdx,(%rax,%rcx,8)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_fill>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    0x2ec3(%rip),%r12
mov    (%r12),%ecx
lea    (%r15,%rcx,1),%eax
add    $0xffffffff,%eax
cltd
idiv   %ecx
mov    %eax,%ebx
cmp    $0x2,%eax
jb     1152 <bitmap_fill+0x42>
lea    -0x8(,%rbx,8),%edx
mov    %r14,%rdi
mov    $0xff,%esi
call   1030 <memset@plt>
mov    (%r12),%ecx
mov    %r15d,%eax
cltd
idiv   %ecx
mov    %edx,%ecx
mov    $0xffffffffffffffff,%rax
shl    %cl,%rax
cmp    $0x1,%edx
sbb    %rcx,%rcx
not    %rax
or     %rax,%rcx
movslq %ebx,%rax
mov    %rcx,-0x8(%r14,%rax,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__WORDSIZE = global i32 0
define void @bitmap_fill(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i64* %0, i64** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = load i32, i32* @__WORDSIZE
%9 = add nsw i32 %7, %8
%10 = sub nsw i32 %9, 1
%11 = load i32, i32* @__WORDSIZE
%12 = sdiv i32 %10, %11
%13 = sext i32 %12 to i64
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = icmp ugt i64 %14, 1
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i64, i64* %5
%18 = sub i64 %17, 1
%19 = mul i64 %18, 8
%20 = trunc i64 %19 to i32
store i32 %20, i32* %6
%21 = load i64*, i64** %3
%22 = load i32, i32* %6
%23 = call i32 @memset(i64* %21, i32 255, i32 %22)
br label %24
24: ; preds = %16, %2
%25 = load i32, i32* %4
%26 = load i32, i32* @__WORDSIZE
%27 = srem i32 %25, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = load i32, i32* %4
%31 = load i32, i32* @__WORDSIZE
%32 = srem i32 %30, %31
%33 = zext i32 %32 to i64
%34 = shl i64 1, %33
%35 = sub i64 %34, 1
br label %37
36: ; preds = %24
br label %37
37: ; preds = %36, %29
%38 = phi i64 [ %35, %29 ], [ -1, %36 ]
%39 = load i64*, i64** %3
%40 = load i64, i64* %5
%41 = sub i64 %40, 1
%42 = getelementptr inbounds i64, i64* %39, i64 %41
store i64 %38, i64* %42
ret void
}

LLVM IR (-O2):
@__WORDSIZE = global i32 0
define void @bitmap_fill(i64* %0, i32 %1) {
%3 = load i32, i32* @__WORDSIZE
%4 = add i32 %1, -1
%5 = add i32 %4, %3
%6 = sdiv i32 %5, %3
%7 = icmp ugt i32 %6, 1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = shl i32 %6, 3
%10 = add i32 %9, -8
%11 = tail call i32 @memset(i64* %0, i32 255, i32 %10)
%12 = load i32, i32* @__WORDSIZE
br label %13
13: ; preds = %8, %2
%14 = phi i32 [ %12, %8 ], [ %3, %2 ]
%15 = srem i32 %1, %14
%16 = icmp eq i32 %15, 0
%17 = zext i32 %15 to i64
%18 = shl nsw i64 -1, %17
%19 = xor i64 %18, -1
%20 = select i1 %16, i64 -1, i64 %19
%21 = sext i32 %6 to i64
%22 = add nsw i64 %21, -1
%23 = getelementptr inbounds i64, i64* %0, i64 %22
store i64 %20, i64* %23
ret void
}