// File: /workspace/github_cpp_makefile_star2_O3/hkbu-victor[P]SFastLDA/super_fast_final1_w.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_pair_val = wpVal[wi];
     for (j=0; j<W_pair_count[wi]; j++){
    	log_likelihood += lgamma( BETA + wi_pair_val[ j ] ) - lgamma_beta;
     }
  }

  for (di=0; di<D; di++){
	  di_pair = dpPair[di];
	  for (j=0; j<D_pair_count[di]; j++){
		  log_likelihood += lgamma(ALPHA[0] + di_pair[j].value) - 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 0x57d9(%rip), %rax      # 0x71b0
cvtsi2sdl 0x5729(%rip), %xmm0 # 0x7108
mulsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x57a7(%rip), %xmm0     # 0x7198
movsd %xmm0, 0x10(%rsp)
movsd 0x5791(%rip), %xmm0     # 0x7190
callq 0x1090
movsd %xmm0, 0x20(%rsp)
movq 0x579f(%rip), %rax      # 0x71b0
movsd (%rax), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movl 0x56f2(%rip), %ecx      # 0x7118
xorpd %xmm1, %xmm1
testl %ecx, %ecx
jle 0x1aa7
movq 0x574b(%rip), %rax      # 0x7180
xorl %ebx, %ebx
movq 0x57a2(%rip), %rdx      # 0x71e0
movq (%rdx,%rbx,8), %rdx
movq %rdx, 0x578f(%rip)      # 0x71d8
cmpl $0x0, (%rax,%rbx,4)
jle 0x1a9c
xorl %r14d, %r14d
movsd %xmm1, (%rsp)
movq 0x577a(%rip), %rax      # 0x71d8
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r14,4), %xmm0
addsd 0x5721(%rip), %xmm0     # 0x7190
callq 0x1090
movsd (%rsp), %xmm1
subsd 0x20(%rsp), %xmm0
addsd %xmm0, %xmm1
incq %r14
movq 0x56f3(%rip), %rax      # 0x7180
movslq (%rax,%rbx,4), %rcx
cmpq %rcx, %r14
jl 0x1a52
movl 0x567c(%rip), %ecx      # 0x7118
incq %rbx
movslq %ecx, %rdx
cmpq %rdx, %rbx
jl 0x1a37
movl 0x5667(%rip), %eax      # 0x7114
testl %eax, %eax
jle 0x1b2e
movq 0x56c0(%rip), %rcx      # 0x7178
xorl %ebx, %ebx
movq 0x576f(%rip), %rdx      # 0x7230
movq (%rdx,%rbx,8), %rdx
movq %rdx, 0x575c(%rip)      # 0x7228
cmpl $0x0, (%rcx,%rbx,4)
jle 0x1b23
xorl %r14d, %r14d
movsd %xmm1, (%rsp)
movq 0x56cf(%rip), %rax      # 0x71b0
movq 0x5740(%rip), %rcx      # 0x7228
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rcx,%r14,8), %xmm0
addsd (%rax), %xmm0
callq 0x1090
movsd (%rsp), %xmm1
subsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm1
incq %r14
movq 0x5664(%rip), %rcx      # 0x7178
movslq (%rcx,%rbx,4), %rax
cmpq %rax, %r14
jl 0x1ad5
movl 0x55f1(%rip), %eax      # 0x7114
incq %rbx
movslq %eax, %rdx
cmpq %rdx, %rbx
jl 0x1aba
cmpl $0x0, 0x55d3(%rip)      # 0x7108
jle 0x1b91
xorl %ebx, %ebx
movsd %xmm1, (%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movq 0x55da(%rip), %rax      # 0x7130
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 0x5582(%rip), %rax      # 0x7108
cmpq %rax, %rbx
jl 0x1b39
movl 0x5583(%rip), %eax      # 0x7114
testl %eax, %eax
jle 0x1be9
xorl %ebx, %ebx
movsd %xmm1, (%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movq 0x55b4(%rip), %rax      # 0x7168
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 0x5530(%rip), %rax      # 0x7114
cmpq %rax, %rbx
jl 0x1b97
xorps %xmm0, %xmm0
cvtsi2sdl 0x5534(%rip), %xmm0 # 0x7128
divsd %xmm0, %xmm1
leaq 0x34a8(%rip), %rdi      # 0x50a7
movapd %xmm1, %xmm0
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r14
jmp 0x1040