// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq 0x4a69(%rip), %rax      # 0x61a8
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
cvtsi2sdl 0x49af(%rip), %xmm0 # 0x6100
movsd %xmm0, 0x28(%rsp)
movsd 0x4a31(%rip), %xmm0     # 0x6190
movsd %xmm0, 0x20(%rsp)
movsd 0x4a1b(%rip), %xmm0     # 0x6188
callq 0x1080
movsd %xmm0, 0x30(%rsp)
movq 0x4a29(%rip), %rax      # 0x61a8
movsd (%rax), %xmm0
callq 0x1080
movsd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebx, %ebx
movslq 0x496f(%rip), %rax      # 0x6110
cmpq %rax, %rbx
jge 0x1824
movq 0x4a4b(%rip), %rax      # 0x61f8
movq (%rax,%rbx,8), %rax
movq %rax, 0x4a30(%rip)      # 0x61e8
movq 0x4a31(%rip), %rax      # 0x61f0
movq (%rax,%rbx,8), %rax
movq %rax, 0x4a16(%rip)      # 0x61e0
xorl %r14d, %r14d
movq 0x49a4(%rip), %rax      # 0x6178
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r14
jge 0x181c
movq 0x49fc(%rip), %rax      # 0x61e0
movq 0x49fd(%rip), %rcx      # 0x61e8
movslq (%rcx,%r14,4), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
addsd 0x498c(%rip), %xmm0     # 0x6188
callq 0x1080
subsd 0x30(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incq %r14
jmp 0x17cd
incq %rbx
jmp 0x179a
xorl %ebx, %ebx
movslq 0x48df(%rip), %rax      # 0x610c
cmpq %rax, %rbx
jge 0x18a6
movq 0x4a0f(%rip), %rax      # 0x6248
movq (%rax,%rbx,8), %rax
movq %rax, 0x49fc(%rip)      # 0x6240
movq 0x49b5(%rip), %rax      # 0x6200
movq (%rax,%rbx,8), %rax
movq %rax, 0x4982(%rip)      # 0x61d8
xorl %r14d, %r14d
movq 0x4910(%rip), %rax      # 0x6170
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r14
jge 0x18a1
movq 0x4938(%rip), %rax      # 0x61a8
movq 0x4961(%rip), %rcx      # 0x61d8
cvtsi2sdl (%rcx,%r14,4), %xmm0
addsd (%rax), %xmm0
callq 0x1080
subsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incq %r14
jmp 0x1859
incq %rbx
jmp 0x1826
xorl %ebx, %ebx
movslq 0x4851(%rip), %rax      # 0x6100
cmpq %rax, %rbx
jge 0x18fb
movsd 0x20(%rsp), %xmm0
callq 0x1080
movsd %xmm0, 0x10(%rsp)
movq 0x485c(%rip), %rax      # 0x6128
cvtsi2sdl (%rax,%rbx,4), %xmm0
addsd 0x20(%rsp), %xmm0
callq 0x1080
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
incq %rbx
jmp 0x18a8
movsd 0x18(%rsp), %xmm0
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %ebx, %ebx
movslq 0x47f6(%rip), %rax      # 0x610c
cmpq %rax, %rbx
jge 0x1962
movsd 0x18(%rsp), %xmm0
callq 0x1080
movsd %xmm0, 0x10(%rsp)
movq 0x4825(%rip), %rax      # 0x6158
cvtsi2sdl (%rax,%rbx,4), %xmm0
addsd 0x18(%rsp), %xmm0
callq 0x1080
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
incq %rbx
jmp 0x190f
cvtsi2sdl 0x47b6(%rip), %xmm1 # 0x6120
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x26d7(%rip), %rdi      # 0x4052
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r14
jmp 0x1040