// File: /workspace/github_cpp_makefile_star2_O2/cegme[P]vose/test.cc
// Function: test::test3()
bool test::test3() {

  // Create a VoseTree structure
  VoseTree tree;
  tree.set_max_marbles(4);

  // Create new marbles and add them to the Vose tree
  std::cerr << tree.toString();
  tree.add("red", 5L);
  std::cerr << tree.toString();
  tree.add("blue", 10L);
  std::cerr << tree.toString();
  tree.add("yellow", 20L);
  std::cerr << tree.toString();

  tree.add("red", 5L);
  std::cerr << tree.toString();
  tree.add("blue", 10L);
  std::cerr << tree.toString();
  tree.add("yellow", 20L);
  std::cerr << tree.toString();

  // Sample from the tree with and save the results to a histogram
  std::map<std::string,double> histogram;
  long hist_sum = 0L;
  for (int i = 0; i != 50000; ++i) {
    auto idx = tree.rand_marble();

    if (histogram.find(idx.label) != histogram.end()) {
      histogram[idx.label] += 1.0;
      hist_sum += 1L;
    }
    else {
      histogram.insert(std::make_pair(idx.label, 1.0));
      hist_sum += 1L;
    }
  }
  
  std::map<std::string,double> new_hist;
  std::for_each(histogram.cbegin(), histogram.cend(),
    [&new_hist,hist_sum] (std::pair<const std::string, double> a) {
      //std::cerr << a.first << ", " << (double)a.second/hist_sum << "\n";
      new_hist.insert( std::make_pair(a.first,(double)a.second/hist_sum));
  });

  std::map<std::string, double> exact_prob = tree.probabilities();
 
  // Compare the results with kl divergence
  double kl1 = VoseTree::kl(new_hist, exact_prob);
  double kl2 = VoseTree::kl(exact_prob, new_hist);
  std::cerr << "kl(histogram, exact_prob): " << kl1 << "\n";
  std::cerr << "kl(exact_prob, histogram): " << kl2 << "\n";
  
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
xorpd %xmm0, %xmm0
leaq -0x110(%rbp), %rsi
movapd %xmm0, 0x50(%rsi)
movapd %xmm0, 0x40(%rsi)
movapd %xmm0, 0x30(%rsi)
movapd %xmm0, 0x20(%rsi)
movapd %xmm0, 0x10(%rsi)
movapd %xmm0, (%rsi)
andq $0x0, 0x68(%rsi)
movq $0x4, 0x60(%rsi)
leaq -0x58(%rbp), %rdi
callq 0x2afe
movq 0x8a19(%rip), %rdi      # 0xfff0
leaq -0x58(%rbp), %rsi
callq 0x21b0
leaq -0x58(%rbp), %rdi
callq 0x20d0
leaq 0x2cf9(%rip), %rsi      # 0xa2e9
leaq -0x200(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x20b0
leaq -0x110(%rbp), %rdi
leaq -0x200(%rbp), %rsi
pushq $0x5
popq %rdx
callq 0x247c
leaq -0x200(%rbp), %rdi
callq 0x20d0
leaq -0x58(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2afe
movq 0x89b7(%rip), %rdi      # 0xfff0
leaq -0x58(%rbp), %rsi
callq 0x21b0
leaq -0x58(%rbp), %rdi
callq 0x20d0
leaq 0x2e6e(%rip), %rsi      # 0xa4c0
leaq -0x1e0(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x20b0
leaq -0x110(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
pushq $0xa
popq %rdx
callq 0x247c
leaq -0x1e0(%rbp), %rdi
callq 0x20d0
leaq -0x58(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2afe
movq 0x8955(%rip), %rdi      # 0xfff0
leaq -0x58(%rbp), %rsi
callq 0x21b0
leaq -0x58(%rbp), %rdi
callq 0x20d0
leaq 0x2c8d(%rip), %rsi      # 0xa341
leaq -0x1c0(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x20b0
leaq -0x110(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
pushq $0x14
popq %rdx
callq 0x247c
leaq -0x1c0(%rbp), %rdi
callq 0x20d0
leaq -0x58(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2afe
movq 0x88f3(%rip), %rdi      # 0xfff0
leaq -0x58(%rbp), %rsi
callq 0x21b0
leaq -0x58(%rbp), %rdi
callq 0x20d0
leaq 0x2bd3(%rip), %rsi      # 0xa2e9
leaq -0x1a0(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x20b0
leaq -0x110(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
pushq $0x5
popq %rdx
callq 0x247c
leaq -0x1a0(%rbp), %rdi
callq 0x20d0
leaq -0x58(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2afe
movq 0x8891(%rip), %rdi      # 0xfff0
leaq -0x58(%rbp), %rsi
callq 0x21b0
leaq -0x58(%rbp), %rdi
callq 0x20d0
leaq 0x2d48(%rip), %rsi      # 0xa4c0
leaq -0x180(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x20b0
leaq -0x110(%rbp), %rdi
leaq -0x180(%rbp), %rsi
pushq $0xa
popq %rdx
callq 0x247c
leaq -0x180(%rbp), %rdi
callq 0x20d0
leaq -0x58(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2afe
movq 0x882f(%rip), %rdi      # 0xfff0
leaq -0x58(%rbp), %rsi
callq 0x21b0
leaq -0x58(%rbp), %rdi
callq 0x20d0
leaq 0x2b67(%rip), %rsi      # 0xa341
leaq -0x160(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x20b0
leaq -0x110(%rbp), %rdi
leaq -0x160(%rbp), %rsi
pushq $0x14
popq %rdx
callq 0x247c
leaq -0x160(%rbp), %rdi
callq 0x20d0
leaq -0x58(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2afe
movq 0x87cd(%rip), %rdi      # 0xfff0
leaq -0x58(%rbp), %rsi
callq 0x21b0
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x20d0
leaq -0x50(%rbp), %r13
andl $0x0, (%r13)
andq $0x0, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
andq $0x0, 0x20(%r13)
movl $0xc350, %r12d          # imm = 0xC350
leaq -0x138(%rbp), %r14
leaq -0x98(%rbp), %r15
subq $0x1, %r12
jb 0x78e3
leaq -0x140(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2a36
movq %rbx, %rdi
movq %r14, %rsi
callq 0x59b4
cmpq %r13, %rax
je 0x78ad
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3696
movsd (%rax), %xmm0
addsd 0x2761(%rip), %xmm0     # 0xa008
movsd %xmm0, (%rax)
jmp 0x78d9
movq %r15, %rdi
movq %r14, %rsi
callq 0x2240
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0x78(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x55dc
movq %r15, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x20d0
jmp 0x7867
leaq -0x140(%rbp), %rbx
andl $0x0, 0x8(%rbx)
andq $0x0, 0x10(%rbx)
movq %r14, 0x18(%rbx)
movq %r14, 0x20(%rbx)
andq $0x0, 0x28(%rbx)
movq -0x40(%rbp), %r12
leaq -0x228(%rbp), %r14
leaq -0x98(%rbp), %r15
cmpq %r13, %r12
je 0x7976
leaq 0x20(%r12), %rsi
movq %r14, %rdi
callq 0x5992
movsd -0x208(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x2240
movsd -0x60(%rbp), %xmm0
divsd 0x292f(%rip), %xmm0     # 0xa278
movsd %xmm0, -0x78(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x55dc
movq %r15, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x20d0
movq %r12, %rdi
callq 0x2210
movq %rax, %r12
jmp 0x7912
leaq -0x98(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2e58
leaq -0x140(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2f78
movsd %xmm0, -0x60(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x2f78
movsd %xmm0, -0x68(%rbp)
movq 0x8630(%rip), %rdi      # 0xfff0
leaq 0x2a7b(%rip), %rsi      # 0xa442
callq 0x21e0
movq %rax, %rdi
movsd -0x60(%rbp), %xmm0
callq 0x2280
leaq 0x2b4c(%rip), %rsi      # 0xa52c
movq %rax, %rdi
callq 0x21e0
movq 0x8601(%rip), %rdi      # 0xfff0
leaq 0x2a68(%rip), %rsi      # 0xa45e
callq 0x21e0
movq %rax, %rdi
movsd -0x68(%rbp), %xmm0
callq 0x2280
leaq 0x2b1d(%rip), %rsi      # 0xa52c
movq %rax, %rdi
callq 0x21e0
leaq -0x98(%rbp), %rdi
callq 0x4290
leaq -0x140(%rbp), %rdi
callq 0x4290
leaq -0x58(%rbp), %rdi
callq 0x4290
leaq -0x110(%rbp), %rdi
callq 0x8788
movb $0x1, %al
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7ae1
jmp 0x7b07
jmp 0x7ace
jmp 0x7adc
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
jmp 0x7ad5
jmp 0x7adc
jmp 0x7ace
jmp 0x7adc
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
jmp 0x7ad5
jmp 0x7adc
jmp 0x7ace
jmp 0x7adc
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
jmp 0x7ad5
jmp 0x7adc
jmp 0x7ace
jmp 0x7adc
movq %rax, %rbx
leaq -0x1c0(%rbp), %rdi
jmp 0x7ad5
jmp 0x7adc
jmp 0x7ace
jmp 0x7adc
movq %rax, %rbx
leaq -0x1e0(%rbp), %rdi
jmp 0x7ad5
jmp 0x7adc
jmp 0x7ace
jmp 0x7adc
movq %rax, %rbx
leaq -0x200(%rbp), %rdi
jmp 0x7ad5
jmp 0x7adc
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x20d0
jmp 0x7b53
movq %rax, %rbx
jmp 0x7b53
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x4290
jmp 0x7b2c
jmp 0x7b3f
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x20d0
jmp 0x7b42
jmp 0x7b3f
movq %rax, %rbx
jmp 0x7b2c
movq %rax, %rbx
jmp 0x7b20
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x20d0
leaq -0x228(%rbp), %rdi
callq 0x20d0
leaq -0x140(%rbp), %rdi
callq 0x4290
jmp 0x7b4a
movq %rax, %rbx
jmp 0x7b4a
movq %rax, %rbx
movq %r14, %rdi
callq 0x20d0
leaq -0x58(%rbp), %rdi
callq 0x4290
leaq -0x110(%rbp), %rdi
callq 0x8788
movq %rbx, %rdi
callq 0x22d0
nop