// File: /workspace/github_cpp_makefile_star2_O1/redpony[P]cpyp/crp_test.cc
// Function: test_mh1a()
void test_mh1a() {
  cpyp::MT19937 eng;
  const vector<double> ref = {0, 0, 0, 0.00466121, 0.0233846, 0.0647365, 0.125693, 0.183448, 0.204806, 0.177036, 0.119629, 0.0627523, 0.02507, 0.00725451, 0.0013911};
  cpyp::crp<int> crp(0.5, 1.0);
  vector<int> hist(15, 0);
  double c = 0;
  double ac = 0;
  double tmh = 0;
  for (int s = 0; s < 200000; ++s) {
    for (int i = 0; i < 15; ++i) {
      int y_i = i % 3;
      cpyp::crp<int> prev = crp;  // save old state
      double lq_old = 0;
      double lp_old = llh(crp, p0);
      if (s > 0) crp.decrement(y_i, eng, &lq_old);

      double lq_new = 0;
      crp.increment_no_base(y_i, eng, &lq_new);
      if (s > 0) {
        double lp_new = llh(crp, p0);
        double a = exp(lp_new - lp_old + lq_old - lq_new);
        ++tmh;
        if (a >= 1.0 || cpyp::sample_uniform01<double>(eng) < a) { // mh accept
          ++ac;
        } else { // mh reject
          std::swap(crp, prev);  // swap is faster than =
        }
      }
    }
    if (s > 300 && s % 4 == 3) { ++c; hist[crp.num_tables()]++; }
  }
  ac /= tmh;
  cerr << "ACCEPTANCE: " << ac << endl;
  int j =0;
  double te = 0;
  double me = 0;
  for (auto i : hist) {
    double err = (i / c - ref[j++]);
    cerr << err << "\t" << i/c << endl;
    te += fabs(err);
    if (fabs(err) > me) { me = fabs(err); }
  }
  te /= 12;
  cerr << "Average error: " << te;
  if (te > 0.01) { cerr << "  ** TOO HIGH **"; }
  cerr << endl << "    Max error: " << me;
  if (me > 0.01) { cerr << "  ** TOO HIGH **"; }
  cerr << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1558, %rsp           # imm = 0x1558
leaq 0x1d0(%rsp), %rdi
callq 0x4c22
leaq 0x758b(%rip), %rsi      # 0xa178
leaq 0x158(%rsp), %rax
movl $0xf, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x50(%rsp), %rdi
leaq 0x68(%rsp), %rcx
movl $0xf, %edx
movq %rax, %rsi
callq 0x4ca0
leaq 0x68(%rsp), %rdi
movsd 0x73e4(%rip), %xmm0     # 0xa008
movsd 0x73e4(%rip), %xmm1     # 0xa010
callq 0x4cde
movl $0x3c, %edi
callq 0x21b0
xorpd %xmm0, %xmm0
movupd %xmm0, 0x2c(%rax)
movupd %xmm0, 0x20(%rax)
movupd %xmm0, 0x10(%rax)
movq %rax, 0x18(%rsp)
movupd %xmm0, (%rax)
leaq 0xe8(%rsp), %r14
leaq 0x70(%rsp), %r15
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x20(%rsp)
xorl %r12d, %r12d
movl $0xf, %ebp
xorl %r13d, %r13d
movl %r13d, %eax
movl $0xaaaaaaab, %ecx       # imm = 0xAAAAAAAB
imulq %rcx, %rax
shrq $0x21, %rax
leal (%rax,%rax,2), %eax
movl %r13d, %ecx
subl %eax, %ecx
movl %ecx, 0x14(%rsp)
movq 0x68(%rsp), %rax
movq 0x78(%rsp), %rcx
movq %rax, 0xe0(%rsp)
movq %rbx, 0xe8(%rsp)
movq %rcx, 0xf0(%rsp)
movq %rbx, 0xf8(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x100(%rsp)
movups 0x20(%r15), %xmm0
movups %xmm0, 0x20(%r14)
movq %rbx, 0x118(%rsp)
movq %r14, 0x158(%rsp)
movq %r14, %rdi
movq %r15, %rsi
leaq 0x158(%rsp), %rdx
callq 0x5b0e
movq 0x68(%r15), %rax
movq %rax, 0x68(%r14)
movupd 0x38(%r15), %xmm0
movupd 0x48(%r15), %xmm1
movupd 0x58(%r15), %xmm2
movupd %xmm2, 0x58(%r14)
movupd %xmm1, 0x48(%r14)
movupd %xmm0, 0x38(%r14)
movq $0x0, 0x40(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x7415(%rip), %rsi      # 0xa160
callq 0x24b1
movsd %xmm0, (%rsp)
testl %r12d, %r12d
je 0x2d76
leaq 0x68(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x1d0(%rsp), %rdx
leaq 0x40(%rsp), %rcx
callq 0x4d48
movq $0x0, 0x38(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x1d0(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0x5034
testl %r12d, %r12d
je 0x2ef5
leaq 0x68(%rsp), %rdi
leaq 0x73b0(%rip), %rsi      # 0xa160
callq 0x24b1
subsd (%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
subsd 0x38(%rsp), %xmm0
callq 0x2280
movapd %xmm0, %xmm2
movsd 0x7239(%rip), %xmm0     # 0xa010
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd %xmm2, (%rsp)
ucomisd %xmm0, %xmm2
jae 0x2e0a
leaq 0x1d0(%rsp), %rdi
callq 0x78bf
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x2e23
movsd 0x8(%rsp), %xmm0
addsd 0x71f8(%rip), %xmm0     # 0xa010
movsd %xmm0, 0x8(%rsp)
jmp 0x2ef5
movq 0x68(%rsp), %rax
movq %rax, 0x158(%rsp)
leaq 0x160(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x7b4c
movq 0x68(%r15), %rax
movq %rax, 0x68(%rbx)
movups 0x38(%r15), %xmm0
movups 0x48(%r15), %xmm1
movups 0x58(%r15), %xmm2
movups %xmm2, 0x58(%rbx)
movups %xmm1, 0x48(%rbx)
movups %xmm0, 0x38(%rbx)
movq 0xe0(%rsp), %rax
movq %rax, 0x68(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x22c0
movq 0x68(%r14), %rax
movq %rax, 0x68(%r15)
movups 0x38(%r14), %xmm0
movups 0x48(%r14), %xmm1
movups 0x58(%r14), %xmm2
movups %xmm2, 0x58(%r15)
movups %xmm1, 0x48(%r15)
movups %xmm0, 0x38(%r15)
movq 0x158(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22c0
movq 0x68(%rbx), %rax
movq %rax, 0x68(%r14)
movupd 0x38(%rbx), %xmm0
movupd 0x48(%rbx), %xmm1
movupd 0x58(%rbx), %xmm2
movupd %xmm2, 0x58(%r14)
movupd %xmm1, 0x48(%r14)
movupd %xmm0, 0x38(%r14)
movq %rbx, %rdi
callq 0x5d20
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x5d20
incl %r13d
decl %ebp
jne 0x2c87
cmpl $0x12d, %r12d           # imm = 0x12D
setae %al
movl %r12d, %ecx
notl %ecx
testb $0x3, %cl
sete %cl
testb %cl, %al
je 0x2f41
movsd 0x30(%rsp), %xmm0
addsd 0x70e1(%rip), %xmm0     # 0xa010
movsd %xmm0, 0x30(%rsp)
movl 0x68(%rsp), %eax
movq 0x18(%rsp), %rcx
incl (%rcx,%rax,4)
incl %r12d
cmpl $0x30d40, %r12d         # imm = 0x30D40
jne 0x2c7f
movq 0xb098(%rip), %rdi      # 0xdff0
leaq 0x7479(%rip), %rsi      # 0xa3d8
movl $0xc, %edx
callq 0x21c0
movsd 0x8(%rsp), %xmm0
divsd 0x20(%rsp), %xmm0
movq 0xb074(%rip), %rdi      # 0xdff0
callq 0x2230
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
xorpd %xmm1, %xmm1
xorl %r12d, %r12d
movq 0xb037(%rip), %rbx      # 0xdff0
leaq 0x7425(%rip), %r14      # 0xa3e5
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd %xmm1, 0x48(%rsp)
movq 0x18(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r12), %xmm0
divsd 0x30(%rsp), %xmm0
movq 0x50(%rsp), %rax
movsd %xmm0, 0x8(%rsp)
subsd (%rax,%r12,2), %xmm0
movq %rbx, %rdi
movapd %xmm0, 0x20(%rsp)
callq 0x2230
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x21c0
movq %r15, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x2230
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movapd 0x20(%rsp), %xmm0
andpd 0x7045(%rip), %xmm0     # 0xa0a0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
maxsd 0x48(%rsp), %xmm0
addq $0x4, %r12
movapd %xmm0, %xmm1
cmpq $0x3c, %r12
jne 0x2fc9
movapd %xmm0, 0x20(%rsp)
movq 0xaf62(%rip), %rdi      # 0xdff0
leaq 0x7352(%rip), %rsi      # 0xa3e7
movl $0xf, %edx
callq 0x21c0
movsd (%rsp), %xmm0
divsd 0x6f6c(%rip), %xmm0     # 0xa018
movsd %xmm0, (%rsp)
movq 0xaf38(%rip), %rbx      # 0xdff0
movq %rbx, %rdi
movsd (%rsp), %xmm0
callq 0x2230
movsd (%rsp), %xmm0
ucomisd 0x6f4e(%rip), %xmm0     # 0xa020
jbe 0x30ec
movq 0xaf15(%rip), %rdi      # 0xdff0
leaq 0x7315(%rip), %rsi      # 0xa3f7
movl $0x10, %edx
callq 0x21c0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0xaee6(%rip), %rbx      # 0xdff0
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq %rax, %r14
leaq 0x72e4(%rip), %rsi      # 0xa408
movl $0xf, %edx
movq %rax, %rdi
callq 0x21c0
movq %r14, %rdi
movapd 0x20(%rsp), %xmm0
callq 0x2230
movapd 0x20(%rsp), %xmm0
ucomisd 0x6ed3(%rip), %xmm0     # 0xa020
jbe 0x3167
movq 0xae9a(%rip), %rdi      # 0xdff0
leaq 0x729a(%rip), %rsi      # 0xa3f7
movl $0x10, %edx
callq 0x21c0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0xae6b(%rip), %rdi      # 0xdff0
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x18(%rsp), %rdi
callq 0x2180
leaq 0x70(%rsp), %rdi
callq 0x5d20
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x31b5
callq 0x2180
addq $0x1558, %rsp           # imm = 0x1558
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x3201
movq %rax, %rbx
jmp 0x320b
jmp 0x31e7
jmp 0x31e7
jmp 0x31d7
movq %rax, %rdi
callq 0x59a4
jmp 0x31e7
jmp 0x31ec
jmp 0x31ec
jmp 0x31ec
movq %rax, %rbx
jmp 0x31f7
movq %rax, %rbx
movq %r14, %rdi
callq 0x5d20
movq 0x18(%rsp), %rdi
callq 0x2180
leaq 0x70(%rsp), %rdi
callq 0x5d20
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x321a
callq 0x2180
movq %rbx, %rdi
callq 0x2270