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

  VoseTree tree;
  tree.set_max_marbles(4);
  tree.set_max_bags(5);

  // Generate a set of label names.
  std::string labels[7] = {"red", "yellow", "pink", "green", "purple", 
                           "orange", "blue"};

  // Make a random number generator for marble labels
  std::default_random_engine label_generator(VoseUtil::RANDOM_SEED); 
  std::uniform_int_distribution<size_t>
    label_distribution(0, 7-1);
  std::function<size_t()> random_label =
    std::bind(label_distribution, label_generator);
  
  // Make a random number generator for marble weights
  std::default_random_engine weight_generator(VoseUtil::RANDOM_SEED); 
  std::uniform_int_distribution<long>
    weight_distribution(1, 1000);
  std::function<long()> random_weight =
    std::bind(weight_distribution, weight_generator);

  for(size_t i = 0; i != 50; ++i) {
    // Get a random marble with random label and random weight.
    size_t label_idx = random_label();
    size_t weight = random_weight();
    //std::cerr << "label_idx: " << label_idx << ", " << labels[label_idx] << "\n";
    //std::cerr << " weight: " << weight << "\n";
    tree.add(std::string(labels[label_idx]), weight);
    std::cerr << tree.toString();
  }

  // Generate a histogram.
  auto hist = VoseTree::histogram(tree, 50000L);

  // Get the real probabilities
  auto prob = tree.probabilities();

  // Compare the results
  double kl1 = VoseTree::kl(hist, prob);
  double kl2 = VoseTree::kl(prob, hist);
  std::cerr << "kl(hist, prob): " << kl1 << "\n";
  std::cerr << "kl(prob, hist): " << kl2 << "\n";
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
xorps %xmm0, %xmm0
movaps %xmm0, -0x100(%rbp)
movaps %xmm0, -0x110(%rbp)
movaps %xmm0, -0x120(%rbp)
movaps %xmm0, -0x130(%rbp)
movaps %xmm0, -0x140(%rbp)
movaps %xmm0, -0x150(%rbp)
movq $0x4, -0xf0(%rbp)
movq $0x5, -0xe8(%rbp)
leaq 0x252b(%rip), %rsi      # 0xa2e9
leaq -0x250(%rbp), %r14
leaq -0x70(%rbp), %rdx
movq %r14, %rdi
callq 0x20b0
leaq -0x230(%rbp), %r15
leaq 0x2562(%rip), %rsi      # 0xa341
leaq -0xe0(%rbp), %rdx
movq %r15, %rdi
callq 0x20b0
leaq -0x210(%rbp), %r15
leaq 0x267e(%rip), %rsi      # 0xa47a
leaq -0xb0(%rbp), %rdx
movq %r15, %rdi
callq 0x20b0
leaq -0x1f0(%rbp), %r15
leaq 0x2666(%rip), %rsi      # 0xa47f
leaq -0x90(%rbp), %rdx
movq %r15, %rdi
callq 0x20b0
leaq -0x1d0(%rbp), %r15
leaq 0x264f(%rip), %rsi      # 0xa485
leaq -0x2b(%rbp), %rdx
movq %r15, %rdi
callq 0x20b0
leaq -0x1b0(%rbp), %r15
leaq 0x263c(%rip), %rsi      # 0xa48c
leaq -0x2a(%rbp), %rdx
movq %r15, %rdi
callq 0x20b0
leaq -0x190(%rbp), %r15
leaq 0x2656(%rip), %rsi      # 0xa4c0
leaq -0x29(%rbp), %rdx
movq %r15, %rdi
callq 0x20b0
leaq -0x70(%rbp), %rsi
andq $0x0, (%rsi)
movq $0x6, 0x8(%rsi)
movq $0x2a, 0x10(%rsi)
leaq -0xb0(%rbp), %rdi
callq 0x87b2
leaq -0x70(%rbp), %rsi
movq $0x1, (%rsi)
movq $0x3e8, 0x8(%rsi)       # imm = 0x3E8
movq $0x2a, 0x10(%rsi)
leaq -0x90(%rbp), %rdi
callq 0x87fa
pushq $0x32
popq %r12
leaq -0x170(%rbp), %r15
leaq -0x70(%rbp), %r13
subq $0x1, %r12
jb 0x7f4c
leaq -0xb0(%rbp), %rdi
callq 0x8842
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x8856
movq %rax, %r14
shlq $0x5, %rbx
leaq (%rbx,%rbp), %rsi
addq $-0x250, %rsi           # imm = 0xFDB0
movq %r15, %rdi
callq 0x2240
leaq -0x150(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x247c
movq %r15, %rdi
callq 0x20d0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2afe
movq 0x80b6(%rip), %rdi      # 0xfff0
movq %r13, %rsi
callq 0x21b0
movq %r13, %rdi
callq 0x20d0
jmp 0x7ed0
leaq -0x2c0(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x886a
leaq -0x70(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
movl $0xc350, %edx           # imm = 0xC350
callq 0x3088
leaq -0x2c0(%rbp), %rdi
callq 0x8788
leaq -0xe0(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x2e58
leaq -0x70(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x2f78
movsd %xmm0, -0x40(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x2f78
movsd %xmm0, -0x38(%rbp)
movq 0x802c(%rip), %rdi      # 0xfff0
leaq 0x24c8(%rip), %rsi      # 0xa493
callq 0x21e0
movq %rax, %rdi
movsd -0x40(%rbp), %xmm0
callq 0x2280
leaq 0x2548(%rip), %rsi      # 0xa52c
movq %rax, %rdi
callq 0x21e0
movq 0x7ffd(%rip), %rdi      # 0xfff0
leaq 0x24aa(%rip), %rsi      # 0xa4a4
callq 0x21e0
movq %rax, %rdi
movsd -0x38(%rbp), %xmm0
callq 0x2280
leaq 0x2519(%rip), %rsi      # 0xa52c
movq %rax, %rdi
callq 0x21e0
leaq -0xe0(%rbp), %rdi
callq 0x4290
leaq -0x70(%rbp), %rdi
callq 0x4290
leaq -0x90(%rbp), %rdi
callq 0x3892
leaq -0xb0(%rbp), %rdi
callq 0x3892
movl $0xc0, %ebx
leaq (%rbx,%rbp), %rdi
addq $-0x250, %rdi           # imm = 0xFDB0
callq 0x20d0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x804d
leaq -0x150(%rbp), %rdi
callq 0x8788
movb $0x1, %al
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x80d0
movq %rax, %rbx
jmp 0x80df
movq %rax, %rbx
leaq -0x2c0(%rbp), %rdi
callq 0x8788
jmp 0x810b
jmp 0x8108
movq %rax, %rbx
jmp 0x8117
movq %rax, %rbx
jmp 0x8123
jmp 0x80b5
jmp 0x80b5
jmp 0x80b5
jmp 0x80b5
jmp 0x80b5
movq %rax, %rbx
addq $-0x20, %r15
movq %r15, %rdi
callq 0x20d0
cmpq %r14, %r15
jne 0x80b8
jmp 0x8143
movq %rax, %rbx
jmp 0x8143
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x4290
leaq -0x70(%rbp), %rdi
callq 0x4290
jmp 0x810b
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
jmp 0x80ff
jmp 0x8108
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x20d0
jmp 0x810b
jmp 0x8108
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x3892
leaq -0xb0(%rbp), %rdi
callq 0x3892
movl $0xc0, %r14d
leaq (%r14,%rbp), %rdi
addq $-0x250, %rdi           # imm = 0xFDB0
callq 0x20d0
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x8129
leaq -0x150(%rbp), %rdi
callq 0x8788
movq %rbx, %rdi
callq 0x22d0
nop