// File: /workspace/github_cpp_makefile_star2_O1/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 0x57e5(%rip), %rax      # 0x71b0
cvtsi2sdl 0x5735(%rip), %xmm0 # 0x7108
mulsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x57b3(%rip), %xmm0     # 0x7198
movsd %xmm0, 0x10(%rsp)
movsd 0x579d(%rip), %xmm0     # 0x7190
callq 0x1090
movsd %xmm0, 0x20(%rsp)
movq 0x57ab(%rip), %rax      # 0x71b0
movsd (%rax), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, 0x56fd(%rip)      # 0x7118
jle 0x1a9a
xorpd %xmm1, %xmm1
xorl %ebx, %ebx
movq 0x57b6(%rip), %rax      # 0x71e0
movq (%rax,%rbx,8), %rax
movq %rax, 0x57a3(%rip)      # 0x71d8
movq 0x5744(%rip), %rax      # 0x7180
cmpl $0x0, (%rax,%rbx,4)
jle 0x1a89
xorl %r14d, %r14d
movsd %xmm1, (%rsp)
movq 0x5787(%rip), %rax      # 0x71d8
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r14,4), %xmm0
addsd 0x572e(%rip), %xmm0     # 0x7190
callq 0x1090
movsd (%rsp), %xmm1
subsd 0x20(%rsp), %xmm0
addsd %xmm0, %xmm1
incq %r14
movq 0x5700(%rip), %rax      # 0x7180
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r14
jl 0x1a45
incq %rbx
movslq 0x5685(%rip), %rax      # 0x7118
cmpq %rax, %rbx
jl 0x1a23
jmp 0x1a9e
xorpd %xmm1, %xmm1
cmpl $0x0, 0x566f(%rip)      # 0x7114
jle 0x1b22
xorl %ebx, %ebx
movq 0x5780(%rip), %rax      # 0x7230
movq (%rax,%rbx,8), %rax
movq %rax, 0x576d(%rip)      # 0x7228
movq 0x56b6(%rip), %rax      # 0x7178
cmpl $0x0, (%rax,%rbx,4)
jle 0x1b13
xorl %r14d, %r14d
movsd %xmm1, (%rsp)
movq 0x56d9(%rip), %rax      # 0x71b0
movq 0x574a(%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 0x566e(%rip), %rax      # 0x7178
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r14
jl 0x1acb
incq %rbx
movslq 0x55f7(%rip), %rax      # 0x7114
cmpq %rax, %rbx
jl 0x1aa9
cmpl $0x0, 0x55df(%rip)      # 0x7108
jle 0x1b7f
xorl %ebx, %ebx
movsd %xmm1, (%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movq 0x55e6(%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 0x558e(%rip), %rax      # 0x7108
cmpq %rax, %rbx
jl 0x1b2d
cmpl $0x0, 0x558e(%rip)      # 0x7114
jle 0x1bdc
xorl %ebx, %ebx
movsd %xmm1, (%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movq 0x55c1(%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 0x553d(%rip), %rax      # 0x7114
cmpq %rax, %rbx
jl 0x1b8a
xorps %xmm0, %xmm0
cvtsi2sdl 0x5541(%rip), %xmm0 # 0x7128
divsd %xmm0, %xmm1
leaq 0x34b5(%rip), %rdi      # 0x50a7
movapd %xmm1, %xmm0
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r14
jmp 0x1040