// File: /workspace/github_c_makefile_star2_O1/FastFilter[P]BlockBloomSimulator/src/bitset.c
// Function: bitset_count
size_t bitset_count(const bitset_t *bitset) {
    size_t card = 0;
    size_t k = 0;
    // assumes that long long is 8 bytes
    for(; k + 7 < bitset->arraysize; k+=8) {
        card += __builtin_popcountll(bitset->array[k]);
        card += __builtin_popcountll(bitset->array[k+1]);
        card += __builtin_popcountll(bitset->array[k+2]);
        card += __builtin_popcountll(bitset->array[k+3]);
        card += __builtin_popcountll(bitset->array[k+4]);
        card += __builtin_popcountll(bitset->array[k+5]);
        card += __builtin_popcountll(bitset->array[k+6]);
        card += __builtin_popcountll(bitset->array[k+7]);
    }
    for(; k + 3 < bitset->arraysize; k+=4) {
        card += __builtin_popcountll(bitset->array[k]);
        card += __builtin_popcountll(bitset->array[k+1]);
        card += __builtin_popcountll(bitset->array[k+2]);
        card += __builtin_popcountll(bitset->array[k+3]);
    }
    for(; k < bitset->arraysize; k++) {
        card += __builtin_popcountll(bitset->array[k]);
    }
    return card;
}

// Assembly:
pushq %rbx
movq 0x8(%rdi), %rcx
cmpq $0x8, %rcx
jb 0x2c6e
movq (%rdi), %rdx
xorl %esi, %esi
movdqa 0x1a6e(%rip), %xmm0     # 0x4590
movdqa 0x1a76(%rip), %xmm1     # 0x45a0
movdqa 0x1a7e(%rip), %xmm2     # 0x45b0
pxor %xmm3, %xmm3
xorl %eax, %eax
movdqu (%rdx,%rsi,8), %xmm7
movdqu 0x10(%rdx,%rsi,8), %xmm4
movdqu 0x20(%rdx,%rsi,8), %xmm6
movdqu 0x30(%rdx,%rsi,8), %xmm5
movdqa %xmm6, %xmm8
psrlw $0x1, %xmm8
pand %xmm0, %xmm8
psubb %xmm8, %xmm6
movdqa %xmm6, %xmm8
pand %xmm1, %xmm8
psrlw $0x2, %xmm6
pand %xmm1, %xmm6
paddb %xmm8, %xmm6
movdqa %xmm6, %xmm8
psrlw $0x4, %xmm8
paddb %xmm6, %xmm8
pand %xmm2, %xmm8
movdqa %xmm7, %xmm6
psrlw $0x1, %xmm6
pand %xmm0, %xmm6
psubb %xmm6, %xmm7
movdqa %xmm7, %xmm6
pand %xmm1, %xmm6
psrlw $0x2, %xmm7
pand %xmm1, %xmm7
paddb %xmm6, %xmm7
movdqa %xmm7, %xmm6
psrlw $0x4, %xmm6
paddb %xmm7, %xmm6
pand %xmm2, %xmm6
paddb %xmm8, %xmm6
movdqa %xmm5, %xmm7
psrlw $0x1, %xmm7
pand %xmm0, %xmm7
psubb %xmm7, %xmm5
movdqa %xmm5, %xmm7
pand %xmm1, %xmm7
psrlw $0x2, %xmm5
pand %xmm1, %xmm5
paddb %xmm7, %xmm5
movdqa %xmm5, %xmm7
psrlw $0x4, %xmm7
paddb %xmm5, %xmm7
pand %xmm2, %xmm7
movdqa %xmm4, %xmm5
psrlw $0x1, %xmm5
pand %xmm0, %xmm5
psubb %xmm5, %xmm4
movdqa %xmm4, %xmm5
pand %xmm1, %xmm5
psrlw $0x2, %xmm4
pand %xmm1, %xmm4
paddb %xmm5, %xmm4
movdqa %xmm4, %xmm5
psrlw $0x4, %xmm5
paddb %xmm4, %xmm5
pand %xmm2, %xmm5
paddb %xmm7, %xmm5
paddb %xmm6, %xmm5
psadbw %xmm3, %xmm5
pshufd $0xee, %xmm5, %xmm4     # xmm4 = xmm5[2,3,2,3]
paddq %xmm5, %xmm4
movq %xmm4, %r8
addq %r8, %rax
leaq 0x8(%rsi), %r8
addq $0xf, %rsi
cmpq %rcx, %rsi
movq %r8, %rsi
jb 0x2b38
jmp 0x2c73
xorl %eax, %eax
xorl %r8d, %r8d
movq %r8, %rdx
orq $0x3, %rdx
cmpq %rcx, %rdx
jae 0x2d4c
movq (%rdi), %rdx
movdqa 0x1902(%rip), %xmm0     # 0x4590
movdqa 0x190a(%rip), %xmm1     # 0x45a0
movdqa 0x1912(%rip), %xmm2     # 0x45b0
pxor %xmm3, %xmm3
movdqu (%rdx,%r8,8), %xmm4
movdqu 0x10(%rdx,%r8,8), %xmm5
movdqa %xmm5, %xmm6
psrlw $0x1, %xmm6
pand %xmm0, %xmm6
psubb %xmm6, %xmm5
movdqa %xmm5, %xmm6
pand %xmm1, %xmm6
psrlw $0x2, %xmm5
pand %xmm1, %xmm5
paddb %xmm6, %xmm5
movdqa %xmm5, %xmm6
psrlw $0x4, %xmm6
paddb %xmm5, %xmm6
pand %xmm2, %xmm6
movdqa %xmm4, %xmm5
psrlw $0x1, %xmm5
pand %xmm0, %xmm5
psubb %xmm5, %xmm4
movdqa %xmm4, %xmm5
pand %xmm1, %xmm5
psrlw $0x2, %xmm4
pand %xmm1, %xmm4
paddb %xmm5, %xmm4
movdqa %xmm4, %xmm5
psrlw $0x4, %xmm5
paddb %xmm4, %xmm5
pand %xmm2, %xmm5
paddb %xmm6, %xmm5
psadbw %xmm3, %xmm5
pshufd $0xee, %xmm5, %xmm4     # xmm4 = xmm5[2,3,2,3]
paddq %xmm5, %xmm4
movq %xmm4, %rsi
addq %rsi, %rax
leaq 0x4(%r8), %rsi
addq $0x7, %r8
cmpq %rcx, %r8
movq %rsi, %r8
jb 0x2ca2
jmp 0x2d4f
movq %r8, %rsi
cmpq %rcx, %rsi
jae 0x2dbf
movq (%rdi), %rdx
movabsq $0x5555555555555555, %rdi # imm = 0x5555555555555555
movabsq $0x3333333333333333, %r8 # imm = 0x3333333333333333
movabsq $0xf0f0f0f0f0f0f0f, %r9 # imm = 0xF0F0F0F0F0F0F0F
movabsq $0x101010101010101, %r10 # imm = 0x101010101010101
movq (%rdx,%rsi,8), %r11
movq %r11, %rbx
shrq %rbx
andq %rdi, %rbx
subq %rbx, %r11
movq %r11, %rbx
andq %r8, %rbx
shrq $0x2, %r11
andq %r8, %r11
addq %rbx, %r11
movq %r11, %rbx
shrq $0x4, %rbx
addq %r11, %rbx
andq %r9, %rbx
imulq %r10, %rbx
shrq $0x38, %rbx
addq %rbx, %rax
incq %rsi
cmpq %rsi, %rcx
jne 0x2d7f
popq %rbx
retq