// File: /workspace/github_cpp_makefile_star2_O1/redpony[P]cpyp/crp_test.cc
// Function: main
int main() {
  cpyp::MT19937 eng;
  double tot = 0;
  double xt = 0;
  cpyp::crp<int> crp(0.5, 1.0);
  unsigned cust = 10;
  vector<int> hist(cust + 1, 0);
  for (unsigned i = 0; i < cust; ++i) { crp.increment(1, 1.0, eng); }
  const int samples = 200000;
  const bool simulate = true;
  for (int k = 0; k < samples; ++k) {
  if (!simulate) {
    crp.clear();
    for (unsigned i = 0; i < cust; ++i) { crp.increment(1, 1.0, eng); }
  } else {
    unsigned da = cpyp::sample_uniform01<double>(eng) * cust;
    bool a = cpyp::sample_uniform01<double>(eng) < 0.5;
    if (a) {
      for (unsigned i = 0; i < da; ++i) { crp.increment(1, 1.0, eng); }
      for (unsigned i = 0; i < da; ++i) { crp.decrement(1, eng); }
      xt += 1.0;
    } else {
      for (unsigned i = 0; i < da; ++i) { crp.decrement(1, eng); }
      for (unsigned i = 0; i < da; ++i) { crp.increment(1, 1.0, eng); }
    }
  }
  int c = crp.num_tables(1);
  ++hist[c];
  tot += c;
  }
  assert(cust == crp.num_customers());
  cerr << crp << endl;
  cerr << crp.log_likelihood() << endl;
  cerr << "P(a) = " << (xt / samples) << endl;
  cerr << "mean num tables = " << (tot / samples) << endl;
  double error = fabs((tot / samples) - 5.4);
  cerr << "  error = " << error << endl;
  for (unsigned i = 1; i <= cust; ++i)
  cerr << i << ' ' << (hist[i]) << endl;
  if (error > 0.1) {
    cerr << "*** error is too big = " << error << endl;
    return 1;
  }
  test_mh1();
  test_mh1a();
  test_mh2();
  test_mfcrp();
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1448, %rsp           # imm = 0x1448
leaq 0xc0(%rsp), %rdi
callq 0x4c22
leaq 0x48(%rsp), %rdi
movsd 0x59a4(%rip), %xmm0     # 0xa008
movsd 0x59a4(%rip), %xmm1     # 0xa010
callq 0x4cde
movl $0x2c, %edi
callq 0x21b0
xorpd %xmm0, %xmm0
movupd %xmm0, 0x1c(%rax)
movupd %xmm0, 0x10(%rax)
movq %rax, 0x8(%rsp)
movupd %xmm0, (%rax)
movl $0xa, %ebx
leaq 0x48(%rsp), %r14
leaq 0x1c(%rsp), %r15
leaq 0x10(%rsp), %r12
leaq 0xc0(%rsp), %r13
movl $0x1, 0x1c(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x4e9e
decl %ebx
jne 0x46ae
xorl %ebp, %ebp
leaq 0xc0(%rsp), %r14
leaq 0x48(%rsp), %r15
leaq 0x1c(%rsp), %r12
leaq 0x10(%rsp), %r13
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movsd %xmm0, 0x30(%rsp)
movq 0x8(%rsp), %rbx
movq %r14, %rdi
callq 0x78bf
addsd 0x5960(%rip), %xmm0     # 0xa078
mulsd 0x5940(%rip), %xmm0     # 0xa060
movsd %xmm0, 0x40(%rsp)
movq %r14, %rdi
callq 0x78bf
movq %rbp, 0x38(%rsp)
cvttsd2si 0x40(%rsp), %rbx
movsd 0x58c6(%rip), %xmm1     # 0xa008
movl %ebx, %ebp
ucomisd %xmm0, %xmm1
jbe 0x47ac
testl %ebx, %ebx
je 0x4796
movl $0x1, 0x1c(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x10(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x4e9e
decl %ebp
jne 0x474e
movl $0x1, 0x10(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x4d48
decl %ebx
jne 0x477a
movsd 0x30(%rsp), %xmm0
addsd 0x586c(%rip), %xmm0     # 0xa010
movsd %xmm0, 0x30(%rsp)
jmp 0x4804
testl %ebx, %ebx
je 0x4804
movl $0x1, 0x10(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x4d48
decl %ebp
jne 0x47b0
movq 0x38(%rsp), %rbp
movl $0x1, 0x1c(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x10(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x4e9e
decl %ebx
jne 0x47d1
movq 0x8(%rsp), %rbx
jmp 0x480e
movq 0x8(%rsp), %rbx
movq 0x38(%rsp), %rbp
movl $0x1, 0x10(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x4be2
cltq
incl (%rbx,%rax,4)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movapd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
incl %ebp
cmpl $0x30d40, %ebp          # imm = 0x30D40
jne 0x4708
cmpl $0xa, 0x4c(%rsp)
jne 0x4b25
movq 0x9793(%rip), %r14      # 0xdff0
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x8e16
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x9768(%rip), %rdi      # 0xdff0
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x88(%rsp), %rsi
leaq 0x90(%rsp), %rdx
leaq 0x48(%rsp), %rdi
callq 0x5dda
movq 0x973a(%rip), %rdi      # 0xdff0
callq 0x2230
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x9704(%rip), %rdi      # 0xdff0
leaq 0x5bfa(%rip), %rsi      # 0xa4ed
movl $0x7, %edx
callq 0x21c0
movsd 0x30(%rsp), %xmm0
divsd 0x5735(%rip), %xmm0     # 0xa040
movq 0x96de(%rip), %rdi      # 0xdff0
callq 0x2230
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x96a8(%rip), %rdi      # 0xdff0
leaq 0x5ba6(%rip), %rsi      # 0xa4f5
movl $0x12, %edx
callq 0x21c0
movapd 0x20(%rsp), %xmm0
divsd 0x56d9(%rip), %xmm0     # 0xa040
movq 0x9682(%rip), %rdi      # 0xdff0
movapd %xmm0, 0x20(%rsp)
callq 0x2230
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x9646(%rip), %rdi      # 0xdff0
leaq 0x5b57(%rip), %rsi      # 0xa508
movl $0xa, %edx
callq 0x21c0
movapd 0x20(%rsp), %xmm0
addsd 0x569f(%rip), %xmm0     # 0xa068
andpd 0x56cf(%rip), %xmm0     # 0xa0a0
movq 0x9618(%rip), %rdi      # 0xdff0
movapd %xmm0, 0x20(%rsp)
callq 0x2230
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movl $0x1, %r14d
movq 0x95d6(%rip), %r15      # 0xdff0
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
callq 0x20f0
movb $0x20, 0x10(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x21c0
movl (%rbx,%r14,4), %esi
movq %rax, %rdi
callq 0x2260
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
incq %r14
cmpq $0xb, %r14
jne 0x4a1f
movapd 0x20(%rsp), %xmm0
ucomisd 0x55e4(%rip), %xmm0     # 0xa070
jbe 0x4ae9
movq 0x955b(%rip), %rdi      # 0xdff0
leaq 0x5a77(%rip), %rsi      # 0xa513
movl $0x17, %edx
callq 0x21c0
movq 0x9543(%rip), %rdi      # 0xdff0
movapd 0x20(%rsp), %xmm0
callq 0x2230
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2100
jmp 0x4aff
callq 0x253f
callq 0x2bc8
callq 0x3222
xorl %ebp, %ebp
callq 0x3f86
movq %rbx, %rdi
callq 0x2180
leaq 0x50(%rsp), %rdi
callq 0x5d20
movl %ebp, %eax
addq $0x1448, %rsp           # imm = 0x1448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x599a(%rip), %rdi      # 0xa4c6
leaq 0x5904(%rip), %rsi      # 0xa437
leaq 0x59a8(%rip), %rcx      # 0xa4e2
movl $0x13b, %edx            # imm = 0x13B
callq 0x20e0
movq %rax, %r14
jmp 0x4b70
jmp 0x4b55
jmp 0x4b55
jmp 0x4b55
jmp 0x4b55
jmp 0x4b60
jmp 0x4b60
movq %rax, %r14
jmp 0x4b68
jmp 0x4b60
jmp 0x4b60
jmp 0x4b60
movq %rax, %r14
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2180
leaq 0x50(%rsp), %rdi
callq 0x5d20
movq %r14, %rdi
callq 0x2270