// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq 0x488a(%rip), %rax      # 0x61b0
cvtsi2sdl 0x47da(%rip), %xmm0 # 0x6108
mulsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x4858(%rip), %xmm0     # 0x6198
movsd %xmm0, 0x10(%rsp)
movsd 0x4842(%rip), %xmm0     # 0x6190
callq 0x1090
movsd %xmm0, 0x20(%rsp)
movq 0x4850(%rip), %rax      # 0x61b0
movsd (%rax), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, 0x47a2(%rip)      # 0x6118
jle 0x1a19
xorpd %xmm1, %xmm1
xorl %ebx, %ebx
movq 0x4877(%rip), %rax      # 0x6200
movq (%rax,%rbx,8), %rax
movq %rax, 0x485c(%rip)      # 0x61f0
movq 0x485d(%rip), %rax      # 0x61f8
movq (%rax,%rbx,8), %rax
movq %rax, 0x4842(%rip)      # 0x61e8
movq 0x47d3(%rip), %rax      # 0x6180
cmpl $0x0, (%rax,%rbx,4)
jle 0x1a04
xorl %r14d, %r14d
movsd %xmm1, (%rsp)
movq 0x4826(%rip), %rax      # 0x61e8
movq 0x4827(%rip), %rcx      # 0x61f0
movslq (%rcx,%r14,4), %rcx
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%rcx,4), %xmm0
addsd 0x47b3(%rip), %xmm0     # 0x6190
callq 0x1090
movsd (%rsp), %xmm1
subsd 0x20(%rsp), %xmm0
addsd %xmm0, %xmm1
incq %r14
movq 0x4785(%rip), %rax      # 0x6180
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r14
jl 0x19b6
incq %rbx
movslq 0x470a(%rip), %rax      # 0x6118
cmpq %rax, %rbx
jl 0x1982
jmp 0x1a1d
xorpd %xmm1, %xmm1
cmpl $0x0, 0x46f0(%rip)      # 0x6114
jle 0x1aba
xorl %ebx, %ebx
movq 0x481d(%rip), %rax      # 0x6250
movq (%rax,%rbx,8), %rax
movq %rax, 0x480a(%rip)      # 0x6248
movq 0x47c3(%rip), %rax      # 0x6208
movq (%rax,%rbx,8), %rax
movq %rax, 0x4790(%rip)      # 0x61e0
movq 0x4721(%rip), %rax      # 0x6178
cmpl $0x0, (%rax,%rbx,4)
jle 0x1aa7
xorl %r14d, %r14d
movsd %xmm1, (%rsp)
movq 0x4744(%rip), %rax      # 0x61b0
movq 0x476d(%rip), %rcx      # 0x61e0
xorps %xmm0, %xmm0
cvtsi2sdl (%rcx,%r14,4), %xmm0
addsd (%rax), %xmm0
callq 0x1090
movsd (%rsp), %xmm1
subsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm1
incq %r14
movq 0x46da(%rip), %rax      # 0x6178
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r14
jl 0x1a60
incq %rbx
movslq 0x4663(%rip), %rax      # 0x6114
cmpq %rax, %rbx
jl 0x1a2c
cmpl $0x0, 0x4647(%rip)      # 0x6108
jle 0x1b17
xorl %ebx, %ebx
movsd %xmm1, (%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movq 0x464e(%rip), %rax      # 0x6130
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 0x45f6(%rip), %rax      # 0x6108
cmpq %rax, %rbx
jl 0x1ac5
cmpl $0x0, 0x45f6(%rip)      # 0x6114
jle 0x1b74
xorl %ebx, %ebx
movsd %xmm1, (%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movq 0x4621(%rip), %rax      # 0x6160
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 0x45a5(%rip), %rax      # 0x6114
cmpq %rax, %rbx
jl 0x1b22
xorps %xmm0, %xmm0
cvtsi2sdl 0x45a9(%rip), %xmm0 # 0x6128
divsd %xmm0, %xmm1
leaq 0x24f8(%rip), %rdi      # 0x4082
movapd %xmm1, %xmm0
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r14
jmp 0x1040