// File: 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:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movq 0xf0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xd8(%rsp)
callq 0x11bd0
testb $0x1, %al
jne 0x11c53
jmp 0x11c79
movq 0x38(%rsp), %rdx
movq 0xe8(%rsp), %rdi
movq %rdx, %rsi
addq $0x50, %rsi
addq $0x58, %rdx
callq 0xa7a0
movsd %xmm0, 0xd8(%rsp)
movq 0x38(%rsp), %rdi
callq 0x11bf0
testb $0x1, %al
jne 0x11c89
jmp 0x11cd9
movq 0x38(%rsp), %rdx
movq 0xe0(%rsp), %rax
movsd (%rax), %xmm0
movq 0xe8(%rsp), %rax
addsd (%rax), %xmm0
movsd %xmm0, 0xd0(%rsp)
movq %rdx, %rsi
addq $0x60, %rsi
addq $0x68, %rdx
leaq 0xd0(%rsp), %rdi
callq 0xa950
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
xorps %xmm0, %xmm0
ucomisd 0xd8(%rsp), %xmm0
jb 0x11ce9
jmp 0x11d08
leaq 0x38ba(%rip), %rdi      # 0x155aa
leaq 0x3d46(%rip), %rsi      # 0x15a3d
movl $0x102, %edx            # imm = 0x102
leaq 0x3d4a(%rip), %rcx      # 0x15a4d
callq 0x20e0
movq 0x38(%rsp), %rax
cmpl $0x0, 0x4(%rax)
je 0x121d7
movq 0xe8(%rsp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x12041
movq 0xe8(%rsp), %rax
movsd 0x32d0(%rip), %xmm0     # 0x15010
subsd (%rax), %xmm0
callq 0x2110
movsd %xmm0, 0xc8(%rsp)
movq 0xe0(%rsp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x11d6b
jp 0x11d6b
jmp 0x11dbe
movq 0xe0(%rsp), %rax
movsd (%rax), %xmm0
callq 0x2110
movsd %xmm0, 0x30(%rsp)
movq 0xe0(%rsp), %rax
movsd (%rax), %xmm0
movq 0xe8(%rsp), %rax
divsd (%rax), %xmm0
callq 0x2110
movaps %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movq 0x38(%rsp), %rax
movq 0xe0(%rsp), %rcx
movsd (%rcx), %xmm0
movl 0x4(%rax), %eax
cvtsi2sd %rax, %xmm1
addsd %xmm1, %xmm0
callq 0x2110
movq 0x38(%rsp), %rax
movsd %xmm0, 0x18(%rsp)
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0xe8(%rsp), %rax
movsd (%rax), %xmm0
callq 0x2130
movsd 0x18(%rsp), %xmm1
movq 0x38(%rsp), %rax
movaps %xmm0, %xmm2
movsd 0x20(%rsp), %xmm0
mulsd %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0xe0(%rsp), %rcx
movsd (%rcx), %xmm0
movq 0xe8(%rsp), %rcx
movsd (%rcx), %xmm1
divsd %xmm1, %xmm0
movl (%rax), %eax
cvtsi2sd %rax, %xmm1
addsd %xmm1, %xmm0
callq 0x2110
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movsd 0xd8(%rsp), %xmm0
callq 0xaac0
testb $0x1, %al
jne 0x11e8a
jmp 0x11e8c
jmp 0x11eab
leaq 0x37a2(%rip), %rdi      # 0x15635
leaq 0x3ba3(%rip), %rsi      # 0x15a3d
movl $0x114, %edx            # imm = 0x114
leaq 0x3ba7(%rip), %rcx      # 0x15a4d
callq 0x20e0
movq 0x38(%rsp), %rax
addq $0x8, %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x12220
movq %rax, 0xb8(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x12250
movq %rax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x12280
testb $0x1, %al
jne 0x11f04
jmp 0x1203c
leaq 0xb8(%rsp), %rdi
callq 0x122a0
movq %rax, 0xa8(%rsp)
movl $0x0, 0xa4(%rsp)
cmpl $0x2, 0xa4(%rsp)
jae 0x12028
movq 0xa8(%rsp), %rax
addq $0x8, %rax
addq $0x8, %rax
movl 0xa4(%rsp), %ecx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0xaba0
movq 0x98(%rsp), %rsi
leaq 0x68(%rsp), %rdi
callq 0xabd0
leaq 0x80(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0xac00
testb $0x1, %al
jne 0x11f97
jmp 0x12010
leaq 0x80(%rsp), %rdi
callq 0xac30
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movq 0xe8(%rsp), %rax
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
callq 0x2110
movsd 0xc8(%rsp), %xmm1
subsd %xmm1, %xmm0
movq 0x60(%rsp), %rax
movl 0x4(%rax), %eax
cvtsi2sd %rax, %xmm2
movsd 0xd8(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xd8(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xac80
jmp 0x11f7f
jmp 0x12012
movl 0xa4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa4(%rsp)
jmp 0x11f24
jmp 0x1202a
leaq 0xb8(%rsp), %rdi
callq 0x122c0
jmp 0x11ee6
jmp 0x121d5
movq 0xe8(%rsp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x121b4
jp 0x121b4
movq 0xe0(%rsp), %rax
movsd (%rax), %xmm0
callq 0x2110
movq 0x38(%rsp), %rax
movsd %xmm0, (%rsp)
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xe0(%rsp), %rax
movsd (%rax), %xmm0
callq 0x2130
movsd (%rsp), %xmm1
movq 0x38(%rsp), %rax
movaps %xmm0, %xmm2
movsd 0x8(%rsp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0xe0(%rsp), %rcx
movsd (%rcx), %xmm0
movl (%rax), %eax
cvtsi2sd %rax, %xmm1
addsd %xmm1, %xmm0
callq 0x2110
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movsd 0xd8(%rsp), %xmm0
callq 0xaac0
testb $0x1, %al
jne 0x12109
jmp 0x1210b
jmp 0x1212a
leaq 0x3523(%rip), %rdi      # 0x15635
leaq 0x3924(%rip), %rsi      # 0x15a3d
movl $0x124, %edx            # imm = 0x124
leaq 0x3928(%rip), %rcx      # 0x15a4d
callq 0x20e0
movq 0x38(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdi
callq 0x12220
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rdi
callq 0x12250
movq %rax, 0x48(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x12280
testb $0x1, %al
jne 0x1216b
jmp 0x121b2
leaq 0x50(%rsp), %rdi
callq 0x122a0
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
addq $0x8, %rdi
callq 0x122f0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
callq 0x2110
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x122c0
jmp 0x12156
jmp 0x121d3
leaq 0x348c(%rip), %rdi      # 0x15647
leaq 0x387b(%rip), %rsi      # 0x15a3d
movl $0x128, %edx            # imm = 0x128
leaq 0x387f(%rip), %rcx      # 0x15a4d
callq 0x20e0
jmp 0x121d5
jmp 0x121d7
movsd 0xd8(%rsp), %xmm0
callq 0xaac0
testb $0x1, %al
jne 0x121eb
jmp 0x121ed
jmp 0x1220c
leaq 0x3441(%rip), %rdi      # 0x15635
leaq 0x3842(%rip), %rsi      # 0x15a3d
movl $0x12b, %edx            # imm = 0x12B
leaq 0x3846(%rip), %rcx      # 0x15a4d
callq 0x20e0
movsd 0xd8(%rsp), %xmm0
addq $0xf8, %rsp
retq
nopl (%rax)