// File: 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:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movq 0x120(%rsp), %rdi
movq %rdi, 0x60(%rsp)
addq $0x8, %rdi
movq %rdi, 0x48(%rsp)
callq 0x47a0
movq 0x60(%rsp), %rdi
addq $0x20, %rdi
movq %rdi, 0x50(%rsp)
callq 0x47b0
movq 0x60(%rsp), %rdi
addq $0x38, %rdi
movq %rdi, 0x58(%rsp)
callq 0x47c0
movq 0x60(%rsp), %rax
movl $0xffffffff, 0x50(%rax) # imm = 0xFFFFFFFF
movl $0x1, 0x4(%rax)
movq 0x60(%rsp), %rax
movl 0x4(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %eax
movq %rax, 0x40(%rsp)
movq 0x118(%rsp), %rdi
callq 0x2640
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
ja 0x37fb
movq 0x60(%rsp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
jmp 0x37bb
movq 0x60(%rsp), %rax
movb 0x4(%rax), %cl
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
movl %ecx, (%rax)
movq %rax, %rdi
addq $0x8, %rdi
movl (%rax), %eax
movl %eax, %esi
movl $0x0, 0x114(%rsp)
leaq 0x114(%rsp), %rdx
callq 0x47d0
jmp 0x3833
movq 0x60(%rsp), %rax
movq %rax, %rdi
addq $0x20, %rdi
movl (%rax), %eax
movl %eax, %esi
movq $0x0, 0xf8(%rsp)
leaq 0xf8(%rsp), %rdx
callq 0x4890
jmp 0x385e
movq 0x60(%rsp), %rax
movq %rax, %rdi
addq $0x38, %rdi
movl (%rax), %eax
movl %eax, %esi
movl $0x0, 0xf4(%rsp)
leaq 0xf4(%rsp), %rdx
callq 0x4950
jmp 0x3888
movl $0x0, 0xf0(%rsp)
movl 0xf0(%rsp), %eax
movq %rax, 0x38(%rsp)
movq 0x118(%rsp), %rdi
callq 0x2640
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jae 0x3926
movq 0x118(%rsp), %rdi
movl 0xf0(%rsp), %eax
movl %eax, %esi
callq 0x2660
movq 0x60(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
addq $0x20, %rdi
movl 0xf0(%rsp), %eax
movl %eax, %esi
callq 0x2660
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0xf0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf0(%rsp)
jmp 0x3893
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x3d4b
movq 0x60(%rsp), %rdi
addq $0x20, %rdi
movq %rdi, 0x20(%rsp)
callq 0x3e70
movq 0x20(%rsp), %rdi
movq %rax, 0xe0(%rsp)
callq 0x3ea0
movq %rax, 0xd8(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
xorps %xmm0, %xmm0
callq 0x4a10
movsd %xmm0, 0x28(%rsp)
jmp 0x3973
movq 0x60(%rsp), %rdi
addq $0x20, %rdi
callq 0x2640
movsd 0x28(%rsp), %xmm0
movq %rax, %rcx
movq 0x60(%rsp), %rax
movq %rcx, %xmm1
movaps 0x7695(%rip), %xmm2     # 0xb030
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x7699(%rip), %xmm2     # 0xb040
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xe8(%rsp)
addq $0x20, %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x3e70
movq %rax, 0xc8(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x3ea0
movq %rax, 0xc0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x4a80
testb $0x1, %al
jne 0x3a14
jmp 0x3a55
leaq 0xc8(%rsp), %rdi
callq 0x4ac0
movq %rax, 0xb8(%rsp)
movsd 0xe8(%rsp), %xmm1
movq 0xb8(%rsp), %rax
movsd (%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
leaq 0xc8(%rsp), %rdi
callq 0x4ad0
jmp 0x39f9
leaq 0xa0(%rsp), %rdi
callq 0x47a0
leaq 0x88(%rsp), %rdi
callq 0x47a0
movl $0x0, 0x84(%rsp)
movq 0x60(%rsp), %rcx
movl 0x84(%rsp), %eax
cmpl (%rcx), %eax
jae 0x3b6c
movq 0x60(%rsp), %rdi
addq $0x20, %rdi
movl 0x84(%rsp), %eax
movl %eax, %esi
callq 0x2660
movsd 0x756b(%rip), %xmm0     # 0xb018
ucomisd (%rax), %xmm0
jbe 0x3b0d
movl 0x84(%rsp), %eax
movl %eax, 0x80(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x4af0
jmp 0x3ad8
jmp 0x3b2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x4c50
leaq 0xa0(%rsp), %rdi
callq 0x4c50
jmp 0x3d4b
movl 0x84(%rsp), %eax
movl %eax, 0x7c(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x7c(%rsp), %rsi
callq 0x4af0
jmp 0x3b2c
jmp 0x3b2e
movq 0x60(%rsp), %rdi
movl 0x84(%rsp), %eax
movl %eax, 0x1c(%rsp)
addq $0x8, %rdi
movl 0x84(%rsp), %eax
movl %eax, %esi
callq 0x4b20
movl 0x1c(%rsp), %ecx
movl %ecx, (%rax)
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x3a7a
jmp 0x3b6e
leaq 0xa0(%rsp), %rdi
callq 0x4b40
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, 0x1b(%rsp)
je 0x3ba2
leaq 0x88(%rsp), %rdi
callq 0x4b40
cmpq $0x0, %rax
setne %al
movb %al, 0x1b(%rsp)
movb 0x1b(%rsp), %al
testb $0x1, %al
jne 0x3baf
jmp 0x3cb3
leaq 0xa0(%rsp), %rdi
callq 0x4b60
movl (%rax), %eax
movl %eax, 0x78(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x4ba0
leaq 0x88(%rsp), %rdi
callq 0x4b60
movq 0x60(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
movl %eax, 0x4(%rsp)
addq $0x8, %rdi
movslq 0x78(%rsp), %rsi
callq 0x4b20
movl 0x4(%rsp), %ecx
movq 0x60(%rsp), %rdi
movl %ecx, (%rax)
addq $0x20, %rdi
movslq 0x74(%rsp), %rsi
callq 0x2660
movq 0x60(%rsp), %rdi
movsd (%rax), %xmm0
movsd 0x73f1(%rip), %xmm1     # 0xb018
subsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
addq $0x20, %rdi
movslq 0x78(%rsp), %rsi
callq 0x2660
movsd 0x8(%rsp), %xmm0
movq 0x60(%rsp), %rdi
addsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
addq $0x20, %rdi
movslq 0x74(%rsp), %rsi
callq 0x2660
movsd 0x10(%rsp), %xmm0
movq 0x60(%rsp), %rdi
movsd %xmm0, (%rax)
addq $0x20, %rdi
movslq 0x74(%rsp), %rsi
callq 0x2660
movsd 0x7391(%rip), %xmm0     # 0xb018
ucomisd (%rax), %xmm0
jbe 0x3cae
leaq 0xa0(%rsp), %rdi
leaq 0x74(%rsp), %rsi
callq 0x4bc0
jmp 0x3ca1
leaq 0x88(%rsp), %rdi
callq 0x4ba0
jmp 0x3b6e
movq 0x60(%rsp), %rcx
movl 0x50(%rcx), %eax
movl 0x4(%rcx), %ecx
shrl %cl, %eax
movl %eax, 0x70(%rsp)
movl $0x0, 0x6c(%rsp)
movq 0x60(%rsp), %rcx
movl 0x6c(%rsp), %eax
cmpl (%rcx), %eax
jae 0x3d29
movq 0x60(%rsp), %rdi
addq $0x20, %rdi
movl 0x6c(%rsp), %eax
movl %eax, %esi
callq 0x2660
movq 0x60(%rsp), %rdi
movsd (%rax), %xmm0
cvtsi2sdl 0x70(%rsp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, (%rsp)
addq $0x38, %rdi
movl 0x6c(%rsp), %eax
movl %eax, %esi
callq 0x4c30
movl (%rsp), %ecx
movl %ecx, (%rax)
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x3ccc
leaq 0x88(%rsp), %rdi
callq 0x4c50
leaq 0xa0(%rsp), %rdi
callq 0x4c50
addq $0x128, %rsp            # imm = 0x128
retq
movq 0x58(%rsp), %rdi
callq 0x4cb0
movq 0x50(%rsp), %rdi
callq 0x34b0
movq 0x48(%rsp), %rdi
callq 0x4c50
movq 0x108(%rsp), %rdi
callq 0x2220
nopw %cs:(%rax,%rax)