// File: /workspace/github_cpp_makefile_star2_O1/s-yata[P]louds-patricia/louds-patricia.cpp
// Function: louds::(anonymous namespace)::BitVector::build()
void build() {
    uint64_t n_blocks = words.size() / 4;
    uint64_t n_ones = 0;
    ranks.resize(n_blocks + 1);
    for (uint64_t block_id = 0; block_id < n_blocks; ++block_id) {
      ranks[block_id].set_abs(n_ones);
      for (uint64_t j = 0; j < 4; ++j) {
        if (j != 0) {
          uint64_t rel = n_ones - ranks[block_id].abs();
          ranks[block_id].rels[j - 1] = rel;
        }

        uint64_t word_id = (block_id * 4) + j;
        uint64_t word = words[word_id];
        uint64_t n_pops = Popcnt(word);
        uint64_t new_n_ones = n_ones + n_pops;
        if (((n_ones + 255) / 256) != ((new_n_ones + 255) / 256)) {
          uint64_t count = n_ones;
          while (word != 0) {
            uint64_t pos = Ctz(word);
            if (count % 256 == 0) {
              selects.push_back(((word_id * 64) + pos) / 256);
              break;
            }
            word ^= 1UL << pos;
            ++count;
          }
        }
        n_ones = new_n_ones;
      }
    }
    ranks.back().set_abs(n_ones);
    selects.push_back(words.size() * 64 / 256);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %r13
movq 0x18(%rdi), %rcx
subq (%rdi), %r13
sarq $0x3, %r13
movq %r13, %rdx
shrq $0x2, %rdx
leaq 0x1(%rdx), %rdi
movq 0x20(%rbx), %rax
movq %rax, %r14
subq %rcx, %r14
movq %r14, %r15
sarq $0x3, %r15
movq %rdx, 0x8(%rsp)
cmpq %rdx, %r15
jbe 0x2965
cmpq %r15, %rdi
jae 0x2b24
leaq (%rcx,%rdi,8), %rcx
cmpq %rcx, %rax
jne 0x2a50
jmp 0x2b24
movq %rdi, %rbp
subq %r15, %rbp
movq 0x28(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbp, %rcx
jae 0x29d0
movq %rdi, 0x10(%rsp)
movabsq $0xfffffffffffffff, %rax # imm = 0xFFFFFFFFFFFFFFF
movq %r15, %rcx
xorq %rax, %rcx
cmpq %rbp, %rcx
jb 0x2c79
cmpq %rbp, %r15
movq %rbp, %rcx
cmovaq %r15, %rcx
leaq (%rcx,%r15), %r12
cmpq %rax, %r12
cmovaeq %rax, %r12
addq %r15, %rcx
cmovbq %rax, %r12
testq %r12, %r12
je 0x2a59
leaq (,%r12,8), %rdi
callq 0x2180
jmp 0x2a5b
movq $0x0, (%rax)
cmpq $0x1, %rbp
jne 0x29e6
addq $0x8, %rax
movq %rax, %rcx
jmp 0x2a50
leaq (%rax,%rbp,8), %rcx
movq 0x8(%rsp), %rdx
leaq (,%rdx,8), %rdx
subq %r14, %rdx
addq $-0x8, %rdx
vpbroadcastq %rdx, %zmm0
shrq $0x3, %rdx
addq $0x8, %rdx
andq $-0x8, %rdx
vpsrlq $0x3, %zmm0, %zmm0
xorl %esi, %esi
vpmovsxbq 0x36a5(%rip), %zmm1 # 0x60c8
vpbroadcastq %rsi, %zmm2
vporq %zmm1, %zmm2, %zmm2
vpcmpleuq %zmm0, %zmm2, %k1
vpbroadcastq (%rax), %zmm2
vmovdqu64 %zmm2, 0x8(%rax,%rsi,8) {%k1}
addq $0x8, %rsi
cmpq %rsi, %rdx
jne 0x2a23
movq %rcx, 0x20(%rbx)
jmp 0x2b24
xorl %eax, %eax
movq $0x0, (%rax,%r15,8)
cmpq $0x1, %rbp
je 0x2ad3
leaq (%rax,%r15,8), %rdi
leaq 0x8(%rdi), %rcx
movq 0x8(%rsp), %rdx
leaq (,%rdx,8), %rdx
subq %r14, %rdx
addq $-0x8, %rdx
vpbroadcastq %rdx, %zmm0
shrq $0x3, %rdx
addq $0x8, %rdx
andq $-0x8, %rdx
vpsrlq $0x3, %zmm0, %zmm0
xorl %esi, %esi
vpmovsxbq 0x361e(%rip), %zmm1 # 0x60c8
vpbroadcastq %rsi, %zmm2
vporq %zmm1, %zmm2, %zmm2
vpcmpleuq %zmm0, %zmm2, %k1
vpbroadcastq (%rdi), %zmm2
vmovdqu64 %zmm2, (%rcx,%rsi,8) {%k1}
addq $0x8, %rsi
cmpq %rsi, %rdx
jne 0x2aaa
movq %rax, %r14
movq 0x18(%rbx), %r15
movq 0x20(%rbx), %rdx
subq %r15, %rdx
testq %rdx, %rdx
jle 0x2af4
movq %r14, %rdi
movq %r15, %rsi
vzeroupper
callq 0x21e0
testq %r15, %r15
je 0x2b0b
movq 0x28(%rbx), %rsi
subq %r15, %rsi
movq %r15, %rdi
vzeroupper
callq 0x2190
movq %r14, 0x18(%rbx)
movq 0x10(%rsp), %rax
leaq (%r14,%rax,8), %rax
movq %rax, 0x20(%rbx)
leaq (%r14,%r12,8), %rax
movq %rax, 0x28(%rbx)
cmpq $0x4, %r13
jae 0x2b32
xorl %r14d, %r14d
jmp 0x2c1c
leaq 0x30(%rbx), %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x18(%rbx), %rax
movq %r14, %rcx
shrq $0x8, %rcx
movl %ecx, (%rax,%rbp,8)
movb %r14b, 0x4(%rax,%rbp,8)
movq %rbp, %rax
shlq $0x5, %rax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
movq %r14, %r12
testq %r13, %r13
je 0x2b80
movq 0x18(%rbx), %rax
leaq (%rax,%rbp,8), %rcx
movb 0x4(%rax,%rbp,8), %al
movl %r12d, %edx
subb %al, %dl
movb %dl, 0x4(%r13,%rcx)
leaq (,%r13,8), %rax
addq (%rbx), %rax
movq 0x20(%rsp), %rcx
movq (%rcx,%rax), %r15
popcntq %r15, %r14
addq %r12, %r14
movl $0xff, %ecx
leaq (%r12,%rcx), %rax
addq %r14, %rcx
xorq %rax, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jb 0x2c01
testq %r15, %r15
je 0x2c01
testb %r12b, %r12b
je 0x2bca
blsrq %r15, %r15
leaq 0x1(%r12), %rax
jmp 0x2bf9
movl %ebp, 0x1c(%rsp)
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x2be4
movl %ebp, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x2bf6
movq 0x10(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
vzeroupper
callq 0x414e
movq %r12, %rax
testb %r12b, %r12b
movq %rax, %r12
jne 0x2bb4
incq %r13
cmpq $0x4, %r13
jne 0x2b62
incq %rbp
cmpq 0x8(%rsp), %rbp
jne 0x2b40
movq 0x20(%rbx), %rax
movq %r14, %rcx
shrq $0x8, %rcx
movl %ecx, -0x8(%rax)
movb %r14b, -0x4(%rax)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x5, %rax
movl %eax, 0x18(%rsp)
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x2c53
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x2c67
addq $0x30, %rbx
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
vzeroupper
callq 0x414e
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
leaq 0x3450(%rip), %rdi      # 0x60d0
callq 0x20b0
nop