// File: /workspace/github_cpp_makefile_star2_O1/cegme[P]vose/test.cc
// Function: test::test2()
bool test::test2() {
  std::cerr << "Check that the vose data structure comes close to actual values.\n";

  Vose vose;
  vose.add("red", 5);
  vose.add("blue", 10);
  vose.add("yellow", 20);

  vose.init();
  
  std::cerr << "Vose Dist: ";
  for (size_t i = 0; i != vose.scores.size(); ++i) {
    std::cerr << "\t" << i << "-->" << vose.scores[i].weight << "\n";
  }
  std::cerr << "\n";
  for (size_t i = 0; i != vose.probabilities().size(); ++i) {
    std::cerr << "\t" << i << "-->" << vose.probabilities()[i] << "\n";
  }
  std::cerr << "\n";

  std::cerr << "Create a histogram by sampling the vose structure.\n";
  std::map<size_t,int> histogram;
  auto hist_sum = 0L;
  for (int i = 0; i != 50000; ++i) {
    size_t idx = vose.rand();

    if (histogram.find(idx) != histogram.end()) {
      histogram[idx] += 1;
      hist_sum += 1L;
    }
    else {
      histogram.insert(std::make_pair(idx, 1));
      hist_sum += 1L;
    }
  }

  std::cerr << "Sampled Distribution:\n";

  // Create the new dist
  std::vector<double> new_dist;
  for (auto& h : histogram) {
    std::cerr << "\t" << h.first <<  "-->" << (double)h.second/hist_sum << "\n";
    new_dist.push_back((double)h.second/hist_sum);
  }

  double kl_result = Vose::kl(vose.probabilities(), new_dist); 
  std::cerr << "kl(probabilities, new_dist): " << kl_result << "\n";
  std::cerr << "kl(new_dist, probabilities): " << Vose::kl(new_dist, vose.probabilities()) << "\n";

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq 0x7d15(%rip), %rdi      # 0xfff0
leaq 0x30c5(%rip), %rsi      # 0xb3a7
movl $0x41, %edx
callq 0x2200
leaq -0x128(%rbp), %rdi
movl $0x90, %edx
xorl %esi, %esi
callq 0x2100
leaq -0x178(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3018(%rip), %rsi      # 0xb329
leaq 0x3014(%rip), %rdx      # 0xb32c
leaq -0x188(%rbp), %rdi
callq 0xa7de
leaq -0x128(%rbp), %rdi
leaq -0x188(%rbp), %rsi
movl $0x5, %edx
callq 0x6cc4
movq -0x188(%rbp), %rdi
cmpq %r14, %rdi
je 0x834d
callq 0x21c0
leaq -0x158(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x31a1(%rip), %rsi      # 0xb500
leaq 0x319e(%rip), %rdx      # 0xb504
leaq -0x168(%rbp), %rdi
callq 0xa7de
leaq -0x128(%rbp), %rdi
leaq -0x168(%rbp), %rsi
movl $0xa, %edx
callq 0x6cc4
movq -0x168(%rbp), %rdi
cmpq %r14, %rdi
je 0x839b
callq 0x21c0
leaq -0x138(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x2fd4(%rip), %rsi      # 0xb381
leaq 0x2fd3(%rip), %rdx      # 0xb387
leaq -0x148(%rbp), %rdi
callq 0xa7de
leaq -0x128(%rbp), %rdi
leaq -0x148(%rbp), %rsi
movl $0x14, %edx
callq 0x6cc4
movq -0x148(%rbp), %rdi
cmpq %r14, %rdi
je 0x83e9
callq 0x21c0
leaq -0x128(%rbp), %rdi
callq 0x6dd4
movq 0x7bf4(%rip), %rdi      # 0xfff0
leaq 0x2fe6(%rip), %rsi      # 0xb3e9
movl $0xb, %edx
callq 0x2200
movq -0xe0(%rbp), %rax
cmpq -0xe8(%rbp), %rax
je 0x84be
xorl %r15d, %r15d
movq 0x7bc5(%rip), %rbx      # 0xfff0
leaq 0x313a(%rip), %r12      # 0xb56c
xorl %r13d, %r13d
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x2fb1(%rip), %rsi      # 0xb3f5
callq 0x2200
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2120
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x2f91(%rip), %rsi      # 0xb3f7
callq 0x2200
movq -0xe8(%rbp), %rax
movq (%rax,%r15), %rsi
movq %r14, %rdi
callq 0x21d0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2200
incq %r13
movq -0xe0(%rbp), %rax
subq -0xe8(%rbp), %rax
sarq $0x4, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x30, %r15
cmpq %rax, %r13
jne 0x8435
movq 0x7b2b(%rip), %rdi      # 0xfff0
leaq 0x30a0(%rip), %rsi      # 0xb56c
movl $0x1, %edx
callq 0x2200
xorl %r14d, %r14d
leaq -0x128(%rbp), %r12
movq 0x7b09(%rip), %r15      # 0xfff0
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movq %r12, %rcx
callq 0xa481
movq -0x90(%rbp), %rbx
movq -0x88(%rbp), %r13
testq %rbx, %rbx
je 0x8533
movq %rbx, %rdi
callq 0x21c0
subq %rbx, %r13
sarq $0x3, %r13
cmpq %r13, %r14
je 0x85ec
movl $0x1, %edx
movq %r15, %rdi
leaq 0x2ea3(%rip), %rsi      # 0xb3f5
callq 0x2200
movq %r15, %rdi
movq %r14, %rsi
callq 0x2120
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x2e83(%rip), %rsi      # 0xb3f7
callq 0x2200
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movq %r12, %rcx
callq 0xa481
movq -0x90(%rbp), %rax
movsd (%rax,%r14,8), %xmm0
movq %rbx, %rdi
callq 0x2260
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2f9e(%rip), %rsi      # 0xb56c
callq 0x2200
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x85e4
callq 0x21c0
incq %r14
jmp 0x84e7
movq 0x79fd(%rip), %rdi      # 0xfff0
leaq 0x2f72(%rip), %rsi      # 0xb56c
movl $0x1, %edx
callq 0x2200
movq 0x79e5(%rip), %rdi      # 0xfff0
leaq 0x2de9(%rip), %rsi      # 0xb3fb
movl $0x33, %edx
callq 0x2200
leaq -0x88(%rbp), %r13
movl $0x0, (%r13)
xorl %r15d, %r15d
movq %r15, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %r15, 0x20(%r13)
leaq -0x128(%rbp), %rbx
leaq -0x90(%rbp), %r14
leaq -0x40(%rbp), %r12
movq %rbx, %rdi
callq 0x71ee
movq %rax, -0x40(%rbp)
movq -0x80(%rbp), %rdx
movq %r13, %rcx
testq %rdx, %rdx
je 0x8683
movq %r13, %rcx
xorl %esi, %esi
cmpq %rax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x866b
movq %r13, %rdx
cmpq %r13, %rcx
je 0x8696
cmpq 0x20(%rcx), %rax
cmovbq %r13, %rcx
movq %rcx, %rdx
cmpq %r13, %rdx
je 0x86aa
movq %r14, %rdi
movq %r12, %rsi
callq 0xa3d2
incl (%rax)
jmp 0x86c1
movq %rax, -0x60(%rbp)
movl $0x1, -0x58(%rbp)
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
callq 0xaa8c
incq %r15
cmpq $0xc350, %r15           # imm = 0xC350
jne 0x8650
movq 0x791c(%rip), %rdi      # 0xfff0
leaq 0x2d54(%rip), %rsi      # 0xb42f
movl $0x16, %edx
callq 0x2200
xorpd %xmm0, %xmm0
movapd %xmm0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x78(%rbp), %rbx
cmpq %r13, %rbx
je 0x87be
movq 0x78e6(%rip), %r14      # 0xfff0
leaq 0x2e5b(%rip), %r12      # 0xb56c
movl $0x1, %edx
movq %r14, %rdi
leaq 0x2cd5(%rip), %rsi      # 0xb3f5
callq 0x2200
movq 0x20(%rbx), %rsi
movq %r14, %rdi
callq 0x2120
movq %rax, %r15
movl $0x3, %edx
movq %rax, %rdi
leaq 0x2cb4(%rip), %rsi      # 0xb3f7
callq 0x2200
xorps %xmm0, %xmm0
cvtsi2sdl 0x28(%rbx), %xmm0
divsd 0x2b60(%rip), %xmm0     # 0xb2b8
movq %r15, %rdi
callq 0x2260
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2200
xorps %xmm0, %xmm0
cvtsi2sdl 0x28(%rbx), %xmm0
divsd 0x2b38(%rip), %xmm0     # 0xb2b8
movsd %xmm0, -0x40(%rbp)
movq -0x58(%rbp), %rsi
cmpq -0x50(%rbp), %rsi
je 0x879d
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, -0x58(%rbp)
jmp 0x87aa
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x78ee
movq %rbx, %rdi
callq 0x2130
movq %rax, %rbx
cmpq %r13, %rax
jne 0x8711
leaq -0x40(%rbp), %rdx
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq -0x128(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq 0x48(%rcx), %rsi
callq 0xa481
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x72d8
movsd %xmm0, -0x98(%rbp)
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x8809
callq 0x21c0
movq 0x77e0(%rip), %rdi      # 0xfff0
leaq 0x2c2f(%rip), %rsi      # 0xb446
movl $0x1d, %edx
callq 0x2200
movq 0x77c8(%rip), %rdi      # 0xfff0
movsd -0x98(%rbp), %xmm0
callq 0x2260
leaq 0x2d30(%rip), %rsi      # 0xb56c
movl $0x1, %edx
movq %rax, %rdi
callq 0x2200
movq 0x77a0(%rip), %rdi      # 0xfff0
leaq 0x2c0d(%rip), %rsi      # 0xb464
movl $0x1d, %edx
callq 0x2200
xorpd %xmm0, %xmm0
leaq -0x40(%rbp), %rdx
movapd %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq -0x128(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq 0x48(%rcx), %rsi
callq 0xa481
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x72d8
movq 0x7753(%rip), %rdi      # 0xfff0
callq 0x2260
leaq 0x2cc3(%rip), %rsi      # 0xb56c
movl $0x1, %edx
movq %rax, %rdi
callq 0x2200
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x88c4
callq 0x21c0
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x88d2
callq 0x21c0
leaq -0x90(%rbp), %rdi
callq 0xa55e
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x88ef
callq 0x21c0
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0x8900
callq 0x21c0
leaq -0xe8(%rbp), %rdi
callq 0x49e2
movq -0xf8(%rbp), %rax
testq %rax, %rax
je 0x8929
leaq -0x108(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x118(%rbp), %rax
testq %rax, %rax
je 0x8946
leaq -0x128(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movb $0x1, %al
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x895c
movq %rax, %rdi
callq 0x4733
jmp 0x899b
jmp 0x899b
jmp 0x899b
jmp 0x89ba
movq %rax, %rbx
movq -0x148(%rbp), %rdi
jmp 0x8992
jmp 0x89f6
movq %rax, %rbx
movq -0x168(%rbp), %rdi
jmp 0x8992
jmp 0x89f6
movq %rax, %rbx
movq -0x188(%rbp), %rdi
cmpq %r14, %rdi
jne 0x89ce
jmp 0x89f9
jmp 0x89f6
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x89da
callq 0x21c0
jmp 0x89da
jmp 0x89d7
jmp 0x89f6
jmp 0x89d7
jmp 0x89ba
jmp 0x89bf
jmp 0x89bf
movq %rax, %rbx
jmp 0x89e8
movq %rax, %rbx
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x89f9
callq 0x21c0
jmp 0x89f9
jmp 0x89f6
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x89e8
callq 0x21c0
leaq -0x90(%rbp), %rdi
callq 0xa55e
jmp 0x89f9
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
callq 0x4468
movq %rbx, %rdi
callq 0x22b0
nop