// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq 0x5a06(%rip), %rax      # 0x71a8
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
cvtsi2sdl 0x594c(%rip), %xmm0 # 0x7100
movsd %xmm0, 0x28(%rsp)
movsd 0x59ce(%rip), %xmm0     # 0x7190
movsd %xmm0, 0x20(%rsp)
movsd 0x59b8(%rip), %xmm0     # 0x7188
callq 0x1080
movsd %xmm0, 0x30(%rsp)
movq 0x59c6(%rip), %rax      # 0x71a8
movsd (%rax), %xmm0
callq 0x1080
movsd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebx, %ebx
movslq 0x590c(%rip), %rax      # 0x7110
cmpq %rax, %rbx
jge 0x1868
movq 0x59c8(%rip), %rax      # 0x71d8
movq (%rax,%rbx,8), %rax
movq %rax, 0x59b5(%rip)      # 0x71d0
xorl %r14d, %r14d
movq 0x5953(%rip), %rax      # 0x7178
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r14
jge 0x1863
movq 0x599b(%rip), %rax      # 0x71d0
cvtsi2sdl (%rax,%r14,4), %xmm0
addsd 0x5945(%rip), %xmm0     # 0x7188
callq 0x1080
subsd 0x30(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incq %r14
jmp 0x181e
incq %rbx
jmp 0x17fd
xorl %ebx, %ebx
movslq 0x589b(%rip), %rax      # 0x710c
cmpq %rax, %rbx
jge 0x18d9
movq 0x59ab(%rip), %rax      # 0x7228
movq (%rax,%rbx,8), %rax
movq %rax, 0x5998(%rip)      # 0x7220
xorl %r14d, %r14d
movq 0x58de(%rip), %rax      # 0x7170
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r14
jge 0x18d4
movq 0x5906(%rip), %rax      # 0x71a8
movq 0x5977(%rip), %rcx      # 0x7220
cvtsi2sdl 0x4(%rcx,%r14,8), %xmm0
addsd (%rax), %xmm0
callq 0x1080
subsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incq %r14
jmp 0x188b
incq %rbx
jmp 0x186a
xorl %ebx, %ebx
movslq 0x581e(%rip), %rax      # 0x7100
cmpq %rax, %rbx
jge 0x192e
movsd 0x20(%rsp), %xmm0
callq 0x1080
movsd %xmm0, 0x10(%rsp)
movq 0x5829(%rip), %rax      # 0x7128
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 0x18db
movsd 0x18(%rsp), %xmm0
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %ebx, %ebx
movslq 0x57c3(%rip), %rax      # 0x710c
cmpq %rax, %rbx
jge 0x1995
movsd 0x18(%rsp), %xmm0
callq 0x1080
movsd %xmm0, 0x10(%rsp)
movq 0x57fa(%rip), %rax      # 0x7160
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 0x1942
cvtsi2sdl 0x5783(%rip), %xmm1 # 0x7120
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x26d1(%rip), %rdi      # 0x407f
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r14
jmp 0x1040