// File: /workspace/github_cpp_makefile_star2_O1/kaityo256[P]randomsampling/./walker_alias.hpp
// Function: walker_alias::walker_alias(std::vector<double, std::allocator<double>>&)
walker_alias(std::vector<double> &a) {
    nb = 1;
    while ((unsigned int)(1 << nb) <= a.size()) {
      nb++;
    }
    n = (1 << nb);
    index.resize(n, 0.0);
    prob.resize(n, 0.0);
    probi.resize(n, 0);
    for (unsigned int i = 0; i < a.size(); i++) {
      prob[i] = a[i];
    }
    double ave = std::accumulate(prob.begin(), prob.end(), 0.0) / prob.size();
    for (auto &v : prob) {
      v /= ave;
    }
    std::vector<int> small, large;
    for (unsigned int i = 0; i < n; i++) {
      if (prob[i] < 1.0) {
        small.push_back(i);
      } else {
        large.push_back(i);
      }
      index[i] = i;
    }
    while (small.size() && large.size()) {
      const int j = small.back();
      small.pop_back();
      const int k = large.back();
      index[j] = k;
      prob[k] = prob[k] - 1.0 + prob[j];
      if (prob[k] < 1.0) {
        small.push_back(k);
        large.pop_back();
      }
    }
    const int imax = int_max >> nb;
    for (unsigned int i = 0; i < n; i++) {
      probi[i] = static_cast<uint32_t>(prob[i] * imax);
    }
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
leaq 0x20(%rdi), %r15
leaq 0x38(%rdi), %r12
xorpd %xmm0, %xmm0
movupd %xmm0, 0x38(%rdi)
movupd %xmm0, 0x28(%rdi)
movupd %xmm0, 0x18(%rdi)
movupd %xmm0, 0x8(%rdi)
movq $0x0, 0x48(%rdi)
movl $0xffffffff, 0x50(%rdi) # imm = 0xFFFFFFFF
movq 0x8(%rsi), %rax
subq (%rsi), %rax
sarq $0x3, %rax
xorl %ecx, %ecx
incl %ecx
movl $0x1, %esi
shll %cl, %esi
cmpq %rsi, %rax
jae 0x2304
movl %ecx, 0x4(%rbx)
movl %esi, (%rbx)
leaq 0x10(%rsp), %rdx
movl $0x0, (%rdx)
movq %r14, %rdi
movq %r12, 0x50(%rsp)
callq 0x2698
movl (%rbx), %esi
leaq 0x10(%rsp), %rdx
movq $0x0, (%rdx)
movq %r15, %rdi
callq 0x26cc
movl (%rbx), %esi
leaq 0x10(%rsp), %rdx
movl $0x0, (%rdx)
movq %r12, %rdi
callq 0x2700
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
je 0x2384
sarq $0x3, %rcx
movq (%r15), %rdx
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0x2370
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
xorpd %xmm0, %xmm0
cmpq %rcx, %rax
je 0x23a5
movq %rax, %rdx
addsd (%rdx), %xmm0
addq $0x8, %rdx
cmpq %rcx, %rdx
jne 0x2398
movq %rcx, %rdx
subq %rax, %rdx
je 0x23eb
sarq $0x3, %rdx
movq %rdx, %xmm1
punpckldq 0x2c92(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x2c9a(%rip), %xmm1     # 0x5060
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd (%rax), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax)
addq $0x8, %rax
cmpq %rcx, %rax
jne 0x23d6
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rax, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
cmpl $0x0, (%rbx)
je 0x249a
xorl %r13d, %r13d
leaq 0xc(%rsp), %rbp
leaq 0x30(%rsp), %r12
movq (%r15), %rax
movsd 0x2bf0(%rip), %xmm0     # 0x5018
ucomisd (%rax,%r13,8), %xmm0
jbe 0x244f
movl %r13d, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x246e
movl %r13d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x2488
movl %r13d, 0xc(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x247d
movl %r13d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x2488
leaq 0x10(%rsp), %rdi
movq %rbp, %rdx
callq 0x376c
jmp 0x2488
movq %r12, %rdi
movq %rbp, %rdx
callq 0x376c
movq 0x8(%rbx), %rax
movl %r13d, (%rax,%r13,4)
incq %r13
movl (%rbx), %eax
cmpq %rax, %r13
jb 0x241d
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0x2539
leaq 0x10(%rsp), %r12
leaq 0xc(%rsp), %r13
movq 0x38(%rsp), %rcx
cmpq 0x30(%rsp), %rcx
je 0x2539
leaq -0x4(%rax), %rsi
movslq -0x4(%rax), %rdx
movq %rsi, 0x18(%rsp)
movl -0x4(%rcx), %ecx
movl %ecx, 0xc(%rsp)
movq (%r14), %rdi
movl %ecx, (%rdi,%rdx,4)
movslq 0xc(%rsp), %rcx
movq (%r15), %rdi
movsd (%rdi,%rcx,8), %xmm0
addsd 0x2b31(%rip), %xmm0     # 0x5020
addsd (%rdi,%rdx,8), %xmm0
movsd %xmm0, (%rdi,%rcx,8)
movsd 0x2b17(%rip), %xmm1     # 0x5018
ucomisd %xmm0, %xmm1
jbe 0x2529
cmpq 0x20(%rsp), %rsi
je 0x2518
movl %ecx, -0x4(%rax)
movq %rax, 0x18(%rsp)
jmp 0x2523
movq %r12, %rdi
movq %r13, %rdx
callq 0x3848
addq $-0x4, 0x38(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
jne 0x24b4
cmpl $0x0, (%rbx)
je 0x2572
movl 0x50(%rbx), %edx
movb 0x4(%rbx), %cl
shrl %cl, %edx
movq 0x20(%rbx), %rax
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movq 0x38(%rbx), %rcx
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rsi
movl %esi, (%rcx,%rdx,4)
incq %rdx
movl (%rbx), %esi
cmpq %rsi, %rdx
jb 0x2557
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2589
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x25a0
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25b3
jmp 0x25b3
movq %rax, %r13
jmp 0x25ed
jmp 0x25bc
jmp 0x25bc
movq %rax, %r13
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x25d6
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x25ed
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0x50(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2606
movq 0x48(%rbx), %rsi
subq %rdi, %rsi
callq 0x10e0
movq (%r15), %rdi
testq %rdi, %rdi
je 0x261a
movq 0x30(%rbx), %rsi
subq %rdi, %rsi
callq 0x10e0
movq (%r14), %rdi
testq %rdi, %rdi
je 0x262e
movq 0x18(%rbx), %rsi
subq %rdi, %rsi
callq 0x10e0
movq %r13, %rdi
callq 0x1140