// File: /workspace/github_cpp_makefile_star2_O2/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 0x8(%rdi), %rdx
movq %rdi, %rbx
movq 0x18(%rdi), %rcx
subq (%rdi), %rdx
movq 0x20(%rdi), %rdi
sarq $0x3, %rdx
movq %rdi, %r15
subq %rcx, %r15
shrq $0x2, %rdx
movq %r15, %rax
sarq $0x3, %rax
leaq 0x1(%rdx), %r14
movq %rdx, 0x18(%rsp)
cmpq %rdx, %rax
jbe 0x28be
cmpq %rax, %r14
jae 0x2970
leaq (%rcx,%r14,8), %rax
cmpq %rax, %rdi
jne 0x296c
jmp 0x2970
movq 0x28(%rbx), %rcx
subq %rax, %r14
subq %rdi, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jae 0x2964
movabsq $0xfffffffffffffff, %rcx # imm = 0xFFFFFFFFFFFFFFF
movq %rax, %rdx
xorq %rcx, %rdx
cmpq %r14, %rdx
jb 0x2a65
cmpq %r14, %rax
movq %r14, %rbp
cmovaq %rax, %rbp
addq %rax, %rbp
cmpq %rcx, %rbp
cmovaeq %rcx, %rbp
leaq (,%rbp,8), %rdi
callq 0x2160
addq %rax, %r15
movq %rax, %r12
movq %r14, %rsi
movq %r15, %rdi
callq 0x2aca
movq 0x18(%rbx), %r13
movq 0x20(%rbx), %rdx
subq %r13, %rdx
testq %rdx, %rdx
jle 0x293b
movq %r12, %rdi
movq %r13, %rsi
callq 0x21d0
movq 0x28(%rbx), %rsi
movq %r13, %rdi
subq %r13, %rsi
sarq $0x3, %rsi
callq 0x24da
leaq (%r15,%r14,8), %rax
leaq (%r12,%rbp,8), %rcx
movq %r12, 0x18(%rbx)
movq %rax, 0x20(%rbx)
movq %rcx, 0x28(%rbx)
jmp 0x2970
movq %r14, %rsi
callq 0x2aca
movq %rax, 0x20(%rbx)
leaq 0x30(%rbx), %rax
movl $0xff, %r13d
xorl %r12d, %r12d
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movq %rax, %rcx
shrq $0x8, %rcx
cmpq 0x18(%rsp), %r12
je 0x2a30
movq 0x18(%rbx), %rdx
leaq (,%r12,4), %rbp
xorl %r15d, %r15d
movl %ecx, (%rdx,%r12,8)
movb %al, 0x4(%rdx,%r12,8)
testq %r15, %r15
je 0x29d0
cmpq $0x4, %r15
je 0x2a28
movq 0x18(%rbx), %rcx
movl %eax, %esi
leaq (%rcx,%r12,8), %rdx
movb 0x4(%rcx,%r12,8), %cl
subb %cl, %sil
movb %sil, 0x4(%r15,%rdx)
movq (%rbx), %rdx
movq %r15, %rcx
orq %rbp, %rcx
movq (%rdx,%rcx,8), %rcx
leaq (%rax,%r13), %rdx
popcntq %rcx, %r14
addq %rax, %r14
leaq (%r14,%r13), %rsi
xorq %rdx, %rsi
cmpq $0x100, %rsi            # imm = 0x100
jb 0x2a20
testq %rcx, %rcx
je 0x2a20
testb %al, %al
je 0x2a0c
blsrq %rcx, %rcx
incq %rax
jmp 0x29f9
movq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movl %r12d, 0xc(%rsp)
callq 0x3c82
incq %r15
movq %r14, %rax
jmp 0x29ae
incq %r12
jmp 0x2984
movq 0x20(%rbx), %rdx
movq 0x10(%rsp), %rdi
leaq 0x24(%rsp), %rsi
movl %ecx, -0x8(%rdx)
movb %al, -0x4(%rdx)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x5, %rax
movl %eax, (%rsi)
callq 0x3c82
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25b4(%rip), %rdi      # 0x5020
callq 0x20d0
nop