// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq 0x8(%rdi), %r13
movq 0x20(%rdi), %rax
movq 0x18(%rdi), %rdx
movq %rdi, %rbx
subq (%rdi), %r13
movq %rax, %r15
subq %rdx, %r15
sarq $0x3, %r13
movq %r15, %rcx
sarq $0x3, %rcx
movq %r13, %rsi
shrq $0x2, %rsi
leaq 0x1(%rsi), %rbp
movq %rsi, 0x8(%rsp)
cmpq %rsi, %rcx
jbe 0x294d
cmpq %rcx, %rbp
jae 0x2af4
leaq (%rdx,%rbp,8), %rcx
cmpq %rcx, %rax
jne 0x2aed
jmp 0x2af4
movq 0x28(%rbx), %rdx
subq %rcx, %rbp
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbp, %rdx
jae 0x2a6d
movabsq $0xfffffffffffffff, %rax # imm = 0xFFFFFFFFFFFFFFF
movq %rcx, %rdx
xorq %rax, %rdx
cmpq %rbp, %rdx
jb 0x2c40
cmpq %rbp, %rcx
movq %rbp, %r12
cmovaq %rcx, %r12
addq %rcx, %r12
cmpq %rax, %r12
cmovaeq %rax, %r12
leaq (,%r12,8), %rdi
callq 0x2180
leaq (%rax,%r15), %r14
movq %rax, (%rsp)
movq $0x0, (%rax,%r15)
cmpq $0x1, %rbp
je 0x2a1a
movq 0x8(%rsp), %rcx
vpmovsxbq 0x3705(%rip), %zmm1 # 0x60c8
leaq 0x8(%r14), %rax
xorl %edx, %edx
leaq (,%rcx,8), %rcx
subq %r15, %rcx
addq $-0x8, %rcx
vpbroadcastq %rcx, %zmm0
shrq $0x3, %rcx
addq $0x8, %rcx
vpsrlq $0x3, %zmm0, %zmm0
andq $-0x8, %rcx
vpbroadcastq (%r14), %zmm3
vpbroadcastq %rdx, %zmm2
vporq %zmm1, %zmm2, %zmm2
vpcmpleuq %zmm0, %zmm2, %k1
vmovdqu64 %zmm3, (%rax,%rdx,8) {%k1}
addq $0x8, %rdx
cmpq %rdx, %rcx
jne 0x29f1
movq 0x18(%rbx), %r15
movq 0x20(%rbx), %rdx
subq %r15, %rdx
testq %rdx, %rdx
jle 0x2a39
movq (%rsp), %rdi
movq %r15, %rsi
vzeroupper
callq 0x21e0
testq %r15, %r15
je 0x2a50
movq 0x28(%rbx), %rsi
movq %r15, %rdi
subq %r15, %rsi
vzeroupper
callq 0x2190
movq (%rsp), %rcx
leaq (%r14,%rbp,8), %rax
movq %rcx, 0x18(%rbx)
leaq (%rcx,%r12,8), %rcx
movq %rax, 0x20(%rbx)
movq %rcx, 0x28(%rbx)
jmp 0x2af4
movq $0x0, (%rax)
cmpq $0x1, %rbp
jne 0x2a83
addq $0x8, %rax
movq %rax, %rcx
jmp 0x2af0
movq 0x8(%rsp), %rdx
vpmovsxbq 0x3636(%rip), %zmm1 # 0x60c8
leaq (%rax,%rbp,8), %rcx
xorl %esi, %esi
leaq (,%rdx,8), %rdx
subq %r15, %rdx
addq $-0x8, %rdx
vpbroadcastq %rdx, %zmm0
shrq $0x3, %rdx
addq $0x8, %rdx
vpsrlq $0x3, %zmm0, %zmm0
andq $-0x8, %rdx
vpbroadcastq (%rax), %zmm3
vpbroadcastq %rsi, %zmm2
vporq %zmm1, %zmm2, %zmm2
vpcmpleuq %zmm0, %zmm2, %k1
vmovdqu64 %zmm3, 0x8(%rax,%rsi,8) {%k1}
addq $0x8, %rsi
cmpq %rsi, %rdx
jne 0x2ac0
movq %rcx, %rax
movq %rcx, 0x20(%rbx)
cmpq $0x4, %r13
jae 0x2b02
xorl %r13d, %r13d
jmp 0x2be7
leaq 0x30(%rbx), %rax
movl $0xff, %ebp
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %rax, (%rsp)
movq 0x18(%rbx), %rax
movq %r13, %rcx
shrq $0x8, %rcx
movq %r12, %r15
shlq $0x5, %r15
xorl %r14d, %r14d
movl %ecx, (%rax,%r12,8)
movb %r13b, 0x4(%rax,%r12,8)
movq %r13, %rax
testq %r14, %r14
je 0x2b52
movq 0x18(%rbx), %rcx
movl %eax, %esi
leaq (%rcx,%r12,8), %rdx
movb 0x4(%rcx,%r12,8), %cl
subb %cl, %sil
movb %sil, 0x4(%r14,%rdx)
leaq (,%r14,8), %rcx
addq (%rbx), %rcx
leaq (%rax,%rbp), %rdx
movq (%r15,%rcx), %rcx
popcntq %rcx, %r13
addq %rax, %r13
leaq (%r13,%rbp), %rsi
xorq %rdx, %rsi
cmpq $0x100, %rsi            # imm = 0x100
setb %dl
testq %rcx, %rcx
sete %sil
orb %dl, %sil
jne 0x2bc8
testb %al, %al
je 0x2b9b
incq %rax
blsrq %rcx, %rcx
jne 0x2b8b
jmp 0x2bc8
movl %r12d, 0x14(%rsp)
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x2bb7
movl %r12d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x2bc8
movq (%rsp), %rdi
leaq 0x14(%rsp), %rdx
vzeroupper
callq 0x40ee
incq %r14
cmpq $0x4, %r14
jne 0x2b33
incq %r12
cmpq 0x8(%rsp), %r12
jne 0x2b15
movq 0x20(%rbx), %rax
movq %r13, %rcx
shrq $0x8, %rcx
movl %ecx, -0x8(%rax)
movb %r13b, -0x4(%rax)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x5, %rax
movl %eax, 0x10(%rsp)
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x2c1a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x2c2e
addq $0x30, %rbx
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
vzeroupper
callq 0x40ee
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
leaq 0x3489(%rip), %rdi      # 0x60d0
callq 0x20b0