// File: /workspace/github_cpp_makefile_star2_O3/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 0x230c
movl %ecx, 0x4(%rbx)
movl %esi, (%rbx)
leaq 0x10(%rsp), %rdx
movl $0x0, (%rdx)
movq %r14, %rdi
callq 0x26e4
movl (%rbx), %esi
leaq 0x10(%rsp), %rdx
movq $0x0, (%rdx)
movq %r15, %rdi
callq 0x2718
movl (%rbx), %esi
leaq 0x10(%rsp), %rdx
movl $0x0, (%rdx)
movq %r12, %rdi
callq 0x274c
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
je 0x2387
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 0x2373
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
cmpq %rcx, %rax
je 0x23ee
xorpd %xmm0, %xmm0
movq %rax, %rdx
addsd (%rdx), %xmm0
addq $0x8, %rdx
cmpq %rcx, %rdx
jne 0x239b
movq %rcx, %rdx
subq %rax, %rdx
je 0x23ee
sarq $0x3, %rdx
movq %rdx, %xmm1
punpckldq 0x2c8f(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x2c97(%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 0x23d9
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rax, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
cmpl $0x0, (%rbx)
movl $0x0, %edi
je 0x25b0
movq %r12, 0x38(%rsp)
movq %r14, 0x30(%rsp)
xorl %r14d, %r14d
leaq 0x10(%rsp), %r13
leaq 0xc(%rsp), %rbp
leaq 0x40(%rsp), %r12
movq (%r15), %rax
movsd 0x2bd9(%rip), %xmm0     # 0x5018
ucomisd (%rax,%r14,8), %xmm0
jbe 0x2466
movl %r14d, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x2485
movl %r14d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x249d
movl %r14d, 0xc(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x2492
movl %r14d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x249d
movq %r13, %rdi
movq %rbp, %rdx
callq 0x37c0
jmp 0x249d
movq %r12, %rdi
movq %rbp, %rdx
callq 0x37c0
movq 0x8(%rbx), %rax
movl %r14d, (%rax,%r14,4)
incq %r14
movl (%rbx), %ecx
cmpq %rcx, %r14
jb 0x2434
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
cmpq %rdi, %rax
je 0x2573
movq 0x48(%rsp), %rcx
leaq 0x10(%rsp), %r13
leaq 0xc(%rsp), %rbp
movq 0x30(%rsp), %r14
cmpq 0x40(%rsp), %rcx
je 0x2571
leaq -0x4(%rax), %rsi
movslq -0x4(%rax), %r8
movq %rsi, 0x18(%rsp)
movl -0x4(%rcx), %edx
movl %edx, 0xc(%rsp)
movq (%r14), %r9
movl %edx, (%r9,%r8,4)
movslq 0xc(%rsp), %rdx
movq (%r15), %r9
movsd (%r9,%rdx,8), %xmm0
addsd 0x2b0e(%rip), %xmm0     # 0x5020
addsd (%r9,%r8,8), %xmm0
movsd %xmm0, (%r9,%rdx,8)
movsd 0x2af2(%rip), %xmm1     # 0x5018
ucomisd %xmm0, %xmm1
jbe 0x253d
cmpq 0x20(%rsp), %rsi
je 0x2542
movl %edx, -0x4(%rax)
movq %rax, 0x18(%rsp)
jmp 0x255c
movq %rsi, %rax
jmp 0x2568
movq %r13, %rdi
movq %rbp, %rdx
callq 0x389c
movq 0x48(%rsp), %rcx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
addq $-0x4, %rcx
movq %rcx, 0x48(%rsp)
movq %rax, %rsi
cmpq %rdi, %rsi
jne 0x24d6
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x25ab
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 0x2590
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x25ca
movq 0x50(%rsp), %rsi
subq %rax, %rsi
movq %rax, %rdi
callq 0x10e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x25dc
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 0x25ef
jmp 0x25ef
movq %r12, 0x38(%rsp)
movq %r14, 0x30(%rsp)
movq %rax, %r13
jmp 0x2633
jmp 0x2602
jmp 0x2602
movq %rax, %r13
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x261c
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2633
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0x38(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x264c
movq 0x48(%rbx), %rsi
subq %rdi, %rsi
callq 0x10e0
movq (%r15), %rdi
testq %rdi, %rdi
je 0x2660
movq 0x30(%rbx), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0x30(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2679
movq 0x18(%rbx), %rsi
subq %rdi, %rsi
callq 0x10e0
movq %r13, %rdi
callq 0x1140
nop