// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
leaq 0x8(%rdi), %rbx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x38(%rdi)
movupd %xmm0, 0x28(%rdi)
movupd %xmm0, 0x18(%rdi)
andq $0x0, 0x48(%rdi)
movupd %xmm0, 0x8(%rdi)
orl $-0x1, 0x50(%rdi)
leaq 0x20(%rdi), %r14
movq 0x8(%rsi), %rax
subq (%rsi), %rax
leaq 0x38(%rdi), %r12
sarq $0x3, %rax
xorl %ecx, %ecx
pushq $0x1
popq %rdx
incl %ecx
movl %edx, %esi
shll %cl, %esi
cmpq %rsi, %rax
jae 0x2c31
movl %ecx, 0x4(%r15)
movl %esi, (%r15)
leaq 0x10(%rsp), %rdx
andl $0x0, (%rdx)
movq %rbx, %rdi
movq %r12, 0x50(%rsp)
callq 0x301a
movl (%r15), %esi
leaq 0x10(%rsp), %rdx
andq $0x0, (%rdx)
movq %r14, %rdi
callq 0x304e
movl (%r15), %esi
leaq 0x10(%rsp), %rdx
andl $0x0, (%rdx)
movq %r12, %rdi
callq 0x3082
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq (%r14), %rdx
xorl %esi, %esi
movl %esi, %esi
cmpq %rsi, %rcx
jbe 0x2ca8
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incl %esi
jmp 0x2c93
movq 0x20(%r15), %rax
movq 0x28(%r15), %rcx
xorpd %xmm0, %xmm0
movq %rax, %rdx
cmpq %rcx, %rdx
je 0x2cc6
addsd (%rdx), %xmm0
addq $0x8, %rdx
jmp 0x2cb7
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movq %rdx, %xmm1
punpckldq 0x2353(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x235b(%rip), %xmm1     # 0x5040
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
cmpq %rcx, %rax
je 0x2d0c
movsd (%rax), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax)
addq $0x8, %rax
jmp 0x2cf5
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x30(%rsp), %rbp
andq $0x0, 0x10(%rbp)
movapd %xmm0, (%rbp)
xorl %r13d, %r13d
leaq 0xc(%rsp), %r12
movl (%r15), %eax
cmpq %rax, %r13
jae 0x2d80
movq (%r14), %rax
movsd 0x22d8(%rip), %xmm0     # 0x5020
ucomisd (%rax,%r13,8), %xmm0
jbe 0x2d64
movl %r13d, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x380e
jmp 0x2d74
movl %r13d, 0xc(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x380e
movq (%rbx), %rax
movl %r13d, (%rax,%r13,4)
incq %r13
jmp 0x2d35
leaq 0x10(%rsp), %r12
leaq 0xc(%rsp), %r13
movq 0x18(%rsp), %rcx
cmpq 0x10(%rsp), %rcx
je 0x2dfc
movq 0x38(%rsp), %rdx
movq (%r14), %rax
cmpq 0x30(%rsp), %rdx
je 0x2dff
movslq -0x4(%rcx), %rsi
addq $-0x4, %rcx
movq %rcx, 0x18(%rsp)
movl -0x4(%rdx), %ecx
movl %ecx, 0xc(%rsp)
movq (%rbx), %rdx
movl %ecx, (%rdx,%rsi,4)
movslq 0xc(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd 0x2247(%rip), %xmm0     # 0x5018
addsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movsd 0x223d(%rip), %xmm1     # 0x5020
ucomisd %xmm0, %xmm1
jbe 0x2d8a
movq %r12, %rdi
movq %r13, %rsi
callq 0x30b6
addq $-0x4, 0x38(%rsp)
jmp 0x2d8a
movq (%r14), %rax
movl 0x50(%r15), %edx
movb 0x4(%r15), %cl
shrl %cl, %edx
cvtsi2sd %edx, %xmm0
movq 0x38(%r15), %rcx
xorl %edx, %edx
movl (%r15), %esi
cmpq %rsi, %rdx
jae 0x2e31
movsd (%rax,%rdx,8), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rsi
movl %esi, (%rcx,%rdx,4)
incq %rdx
jmp 0x2e13
leaq 0x30(%rsp), %rdi
callq 0x39c6
leaq 0x10(%rsp), %rdi
callq 0x39c6
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2e58
jmp 0x2e58
movq %rax, %r15
jmp 0x2e78
jmp 0x2e61
jmp 0x2e61
movq %rax, %r15
leaq 0x30(%rsp), %rdi
callq 0x39c6
leaq 0x10(%rsp), %rdi
callq 0x39c6
movq 0x50(%rsp), %rdi
callq 0x39e4
movq %r14, %rdi
callq 0x2b4c
movq %rbx, %rdi
callq 0x39c6
movq %r15, %rdi
callq 0x21b0