// File: /workspace/github_cpp_makefile_star2_O2/lns[P]team-tactic-topic-model/./lda.cpp
// Function: LDA<unsigned int, unsigned int, unsigned char>::reassign(unsigned int, unsigned int, bool)
void reassign(uint32_t d, uint32_t i, bool first_run=false)
	{
		static vector<double> prob;
		static vector<double> qprob;
		// Remove statistics
		if(not first_run) {
			topic_t k = dat[d][i].z;
			word_t w = dat[d][i].w;
			player_t p = dat[d][i].p;
			float x = dat[d][i].x;
			float y = dat[d][i].y;

			topic[k].c[w]--;
			topic[k].c_sum--;
			topic[k].n[p]--;
			topic[k].x[p]-=x;
			topic[k].y[p]-=y;
			topic[k].xx[p]-=x*x;
			topic[k].xy[p]-=x*y;
			topic[k].yy[p]-=y*y;
			theta[k][d]--;
		}
		prob.resize(topic.size());
		qprob.resize(topic.size());
		// P(z_{d,i}=k | z_{-(d,i)})
		for(topic_t k=0;k<topic.size();k++)
			prob[k] = pct_log_a(theta[k][d]);
		// P(w_{d,i} | z_{d,i}=k)
		for(topic_t k=0;k<topic.size();k++)
			prob[k] += pct_log_b(topic[k].c[dat[d][i].w])-pct_log_Nb(topic[k].c_sum);
		// P(x_{d,i} | z_{d,i}=k)
		for(topic_t k=0;k<topic.size();k++)
			if(use_position) {
				player_t p=dat[d][i].p;
				uint32_t n = topic[k].n[p];
				double x = topic[k].x[p];
				double y = topic[k].y[p];
				double xx = topic[k].xx[p];
				double xy = topic[k].xy[p];
				double yy = topic[k].yy[p];
				double mu0_x = prior.mu0_x;
				double mu0_y = prior.mu0_y;
				double kappa0 = prior.kappa0;
				double nu0 = prior.nu0;
				double Lambda0_xx = prior.Lambda0_xx;
				double Lambda0_xy = prior.Lambda0_xy;
				double Lambda0_yy = prior.Lambda0_yy;

				double kappa_n = kappa0 + n;
				double mu_x = (kappa0*mu0_x + x)/kappa_n;
				double mu_y = (kappa0*mu0_y + y)/kappa_n;
				double nu_n = nu0 + n;
				double Lambda_xx = Lambda0_xx;
				double Lambda_xy = Lambda0_xy;
				double Lambda_yy = Lambda0_yy;
				if(n>0) {
					Lambda_xx += xx - x*x/n + kappa0*n/kappa_n*(x/n-mu0_x)*(x/n-mu0_x);
					Lambda_xy += xy - x*y/n + kappa0*n/kappa_n*(x/n-mu0_x)*(y/n-mu0_y);
					Lambda_yy += yy - y*y/n + kappa0*n/kappa_n*(y/n-mu0_y)*(y/n-mu0_y);
				}
				double Sigma_xx = Lambda_xx*(kappa_n+1)/kappa_n/(nu_n-2+1);
				double Sigma_xy = Lambda_xy*(kappa_n+1)/kappa_n/(nu_n-2+1);
				double Sigma_yy = Lambda_yy*(kappa_n+1)/kappa_n/(nu_n-2+1);
				double det_Sigma = Sigma_xx*Sigma_yy - Sigma_xy*Sigma_xy;
				double SigmaInv_xx = Sigma_yy/det_Sigma;
				double SigmaInv_xy = -Sigma_xy/det_Sigma;
				double SigmaInv_yy = Sigma_xx/det_Sigma;
				double nu = nu_n - 2 + 1;
				double pp = 0; // prob
				pp += lgamma((nu+2)/2);
				pp -= lgamma(nu/2);
				pp -= log(nu);
				//pp -= log(3.1416);
				pp -= 0.5*log(det_Sigma);
				double dx = (dat[d][i].x-mu_x);
				double dy = (dat[d][i].y-mu_y);
				double s_norm = SigmaInv_xx*dx*dx + SigmaInv_yy*dy*dy + 2*SigmaInv_xy*dx*dy;
				pp -= (nu+2)/2*log(1+s_norm/nu);
				prob[k] += pp;
			}
		// Calculate probability and draw rmultinorm
		prop_exp(&prob[0],topic.size());
		dat[d][i].z = rmultinorm(&prob[0],&qprob[0],topic.size());
		// Update statistics
		if(true) {
			topic_t k = dat[d][i].z;
			word_t w = dat[d][i].w;
			player_t p = dat[d][i].p;
			float x = dat[d][i].x;
			float y = dat[d][i].y;

			topic[k].c[w]++;
			topic[k].c_sum++;
			topic[k].n[p]++;
			topic[k].x[p]+=x;
			topic[k].y[p]+=y;
			topic[k].xx[p]+=x*x;
			topic[k].xy[p]+=x*y;
			topic[k].yy[p]+=y*y;
			theta[k][d]++;
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %ecx, %r14d
movl %edx, %r15d
movl %esi, %ebp
movq %rdi, %rbx
movb 0x43a2(%rip), %al       # 0x7160
testb %al, %al
je 0x3404
movb 0x43b4(%rip), %al       # 0x7180
testb %al, %al
je 0x3455
movl %r15d, %r13d
testb %r14b, %r14b
je 0x2de8
movq 0x70(%rbx), %rax
movl %ebp, %r12d
jmp 0x2eb4
movl %ebp, %r12d
imulq $0x18, %r12, %rcx
movq 0x58(%rbx), %rdx
movq 0x70(%rbx), %rax
movq (%rdx,%rcx), %rdi
imulq $0x14, %r13, %r8
movzbl 0x8(%rdi,%r8), %esi
movl (%rdi,%r8), %edx
movl 0x4(%rdi,%r8), %ecx
movss 0xc(%rdi,%r8), %xmm1
movss 0x10(%rdi,%r8), %xmm0
imulq $0x18, %rsi, %rdi
shll $0x6, %esi
movq 0x8(%rax,%rsi), %r8
decl (%r8,%rdx,4)
decl (%rax,%rsi)
movq 0x10(%rax,%rsi), %rdx
decl (%rdx,%rcx,4)
movq 0x18(%rax,%rsi), %rdx
movss (%rdx,%rcx,4), %xmm2
subss %xmm1, %xmm2
movss %xmm2, (%rdx,%rcx,4)
movq 0x20(%rax,%rsi), %rdx
movss (%rdx,%rcx,4), %xmm2
subss %xmm0, %xmm2
movss %xmm2, (%rdx,%rcx,4)
movq 0x28(%rax,%rsi), %rdx
movss (%rdx,%rcx,4), %xmm2
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
subss %xmm3, %xmm2
movss %xmm2, (%rdx,%rcx,4)
movq 0x30(%rax,%rsi), %rdx
movss (%rdx,%rcx,4), %xmm2
mulss %xmm0, %xmm1
subss %xmm1, %xmm2
movss %xmm2, (%rdx,%rcx,4)
movq 0x38(%rax,%rsi), %rdx
movss (%rdx,%rcx,4), %xmm1
mulss %xmm0, %xmm0
subss %xmm0, %xmm1
movss %xmm1, (%rdx,%rcx,4)
movq 0x88(%rbx), %rcx
movq (%rcx,%rdi), %rcx
decl (%rcx,%r12,4)
movq 0x78(%rbx), %rsi
subq %rax, %rsi
sarq $0x6, %rsi
leaq 0x4282(%rip), %rdi      # 0x7148
callq 0x356e
movq 0x78(%rbx), %rsi
subq 0x70(%rbx), %rsi
sarq $0x6, %rsi
leaq 0x428a(%rip), %rdi      # 0x7168
callq 0x356e
leaq 0xa0(%rbx), %r14
xorl %eax, %eax
movzbl %al, %r15d
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r15, %rdx
jbe 0x2f35
movq 0x88(%rbx), %rax
imulq $0x18, %r15, %rcx
movq (%rax,%rcx), %rax
movl (%rax,%r12,4), %esi
movq %r14, %rdi
callq 0x35a0
movq 0x421f(%rip), %rax      # 0x7148
movsd %xmm0, (%rax,%r15,8)
leal 0x1(%r15), %eax
jmp 0x2eec
leaq 0xc0(%rbx), %r14
leaq 0xe0(%rbx), %r15
xorl %edx, %edx
movq %r12, 0x28(%rsp)
imulq $0x18, %r12, %rsi
movq %rsi, 0x8(%rsp)
imulq $0x14, %r13, %r13
movzbl %dl, %ebp
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %rbp, %rdx
jbe 0x2fcd
movl %ebp, %r12d
shll $0x6, %r12d
movq 0x8(%rax,%r12), %rax
movq 0x58(%rbx), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx), %rcx
movl (%rcx,%r13), %ecx
movl (%rax,%rcx,4), %esi
movq %r14, %rdi
callq 0x35a0
movsd %xmm0, (%rsp)
movq 0x70(%rbx), %rax
movl (%rax,%r12), %esi
movq %r15, %rdi
callq 0x35a0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x4192(%rip), %rax      # 0x7148
addsd (%rax,%rbp,8), %xmm1
movsd %xmm1, (%rax,%rbp,8)
leal 0x1(%rbp), %edx
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
jmp 0x2f57
xorl %r14d, %r14d
movq 0x28(%rsp), %r15
movzbl %r14b, %r14d
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x6, %rsi
cmpq %r14, %rsi
jbe 0x3306
cmpb $0x1, (%rbx)
jne 0x32fe
movq 0x58(%rbx), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx), %rcx
movl 0x4(%rcx,%r13), %ecx
movl %r14d, %edx
shll $0x6, %edx
movq 0x10(%rax,%rdx), %rsi
movq 0x18(%rax,%rdx), %rdi
movl (%rsi,%rcx,4), %esi
movq 0x20(%rax,%rdx), %r8
movsd 0x30(%rbx), %xmm1
movsd 0x38(%rbx), %xmm13
movss (%r8,%rcx,4), %xmm0
movss (%rdi,%rcx,4), %xmm2
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
cvtps2pd %xmm2, %xmm3
movupd 0x20(%rbx), %xmm14
movupd 0x40(%rbx), %xmm11
cvtsi2sd %rsi, %xmm12
movapd %xmm1, %xmm0
addsd %xmm12, %xmm0
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
testl %esi, %esi
je 0x3104
addq %rdx, %rax
movq 0x28(%rax), %rdx
movq 0x30(%rax), %rsi
cvtss2sd (%rdx,%rcx,4), %xmm5
movq 0x38(%rax), %rax
movapd %xmm3, %xmm4
mulsd %xmm3, %xmm4
divsd %xmm12, %xmm4
subsd %xmm4, %xmm5
movapd %xmm1, %xmm4
mulsd %xmm12, %xmm4
divsd %xmm0, %xmm4
movapd %xmm12, %xmm6
unpcklpd %xmm12, %xmm6           # xmm6 = xmm6[0],xmm12[0]
movapd %xmm3, %xmm7
divpd %xmm6, %xmm7
movapd %xmm2, %xmm8
mulpd %xmm3, %xmm8
movss (%rax,%rcx,4), %xmm9
movss (%rsi,%rcx,4), %xmm10
unpcklps %xmm9, %xmm10           # xmm10 = xmm10[0],xmm9[0],xmm10[1],xmm9[1]
cvtps2pd %xmm10, %xmm9
subpd %xmm14, %xmm7
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
mulpd %xmm7, %xmm4
movapd %xmm4, %xmm10
mulsd %xmm7, %xmm10
addsd %xmm5, %xmm10
addsd %xmm10, %xmm13
divpd %xmm6, %xmm8
subpd %xmm8, %xmm9
unpckhpd %xmm7, %xmm7            # xmm7 = xmm7[1,1]
mulpd %xmm4, %xmm7
addpd %xmm9, %xmm7
addpd %xmm7, %xmm11
movapd %xmm1, %xmm4
mulsd %xmm14, %xmm4
addsd %xmm3, %xmm4
divsd %xmm0, %xmm4
movsd %xmm4, 0x48(%rsp)
unpckhpd %xmm14, %xmm14          # xmm14 = xmm14[1,1]
mulsd %xmm1, %xmm14
addsd %xmm2, %xmm14
divsd %xmm0, %xmm14
movapd %xmm14, 0x50(%rsp)
addsd 0x50(%rbx), %xmm12
movapd %xmm0, %xmm1
movsd 0xf08(%rip), %xmm2      # 0x4050
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm13
divsd %xmm0, %xmm13
addsd 0xef9(%rip), %xmm12     # 0x4058
addsd %xmm2, %xmm12
movapd %xmm12, 0x10(%rsp)
divsd %xmm12, %xmm13
movapd %xmm1, %xmm2
mulsd %xmm11, %xmm2
divsd %xmm0, %xmm2
divsd %xmm12, %xmm2
unpckhpd %xmm11, %xmm11          # xmm11 = xmm11[1,1]
mulsd %xmm1, %xmm11
divsd %xmm0, %xmm11
divsd %xmm12, %xmm11
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movapd %xmm13, %xmm1
mulsd %xmm11, %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
divsd %xmm1, %xmm11
movapd %xmm11, 0x60(%rsp)
divsd %xmm1, %xmm2
movsd %xmm2, 0x40(%rsp)
divsd %xmm1, %xmm13
movsd %xmm13, 0x38(%rsp)
movapd %xmm12, %xmm1
addsd 0xe7f(%rip), %xmm1      # 0x4060
movsd 0xe7f(%rip), %xmm0      # 0x4068
mulsd %xmm0, %xmm1
movapd %xmm1, 0x70(%rsp)
movapd %xmm1, %xmm0
callq 0x10b0
addsd 0xe74(%rip), %xmm0      # 0x4078
movsd %xmm0, (%rsp)
movapd 0x10(%rsp), %xmm0
mulsd 0xe51(%rip), %xmm0      # 0x4068
callq 0x10b0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movapd 0x10(%rsp), %xmm0
callq 0x1208
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x1208
mulsd 0xe1a(%rip), %xmm0      # 0x4070
movq 0x58(%rbx), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %rax
cvtss2sd 0xc(%rax,%r13), %xmm4
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
subsd 0x48(%rsp), %xmm4
cvtss2sd 0x10(%rax,%r13), %xmm1
subsd 0x50(%rsp), %xmm1
movapd 0x60(%rsp), %xmm3
mulsd %xmm4, %xmm3
movsd 0x38(%rsp), %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm4, %xmm3
addsd %xmm2, %xmm3
movsd 0x40(%rsp), %xmm2
addsd %xmm2, %xmm2
mulsd %xmm4, %xmm2
mulsd %xmm1, %xmm2
subsd %xmm2, %xmm3
divsd 0x10(%rsp), %xmm3
addsd 0xd85(%rip), %xmm3      # 0x4050
movapd %xmm3, %xmm0
callq 0x1208
mulsd 0x70(%rsp), %xmm0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x3e5e(%rip), %rax      # 0x7148
addsd (%rax,%r14,8), %xmm1
movsd %xmm1, (%rax,%r14,8)
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
incb %r14b
jmp 0x2fd5
movq 0x3e3b(%rip), %rdi      # 0x7148
callq 0x35bf
movq 0x3e2f(%rip), %rdi      # 0x7148
movq 0x3e48(%rip), %rsi      # 0x7168
movq 0x78(%rbx), %rdx
subq 0x70(%rbx), %rdx
shrq $0x6, %rdx
pushq $0x1
popq %rcx
callq 0x363d
movq 0x58(%rbx), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx), %rdx
movb %al, 0x8(%rdx,%r13)
movl (%rdx,%r13), %edi
movl 0x4(%rdx,%r13), %ecx
movss 0xc(%rdx,%r13), %xmm1
movss 0x10(%rdx,%r13), %xmm0
movzbl %al, %eax
movq 0x70(%rbx), %rdx
movl %eax, %esi
shll $0x6, %esi
movq 0x8(%rdx,%rsi), %r8
incl (%r8,%rdi,4)
incl (%rdx,%rsi)
movq 0x10(%rdx,%rsi), %rdi
incl (%rdi,%rcx,4)
movq 0x18(%rdx,%rsi), %rdi
movss (%rdi,%rcx,4), %xmm2
addss %xmm1, %xmm2
movss %xmm2, (%rdi,%rcx,4)
movq 0x20(%rdx,%rsi), %rdi
movss (%rdi,%rcx,4), %xmm2
addss %xmm0, %xmm2
movss %xmm2, (%rdi,%rcx,4)
movq 0x28(%rdx,%rsi), %rdi
movaps %xmm1, %xmm2
mulss %xmm1, %xmm2
addss (%rdi,%rcx,4), %xmm2
movss %xmm2, (%rdi,%rcx,4)
movq 0x30(%rdx,%rsi), %rdi
mulss %xmm0, %xmm1
addss (%rdi,%rcx,4), %xmm1
imulq $0x18, %rax, %rax
movss %xmm1, (%rdi,%rcx,4)
movq 0x38(%rdx,%rsi), %rdx
mulss %xmm0, %xmm0
addss (%rdx,%rcx,4), %xmm0
movss %xmm0, (%rdx,%rcx,4)
movq 0x88(%rbx), %rcx
movq (%rcx,%rax), %rax
incl (%rax,%r15,4)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3d55(%rip), %rdi      # 0x7160
callq 0x11e0
testl %eax, %eax
je 0x2dc6
xorps %xmm0, %xmm0
movups %xmm0, 0x3d26(%rip)     # 0x7148
andq $0x0, 0x3d2e(%rip)      # 0x7158
leaq 0x3d17(%rip), %rsi      # 0x7148
leaq 0x130(%rip), %rdi       # 0x3568
leaq 0x3cc9(%rip), %rdx      # 0x7108
callq 0x10e0
leaq 0x3d15(%rip), %rdi      # 0x7160
callq 0x10a0
jmp 0x2dc6
leaq 0x3d24(%rip), %rdi      # 0x7180
callq 0x11e0
testl %eax, %eax
je 0x2dd4
xorps %xmm0, %xmm0
movups %xmm0, 0x3cf5(%rip)     # 0x7168
andq $0x0, 0x3cfd(%rip)      # 0x7178
leaq 0x3ce6(%rip), %rsi      # 0x7168
leaq 0xdf(%rip), %rdi        # 0x3568
leaq 0x3c78(%rip), %rdx      # 0x7108
callq 0x10e0
leaq 0x3ce4(%rip), %rdi      # 0x7180
callq 0x10a0
jmp 0x2dd4