#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 */
size_t BITMAP_N_LONGS(size_t);
unsigned long *bitmap_and(unsigned long *dst, const unsigned long *arg,
                          size_t n) {
  size_t i;
  for (i = 0; i < BITMAP_N_LONGS(n); i++) {
    dst[i] &= arg[i];
  }
  return dst;
}


x86 assembly (clang, -O0):
<bitmap_and>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <BITMAP_N_LONGS@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    117a <bitmap_and+0x6a>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
and    (%rax,%rcx,8),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <bitmap_and+0x1c>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_and>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rdx,%rdi
call   1030 <BITMAP_N_LONGS@plt>
test   %rax,%rax
je     1149 <bitmap_and+0x39>
xor    %ebx,%ebx
mov    (%r15,%rbx,8),%rax
and    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <BITMAP_N_LONGS@plt>
cmp    %rax,%rbx
jb     1130 <bitmap_and+0x20>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64* @bitmap_and(i64* %0, i64* %1, i64 %2) {
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
store i64* %0, i64** %4
store i64* %1, i64** %5
store i64 %2, i64* %6
store i64 0, i64* %7
br label %8
8: ; preds = %23, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %6
%11 = call i64 @BITMAP_N_LONGS(i64 %10)
%12 = icmp ult i64 %9, %11
br i1 %12, label %13, label %26
13: ; preds = %8
%14 = load i64*, i64** %5
%15 = load i64, i64* %7
%16 = getelementptr inbounds i64, i64* %14, i64 %15
%17 = load i64, i64* %16
%18 = load i64*, i64** %4
%19 = load i64, i64* %7
%20 = getelementptr inbounds i64, i64* %18, i64 %19
%21 = load i64, i64* %20
%22 = and i64 %21, %17
store i64 %22, i64* %20
br label %23
23: ; preds = %13
%24 = load i64, i64* %7
%25 = add i64 %24, 1
store i64 %25, i64* %7
br label %8
26: ; preds = %8
%27 = load i64*, i64** %4
ret i64* %27
}

LLVM IR (-O2):
define i64* @bitmap_and(i64* returned %0, i64* nocapture %1, i64 %2) {
%4 = tail call i64 @BITMAP_N_LONGS(i64 %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %13, %6 ], [ 0, %3 ]
%8 = getelementptr inbounds i64, i64* %1, i64 %7
%9 = load i64, i64* %8
%10 = getelementptr inbounds i64, i64* %0, i64 %7
%11 = load i64, i64* %10
%12 = and i64 %11, %9
store i64 %12, i64* %10
%13 = add nuw i64 %7, 1
%14 = tail call i64 @BITMAP_N_LONGS(i64 %2)
%15 = icmp ult i64 %13, %14
br i1 %15, label %6, label %16
16: ; preds = %6, %3
ret i64* %0
}