#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*/ bit_array_set(void *, size_t);
scalar_t__ bit_array_test(void *, size_t);
void bit_array_merge(void *dest, void *source, size_t offset) {
  if (dest && source) {
    size_t *dsize = (size_t *)dest;
    size_t *ssize = (size_t *)source;
    size_t soffset = 0;
    while (offset < *dsize && soffset < *ssize) {
      if (bit_array_test(source, soffset)) {
        bit_array_set(dest, offset);
      }
      soffset++;
      offset++;
    }
  }
}


x86 assembly (clang, -O0):
<bit_array_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11df <bit_array_merge+0xbf>
cmpq   $0x0,-0x10(%rbp)
je     11df <bit_array_merge+0xbf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
mov    %al,-0x31(%rbp)
jae    1189 <bit_array_merge+0x69>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%rax
setb   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1199 <bit_array_merge+0x79>
jmp    11da <bit_array_merge+0xba>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <bit_array_test@plt>
cmp    $0x0,%rax
je     11bd <bit_array_merge+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <bit_array_set@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1162 <bit_array_merge+0x42>
jmp    11df <bit_array_merge+0xbf>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_array_merge>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1185 <bit_array_merge+0x65>
mov    %rsi,%r12
test   %rsi,%rsi
je     1185 <bit_array_merge+0x65>
mov    %rdx,%r14
mov    %rdi,%r15
cmp    %rdx,(%rdi)
jbe    1185 <bit_array_merge+0x65>
xor    %ebx,%ebx
jmp    1161 <bit_array_merge+0x41>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    (%r15),%rax
jae    1185 <bit_array_merge+0x65>
cmp    (%r12),%rbx
jae    1185 <bit_array_merge+0x65>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <bit_array_test@plt>
test   %rax,%rax
je     1150 <bit_array_merge+0x30>
lea    (%r14,%rbx,1),%rsi
mov    %r15,%rdi
call   1030 <bit_array_set@plt>
jmp    1150 <bit_array_merge+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @bit_array_merge(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %47
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %47
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = bitcast i8* %16 to i64*
store i64* %17, i64** %7
%18 = load i8*, i8** %5
%19 = bitcast i8* %18 to i64*
store i64* %19, i64** %8
store i64 0, i64* %9
br label %20
20: ; preds = %41, %15
%21 = load i64, i64* %6
%22 = load i64*, i64** %7
%23 = load i64, i64* %22
%24 = icmp ult i64 %21, %23
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i64, i64* %9
%27 = load i64*, i64** %8
%28 = load i64, i64* %27
%29 = icmp ult i64 %26, %28
br label %30
30: ; preds = %25, %20
%31 = phi i1 [ false, %20 ], [ %29, %25 ]
br i1 %31, label %32, label %46
32: ; preds = %30
%33 = load i8*, i8** %5
%34 = load i64, i64* %9
%35 = call i64 @bit_array_test(i8* %33, i64 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i8*, i8** %4
%39 = load i64, i64* %6
%40 = call i32 @bit_array_set(i8* %38, i64 %39)
br label %41
41: ; preds = %37, %32
%42 = load i64, i64* %9
%43 = add i64 %42, 1
store i64 %43, i64* %9
%44 = load i64, i64* %6
%45 = add i64 %44, 1
store i64 %45, i64* %6
br label %20
46: ; preds = %30
br label %47
47: ; preds = %46, %12, %3
ret void
}

LLVM IR (-O2):
define void @bit_array_merge(i8* %0, i8* %1, i64 %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
br i1 %6, label %7, label %27
7: ; preds = %3
%8 = bitcast i8* %0 to i64*
%9 = bitcast i8* %1 to i64*
%10 = load i64, i64* %8
%11 = icmp ugt i64 %10, %2
br i1 %11, label %12, label %27
12: ; preds = %7, %22
%13 = phi i64 [ %23, %22 ], [ 0, %7 ]
%14 = phi i64 [ %24, %22 ], [ %2, %7 ]
%15 = load i64, i64* %9
%16 = icmp ult i64 %13, %15
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = tail call i64 @bit_array_test(i8* %1, i64 %13)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @bit_array_set(i8* %0, i64 %14)
br label %22
22: ; preds = %20, %17
%23 = add nuw i64 %13, 1
%24 = add nuw i64 %14, 1
%25 = load i64, i64* %8
%26 = icmp ult i64 %24, %25
br i1 %26, label %12, label %27
27: ; preds = %22, %12, %7, %3
ret void
}