#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 */
typedef int /*<<< orphan*/ n;

/* Variables and functions */
int /*<<< orphan*/ bitmap_zero(unsigned long *, int);
int find_first_bit(unsigned long const *, int);
int find_next_bit(unsigned long const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ set_bit(int, unsigned long *);
scalar_t__ test_bit(int, unsigned long const *);
void bitmap_onto(unsigned long *dst, const unsigned long *orig,
                 const unsigned long *relmap, int bits) {
  int n, m;
  if (dst == orig)
    return;
  bitmap_zero(dst, bits);
  m = 0;
  for ((n) = find_first_bit((relmap), (bits)); (n) < (bits);
       (n) = find_next_bit((relmap), (bits), (n) + 1)) {
    if (test_bit(m, orig))
      set_bit(n, dst);
    m++;
  }
}


x86 assembly (clang, -O0):
<bitmap_onto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    117a <bitmap_onto+0x2a>
jmp    11ed <bitmap_onto+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <bitmap_zero@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <find_first_bit@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ed <bitmap_onto+0x9d>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <test_bit@plt>
cmp    $0x0,%rax
je     11ca <bitmap_onto+0x7a>
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <set_bit@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1050 <find_next_bit@plt>
mov    %eax,-0x20(%rbp)
jmp    119c <bitmap_onto+0x4c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_onto>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %rsi,%rdi
je     11c5 <bitmap_onto+0x75>
mov    %ecx,%r13d
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %ecx,%esi
call   1030 <bitmap_zero@plt>
mov    %r14,%rdi
mov    %r13d,%esi
call   1060 <find_first_bit@plt>
cmp    %r13d,%eax
jge    11c5 <bitmap_onto+0x75>
mov    %eax,%ebp
xor    %ebx,%ebx
jmp    11aa <bitmap_onto+0x5a>
nopl   0x0(%rax)
add    $0x1,%ebx
add    $0x1,%ebp
mov    %r14,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
call   1050 <find_next_bit@plt>
mov    %eax,%ebp
cmp    %r13d,%eax
jge    11c5 <bitmap_onto+0x75>
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <test_bit@plt>
test   %rax,%rax
je     1190 <bitmap_onto+0x40>
mov    %ebp,%edi
mov    %r12,%rsi
call   1040 <set_bit@plt>
jmp    1190 <bitmap_onto+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @bitmap_onto(i64* %0, i64* %1, i64* %2, i32 %3) {
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i64* %0, i64** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
store i32 %3, i32* %8
%11 = load i64*, i64** %5
%12 = load i64*, i64** %6
%13 = icmp eq i64* %11, %12
br i1 %13, label %14, label %15
14: ; preds = %4
br label %44
15: ; preds = %4
%16 = load i64*, i64** %5
%17 = load i32, i32* %8
%18 = call i32 @bitmap_zero(i64* %16, i32 %17)
store i32 0, i32* %10
%19 = load i64*, i64** %7
%20 = load i32, i32* %8
%21 = call i32 @find_first_bit(i64* %19, i32 %20)
store i32 %21, i32* %9
br label %22
22: ; preds = %38, %15
%23 = load i32, i32* %9
%24 = load i32, i32* %8
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %44
26: ; preds = %22
%27 = load i32, i32* %10
%28 = load i64*, i64** %6
%29 = call i64 @test_bit(i32 %27, i64* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* %9
%33 = load i64*, i64** %5
%34 = call i32 @set_bit(i32 %32, i64* %33)
br label %35
35: ; preds = %31, %26
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %38
38: ; preds = %35
%39 = load i64*, i64** %7
%40 = load i32, i32* %8
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
%43 = call i32 @find_next_bit(i64* %39, i32 %40, i32 %42)
store i32 %43, i32* %9
br label %22
44: ; preds = %14, %22
ret void
}

LLVM IR (-O2):
define void @bitmap_onto(i64* %0, i64* %1, i64* %2, i32 %3) {
%5 = icmp eq i64* %0, %1
br i1 %5, label %22, label %6
6: ; preds = %4
%7 = tail call i32 @bitmap_zero(i64* %0, i32 %3)
%8 = tail call i32 @find_first_bit(i64* %2, i32 %3)
%9 = icmp slt i32 %8, %3
br i1 %9, label %10, label %22
10: ; preds = %6, %17
%11 = phi i32 [ %18, %17 ], [ 0, %6 ]
%12 = phi i32 [ %20, %17 ], [ %8, %6 ]
%13 = tail call i64 @test_bit(i32 %11, i64* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = tail call i32 @set_bit(i32 %12, i64* %0)
br label %17
17: ; preds = %15, %10
%18 = add nuw nsw i32 %11, 1
%19 = add nsw i32 %12, 1
%20 = tail call i32 @find_next_bit(i64* %2, i32 %3, i32 %19)
%21 = icmp slt i32 %20, %3
br i1 %21, label %10, label %22
22: ; preds = %17, %6, %4
ret void
}