// File: 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:
subq $0x48, %rsp
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x77fc(%rip), %rax      # 0x91a0
movsd (%rax), %xmm0
cvtsi2sdl 0x7748(%rip), %xmm1 # 0x90f8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x77c6(%rip), %xmm0     # 0x9188
movsd %xmm0, 0x30(%rsp)
movsd 0x77b0(%rip), %xmm0     # 0x9180
callq 0x1080
movsd %xmm0, 0x18(%rsp)
movq 0x77be(%rip), %rax      # 0x91a0
movsd (%rax), %xmm0
callq 0x1080
movsd %xmm0, 0x10(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x7705(%rip), %eax      # 0x9108
jge 0x1ab2
movq 0x77e0(%rip), %rax      # 0x91f0
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x77c0(%rip)      # 0x91e0
movq 0x77c1(%rip), %rax      # 0x91e8
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x77a1(%rip)      # 0x91d8
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movq 0x7726(%rip), %rcx      # 0x9170
movslq 0x2c(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x1aa0
movsd 0x7724(%rip), %xmm0     # 0x9180
movq 0x7775(%rip), %rax      # 0x91d8
movq 0x7776(%rip), %rcx      # 0x91e0
movslq 0x24(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
addsd %xmm1, %xmm0
callq 0x1080
subsd 0x18(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1a3f
jmp 0x1aa2
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x19f9
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x7640(%rip), %eax      # 0x9104
jge 0x1b6b
movq 0x776f(%rip), %rax      # 0x9240
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x7757(%rip)      # 0x9238
movq 0x7710(%rip), %rax      # 0x91f8
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x76d8(%rip)      # 0x91d0
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movq 0x765d(%rip), %rcx      # 0x9168
movslq 0x28(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x1b59
movq 0x7684(%rip), %rax      # 0x91a0
movsd (%rax), %xmm0
movq 0x76a9(%rip), %rax      # 0x91d0
movslq 0x24(%rsp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
addsd %xmm1, %xmm0
callq 0x1080
subsd 0x10(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1b00
jmp 0x1b5b
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x1aba
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x757b(%rip), %eax      # 0x90f8
jge 0x1bd6
movsd 0x30(%rsp), %xmm0
callq 0x1080
movsd %xmm0, 0x8(%rsp)
movsd 0x30(%rsp), %xmm0
movq 0x7583(%rip), %rax      # 0x9120
movslq 0x24(%rsp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
addsd %xmm1, %xmm0
callq 0x1080
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1b73
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x751c(%rip), %eax      # 0x9104
jge 0x1c3f
movsd 0x38(%rsp), %xmm0
callq 0x1080
movsd %xmm0, (%rsp)
movsd 0x38(%rsp), %xmm0
movq 0x7549(%rip), %rax      # 0x9150
movslq 0x28(%rsp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
addsd %xmm1, %xmm0
callq 0x1080
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x1bde
movsd 0x40(%rsp), %xmm0
cvtsi2sdl 0x74cb(%rip), %xmm1 # 0x9118
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
leaq 0x466d(%rip), %rdi      # 0x62d1
movb $0x1, %al
callq 0x1040
addq $0x48, %rsp
retq