// File: /workspace/github_cpp_makefile_star2_O3/hkbu-victor[P]SFastLDA/super_fast_final1_d.cpp
// Function: eval_likelihood()
void eval_likelihood(){

	//assume symmetric alpha and beta
  double log_likelihood = 0.0;
  double ALPHA_BAR = ALPHA[0] * T;
  double BETA_BAR = WBETA;
  int wi, di, j;

  double lgamma_beta = lgamma(BETA);
  double lgamma_alpha = lgamma(ALPHA[0]);

  for (wi=0; wi<W; wi++){
     wi_idx = wpIdx[wi];
     wi_array = wpVal[wi];
     for (j=0; j<W_pair_count[wi]; j++){
     	log_likelihood += lgamma(BETA + wi_array[ wi_idx[j] ]) - lgamma_beta;
     }
  }

  for (di=0; di<D; di++){
	  dp_pair_idx = dpIdx[di];
	  dp_pair_val = dpVal[di];

	  for (j=0; j<D_pair_count[di]; j++){
		  log_likelihood += lgamma(ALPHA[0] + dp_pair_val[j]) - lgamma_alpha;
	  }
  }

  for (j=0; j<T; j++)
	  log_likelihood += lgamma(BETA_BAR) - lgamma(BETA_BAR + ztot[j] );

  for (di=0; di<D; di++){
	  log_likelihood += lgamma(ALPHA_BAR) - lgamma(ALPHA_BAR + doc_lens[di] );
  }

  log_likelihood = log_likelihood / nTokens;

  printf("LOG LIKELIHOOD (per token) : %lf\n", log_likelihood);

}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq 0x4894(%rip), %rax      # 0x61b0
cvtsi2sdl 0x47e4(%rip), %xmm0 # 0x6108
mulsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x4862(%rip), %xmm0     # 0x6198
movsd %xmm0, 0x10(%rsp)
movsd 0x484c(%rip), %xmm0     # 0x6190
callq 0x1090
movsd %xmm0, 0x20(%rsp)
movq 0x485a(%rip), %rax      # 0x61b0
movsd (%rax), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movl 0x47ad(%rip), %ecx      # 0x6118
xorpd %xmm1, %xmm1
testl %ecx, %ecx
jle 0x1a10
movq 0x4802(%rip), %rax      # 0x6180
xorl %ebx, %ebx
movq 0x4879(%rip), %rdx      # 0x6200
movq (%rdx,%rbx,8), %rdx
movq %rdx, 0x485e(%rip)      # 0x61f0
movq 0x485f(%rip), %rdx      # 0x61f8
movq (%rdx,%rbx,8), %rdx
movq %rdx, 0x4844(%rip)      # 0x61e8
cmpl $0x0, (%rax,%rbx,4)
jle 0x1a01
xorl %r14d, %r14d
movsd %xmm1, (%rsp)
movq 0x482f(%rip), %rax      # 0x61e8
movq 0x4830(%rip), %rcx      # 0x61f0
movslq (%rcx,%r14,4), %rcx
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%rcx,4), %xmm0
addsd 0x47bc(%rip), %xmm0     # 0x6190
callq 0x1090
movsd (%rsp), %xmm1
subsd 0x20(%rsp), %xmm0
addsd %xmm0, %xmm1
incq %r14
movq 0x478e(%rip), %rax      # 0x6180
movslq (%rax,%rbx,4), %rcx
cmpq %rcx, %r14
jl 0x19ad
movl 0x4717(%rip), %ecx      # 0x6118
incq %rbx
movslq %ecx, %rdx
cmpq %rdx, %rbx
jl 0x1980
movl 0x46fe(%rip), %eax      # 0x6114
testl %eax, %eax
jle 0x1ab0
movq 0x4753(%rip), %rcx      # 0x6178
xorl %ebx, %ebx
movq 0x4822(%rip), %rdx      # 0x6250
movq (%rdx,%rbx,8), %rdx
movq %rdx, 0x480f(%rip)      # 0x6248
movq 0x47c8(%rip), %rdx      # 0x6208
movq (%rdx,%rbx,8), %rdx
movq %rdx, 0x4795(%rip)      # 0x61e0
cmpl $0x0, (%rcx,%rbx,4)
jle 0x1aa1
xorl %r14d, %r14d
movsd %xmm1, (%rsp)
movq 0x4750(%rip), %rax      # 0x61b0
movq 0x4779(%rip), %rcx      # 0x61e0
xorps %xmm0, %xmm0
cvtsi2sdl (%rcx,%r14,4), %xmm0
addsd (%rax), %xmm0
callq 0x1090
movsd (%rsp), %xmm1
subsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm1
incq %r14
movq 0x46e6(%rip), %rcx      # 0x6178
movslq (%rcx,%rbx,4), %rax
cmpq %rax, %r14
jl 0x1a54
movl 0x4673(%rip), %eax      # 0x6114
incq %rbx
movslq %eax, %rdx
cmpq %rdx, %rbx
jl 0x1a27
cmpl $0x0, 0x4651(%rip)      # 0x6108
jle 0x1b13
xorl %ebx, %ebx
movsd %xmm1, (%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movq 0x4658(%rip), %rax      # 0x6130
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%rbx,4), %xmm0
addsd 0x10(%rsp), %xmm0
callq 0x1090
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
subsd %xmm0, %xmm2
addsd %xmm2, %xmm1
incq %rbx
movslq 0x4600(%rip), %rax      # 0x6108
cmpq %rax, %rbx
jl 0x1abb
movl 0x4601(%rip), %eax      # 0x6114
testl %eax, %eax
jle 0x1b6b
xorl %ebx, %ebx
movsd %xmm1, (%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movq 0x462a(%rip), %rax      # 0x6160
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%rbx,4), %xmm0
addsd 0x18(%rsp), %xmm0
callq 0x1090
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
subsd %xmm0, %xmm2
addsd %xmm2, %xmm1
incq %rbx
movslq 0x45ae(%rip), %rax      # 0x6114
cmpq %rax, %rbx
jl 0x1b19
xorps %xmm0, %xmm0
cvtsi2sdl 0x45b2(%rip), %xmm0 # 0x6128
divsd %xmm0, %xmm1
leaq 0x2501(%rip), %rdi      # 0x4082
movapd %xmm1, %xmm0
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r14
jmp 0x1040