// File: /workspace/github_cpp_makefile_star2_O1/redpony[P]cpyp/./cpyp/mf_crp.h
// Function: cpyp::mf_crp<2u, unsigned int, std::hash<unsigned int>>::log_likelihood(double const&, double const&) const
double log_likelihood(const double& discount, const double& strength) const {
    double lp = 0.0;
    if (has_discount_prior())
      lp = Md::log_beta_density(discount, discount_prior_strength_, discount_prior_beta_);
    if (has_strength_prior())
      lp += Md::log_gamma_density(strength + discount, strength_prior_shape_, strength_prior_rate_);
    assert(lp <= 0.0);
    if (num_customers_) {  // if restaurant is not empty
      if (discount > 0.0) {  // two parameter case: discount > 0
        const double r = lgamma(1.0 - discount);
        if (strength)
          lp += lgamma(strength) - lgamma(strength / discount);
        lp += - lgamma(strength + num_customers_)
             + num_tables_ * log(discount) + lgamma(strength / discount + num_tables_);
        // above line implies
        // 1) when adding a customer to a restaurant containing N customers:
        //    lp -= log(strength + N)    [because \Gamma(s+N+1) = (s+N)\Gamma(s+N)
        // 2) when removing a customer from a restaurant containing N customers:
        //    lp += log(strength + N - 1)  [because \Gamma(s+N) = (s+N-1)\Gamma(s+N-1)]
        // 3) when adding a table to a restaurant containing T tables:
        //    lp += log(discount) + log(s / d + T)
        // 4) when removing a table from a restuarant containint T tables:
        //    lp -= log(discount) + log(s / d + T - 1)

        assert(std::isfinite(lp));
        for (auto& dish_loc : dish_locs_)
          for (unsigned floor = 0; floor < NumFloors; ++floor)
            for (auto& bin : dish_loc.second.h[floor])
              lp += (lgamma(bin.first - discount) - r) * bin.second;
         // above implies
         // 1) when adding to a table seating N > 1 customers
         //    lp += log(N - discount)
         // 2) when adding a new table
         //    do nothing
         // 3) when removing a customer from a table with N > 1 customers
         //    lp -= log(N - discount - 1)
         // 4) when closing a table
         //    do nothing
      } else if (!discount) { // discount == 0.0 (ie, Dirichlet Process)
        lp += lgamma(strength) + num_tables_ * log(strength) - lgamma(strength + num_tables_);
        assert(std::isfinite(lp));
        for (auto& dish_loc : dish_locs_)
          lp += lgamma(dish_loc.second.num_tables());
      } else { // should never happen
        assert(!"discount less than 0 detected!");
      }
    }
    assert(std::isfinite(lp));
    return lp;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movsd 0x50(%rdi), %xmm0
ucomisd %xmm0, %xmm0
jp 0x81e4
leaq 0x50(%r14), %rsi
leaq 0x58(%r14), %rdx
movq %rbx, %rdi
callq 0x6288
movsd %xmm0, 0x8(%rsp)
movsd 0x60(%r14), %xmm0
ucomisd %xmm0, %xmm0
jp 0x81ed
movsd (%r15), %xmm0
addsd (%rbx), %xmm0
leaq 0x60(%r14), %rsi
leaq 0x30(%rsp), %rdi
movsd %xmm0, (%rdi)
leaq 0x68(%r14), %rdx
callq 0x640c
movsd 0x8(%rsp), %xmm2
addsd %xmm0, %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm2, %xmm0
jb 0x81f8
cmpl $0x0, 0x4(%r14)
movabsq $0x7ff0000000000000, %r12 # imm = 0x7FF0000000000000
je 0x81b8
movsd (%rbx), %xmm1
ucomisd %xmm0, %xmm1
movsd %xmm2, 0x8(%rsp)
jbe 0x7f68
movsd 0x20fe(%rip), %xmm0     # 0xa010
subsd %xmm1, %xmm0
callq 0x2130
movsd %xmm0, 0x18(%rsp)
movsd (%r15), %xmm0
ucomisd 0x214a(%rip), %xmm0     # 0xa078
jne 0x7f36
jnp 0x801f
callq 0x2130
movsd %xmm0, 0x10(%rsp)
movsd (%r15), %xmm0
divsd (%rbx), %xmm0
callq 0x2130
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
jmp 0x8025
jne 0x8236
jp 0x8236
movsd (%r15), %xmm0
callq 0x2130
movsd %xmm0, 0x18(%rsp)
movl (%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd (%r15), %xmm0
callq 0x2150
mulsd 0x10(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movl (%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd (%r15), %xmm0
callq 0x2130
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm2
addsd %xmm1, %xmm2
movq %xmm2, %rax
btrq $0x3f, %rax
cmpq %r12, %rax
jge 0x8274
movq 0x18(%r14), %rbx
testq %rbx, %rbx
je 0x81b8
movsd %xmm2, 0x8(%rsp)
movl 0x14(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
callq 0x2130
movsd 0x8(%rsp), %xmm2
addsd %xmm0, %xmm2
movq (%rbx), %rbx
jmp 0x7ff1
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0x4(%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd (%r15), %xmm0
callq 0x2130
movsd %xmm0, 0x10(%rsp)
movl (%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd (%rbx), %xmm0
callq 0x2150
mulsd 0x20(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd (%r15), %xmm1
divsd (%rbx), %xmm1
movl (%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd %xmm1, %xmm0
callq 0x2130
movapd %xmm0, %xmm2
addsd 0x10(%rsp), %xmm2
addsd 0x8(%rsp), %xmm2
movq %xmm2, %rax
btrq $0x3f, %rax
cmpq %r12, %rax
jge 0x8255
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x81b8
movq %rax, 0x28(%rsp)
addq $0x18, %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, %rcx
shlq $0x7, %rcx
movq 0x20(%rsp), %rdx
leaq (%rdx,%rcx), %rax
movb 0x79(%rdx,%rcx), %r14b
testb %r14b, %r14b
je 0x80f8
movq (%rax), %rcx
movq 0x10(%rcx), %rbp
jmp 0x80fd
movq %rax, %r15
xorl %ebp, %ebp
testb %r14b, %r14b
jne 0x810a
movzbl 0x78(%rax), %ecx
leaq (%rax,%rcx,8), %r13
xorl %eax, %eax
cmpq %r15, %r13
setne %al
xorl %ecx, %ecx
testq %rbp, %rbp
setne %cl
testb %r14b, %r14b
cmovel %eax, %ecx
cmpb $0x1, %cl
jne 0x8195
movsd %xmm2, 0x8(%rsp)
leaq 0x8(%rbp), %r12
testb %r14b, %r14b
cmoveq %r15, %r12
movl (%r12), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subsd (%rbx), %xmm0
callq 0x2130
testb %r14b, %r14b
je 0x8156
movq (%rbp), %rbp
jmp 0x815a
addq $0x8, %r15
movsd 0x8(%rsp), %xmm2
subsd 0x18(%rsp), %xmm0
movl 0x4(%r12), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm1, %xmm2
xorl %eax, %eax
cmpq %r15, %r13
setne %al
xorl %ecx, %ecx
testq %rbp, %rbp
setne %cl
testb %r14b, %r14b
cmovel %eax, %ecx
testb %cl, %cl
jne 0x8125
movq 0x10(%rsp), %rcx
leaq 0x1(%rcx), %rax
testq %rcx, %rcx
je 0x80d0
movq 0x28(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
jne 0x80c0
movq %xmm2, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
cmpq %rcx, %rax
jge 0x8217
movapd %xmm2, %xmm0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm0, %xmm0
jmp 0x7e98
movsd 0x8(%rsp), %xmm2
jmp 0x7ed7
leaq 0x239a(%rip), %rdi      # 0xa599
leaq 0x2745(%rip), %rsi      # 0xa94b
leaq 0x274e(%rip), %rcx      # 0xa95b
movl $0x102, %edx            # imm = 0x102
callq 0x20e0
leaq 0x2406(%rip), %rdi      # 0xa624
leaq 0x2726(%rip), %rsi      # 0xa94b
leaq 0x272f(%rip), %rcx      # 0xa95b
movl $0x12b, %edx            # imm = 0x12B
callq 0x20e0
leaq 0x23f9(%rip), %rdi      # 0xa636
leaq 0x2707(%rip), %rsi      # 0xa94b
leaq 0x2710(%rip), %rcx      # 0xa95b
movl $0x128, %edx            # imm = 0x128
callq 0x20e0
leaq 0x23c8(%rip), %rdi      # 0xa624
leaq 0x26e8(%rip), %rsi      # 0xa94b
leaq 0x26f1(%rip), %rcx      # 0xa95b
movl $0x114, %edx            # imm = 0x114
callq 0x20e0
leaq 0x23a9(%rip), %rdi      # 0xa624
leaq 0x26c9(%rip), %rsi      # 0xa94b
leaq 0x26d2(%rip), %rcx      # 0xa95b
movl $0x124, %edx            # imm = 0x124
callq 0x20e0
nop