// File: /workspace/github_cpp_makefile_star2_O3/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, %ebp
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %rbx
movb 0x40ac(%rip), %al       # 0x7140
testb %al, %al
je 0x38a8
movb 0x40be(%rip), %al       # 0x7160
testb %al, %al
je 0x38b2
movl %r15d, %r15d
movl %r14d, %r13d
testb %bpl, %bpl
je 0x30be
movq 0x70(%rbx), %rax
jmp 0x318e
leaq (%r15,%r15,2), %rcx
movq 0x58(%rbx), %rdx
movq 0x70(%rbx), %rax
movq (%rdx,%rcx,8), %rdi
leaq (,%r13,4), %r8
addq %r13, %r8
movzbl 0x8(%rdi,%r8,4), %esi
movl (%rdi,%r8,4), %edx
movl 0x4(%rdi,%r8,4), %ecx
movss 0xc(%rdi,%r8,4), %xmm1
movss 0x10(%rdi,%r8,4), %xmm0
leaq (%rsi,%rsi,2), %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,8), %rcx
decl (%rcx,%r15,4)
movq 0x78(%rbx), %rsi
subq %rax, %rsi
sarq $0x6, %rsi
leaq 0x3f88(%rip), %rdi      # 0x7128
callq 0x39b0
movq 0x78(%rbx), %rsi
subq 0x70(%rbx), %rsi
sarq $0x6, %rsi
leaq 0x3f90(%rip), %rdi      # 0x7148
callq 0x39b0
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
cmpq %rax, %rcx
je 0x323d
movb $0x1, %bpl
xorl %r14d, %r14d
movq 0x88(%rbx), %rdx
leaq (%r14,%r14,2), %rsi
movq (%rdx,%rsi,8), %rdx
movl (%rdx,%r15,4), %edx
cmpl %edx, 0xa0(%rbx)
jbe 0x31f9
movq 0xb8(%rbx), %rsi
movsd (%rsi,%rdx,8), %xmm0
jmp 0x3217
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
addsd 0xb0(%rbx), %xmm0
callq *0xa8(%rbx)
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
movq 0x3f0a(%rip), %rdx      # 0x7128
movsd %xmm0, (%rdx,%r14,8)
movzbl %bpl, %r14d
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x6, %rdx
movl %r14d, %ebp
incb %bpl
cmpq %r14, %rdx
ja 0x31d0
cmpq %rax, %rcx
je 0x367d
movb $0x1, %bpl
xorl %r14d, %r14d
movq %r15, 0x18(%rsp)
leaq (%r15,%r15,2), %r12
movq %r13, 0x10(%rsp)
leaq (%r13,%r13,4), %r13
movq %r14, %r15
shlq $0x6, %r15
movq 0x8(%rax,%r15), %rcx
movq 0x58(%rbx), %rdx
movq (%rdx,%r12,8), %rdx
movl (%rdx,%r13,4), %edx
movl (%rcx,%rdx,4), %ecx
cmpl %ecx, 0xc0(%rbx)
jbe 0x3290
movq 0xd8(%rbx), %rdx
movsd (%rdx,%rcx,8), %xmm1
jmp 0x32ae
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
addsd 0xd0(%rbx), %xmm0
callq *0xc8(%rbx)
movapd %xmm0, %xmm1
movq 0x70(%rbx), %rax
movl (%rax,%r15), %ecx
cmpl %ecx, 0xe0(%rbx)
jbe 0x32c8
movq 0xf8(%rbx), %rdx
movsd (%rdx,%rcx,8), %xmm0
jmp 0x32ee
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
addsd 0xf0(%rbx), %xmm0
movsd %xmm1, 0x8(%rsp)
callq *0xe8(%rbx)
movsd 0x8(%rsp), %xmm1
movq 0x70(%rbx), %rax
subsd %xmm0, %xmm1
movq 0x3e2f(%rip), %rcx      # 0x7128
addsd (%rcx,%r14,8), %xmm1
movsd %xmm1, (%rcx,%r14,8)
movzbl %bpl, %r14d
movq 0x78(%rbx), %rcx
movq %rcx, %r15
subq %rax, %r15
sarq $0x6, %r15
movl %r14d, %ebp
incb %bpl
cmpq %r14, %r15
ja 0x325f
cmpq %rax, %rcx
je 0x368c
movb $0x1, %bpl
xorl %r14d, %r14d
movq 0x18(%rsp), %rdx
leaq (%rdx,%rdx,2), %r12
movq 0x10(%rsp), %rdx
leaq (%rdx,%rdx,4), %r13
cmpb $0x1, (%rbx)
jne 0x365e
movq 0x58(%rbx), %rcx
movq (%rcx,%r12,8), %rcx
movl 0x4(%rcx,%r13,4), %ecx
movq %r14, %rdx
shlq $0x6, %rdx
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 0x345b
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 0xbe1(%rip), %xmm2      # 0x4080
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm13
divsd %xmm0, %xmm13
addsd 0xbd2(%rip), %xmm12     # 0x4088
addsd %xmm2, %xmm12
movapd %xmm12, 0x20(%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 0xb58(%rip), %xmm1      # 0x4090
movsd 0xb58(%rip), %xmm0      # 0x4098
mulsd %xmm0, %xmm1
movapd %xmm1, 0x70(%rsp)
movapd %xmm1, %xmm0
callq 0x1090
addsd 0xb55(%rip), %xmm0      # 0x40b0
movsd %xmm0, 0x8(%rsp)
movapd 0x20(%rsp), %xmm0
mulsd 0xb29(%rip), %xmm0      # 0x4098
callq 0x1090
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movapd 0x20(%rsp), %xmm0
callq 0x11c8
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x11c8
mulsd 0xaee(%rip), %xmm0      # 0x40a0
movq 0x58(%rbx), %rax
movq (%rax,%r12,8), %rax
xorps %xmm4, %xmm4
cvtss2sd 0xc(%rax,%r13,4), %xmm4
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
subsd 0x48(%rsp), %xmm4
xorps %xmm1, %xmm1
cvtss2sd 0x10(%rax,%r13,4), %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 0x20(%rsp), %xmm3
addsd 0xa56(%rip), %xmm3      # 0x4080
movapd %xmm3, %xmm0
callq 0x11c8
mulsd 0x70(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x3ade(%rip), %rax      # 0x7128
addsd (%rax,%r14,8), %xmm1
movsd %xmm1, (%rax,%r14,8)
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
movzbl %bpl, %r14d
movq %rcx, %r15
subq %rax, %r15
sarq $0x6, %r15
movl %r14d, %ebp
incb %bpl
cmpq %r14, %r15
ja 0x3347
jmp 0x368f
movq 0x3aa4(%rip), %r14      # 0x7128
movq %rax, %rcx
jmp 0x372f
movq %rax, %rcx
movq 0x3a92(%rip), %r14      # 0x7128
testl %r15d, %r15d
je 0x3725
xorps %xmm1, %xmm1
xorl %eax, %eax
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
movq 0x10(%rsp), %r13
movq (%r14,%rax,8), %xmm0
movq %xmm0, %rdx
btrq $0x3f, %rdx
cmpq %rcx, %rdx
jge 0x36cc
addsd %xmm0, %xmm1
incq %rax
cmpq %rax, %r15
jne 0x36b3
movl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm1
xorl %r12d, %r12d
movsd %xmm1, 0x8(%rsp)
movsd (%r14,%r12,8), %xmm0
subsd %xmm1, %xmm0
callq 0x1190
movsd 0x8(%rsp), %xmm1
movsd %xmm0, (%r14,%r12,8)
incq %r12
cmpq %r12, %r15
jne 0x36ec
movq 0x3a12(%rip), %r14      # 0x7128
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
movq 0x18(%rsp), %r15
jmp 0x372f
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %r13
movq 0x3a12(%rip), %rdx      # 0x7148
subq %rax, %rcx
shrq $0x6, %rcx
movsd (%r14), %xmm0
movsd %xmm0, (%rdx)
cmpl $0x2, %ecx
jb 0x3765
movl %ecx, %esi
movl $0x1, %edi
addsd (%r14,%rdi,8), %xmm0
movsd %xmm0, (%rdx,%rdi,8)
incq %rdi
cmpq %rdi, %rsi
jne 0x3752
movabsq $-0x42e60443a3f800b, %rdi # imm = 0xFBD19FBBC5C07FF5
imulq 0x3989(%rip), %rdi      # 0x7100
incq %rdi
movq %rdi, 0x397f(%rip)      # 0x7100
movb $-0x1, %sil
testl %ecx, %ecx
je 0x37d4
movq %rdi, %xmm1
punpckldq 0x8cb(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x8d3(%rip), %xmm1      # 0x4070
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x8f7(%rip), %xmm0      # 0x40a8
leal -0x1(%rcx), %edi
mulsd (%rdx,%rdi,8), %xmm0
movl %ecx, %edi
xorl %ecx, %ecx
movsd (%rdx,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
jae 0x37d2
incq %rcx
cmpq %rcx, %rdi
jne 0x37bd
jmp 0x37d4
movl %ecx, %esi
movq 0x58(%rbx), %rcx
leaq (%r15,%r15,2), %rdx
movq (%rcx,%rdx,8), %rdx
leaq (,%r13,4), %rdi
addq %r13, %rdi
movb %sil, 0x8(%rdx,%rdi,4)
movl (%rdx,%rdi,4), %r8d
movl 0x4(%rdx,%rdi,4), %ecx
movss 0xc(%rdx,%rdi,4), %xmm1
movss 0x10(%rdx,%rdi,4), %xmm0
movzbl %sil, %edx
movl %edx, %esi
shll $0x6, %esi
movq 0x8(%rax,%rsi), %rdi
incl (%rdi,%r8,4)
incl (%rax,%rsi)
movq 0x10(%rax,%rsi), %rdi
incl (%rdi,%rcx,4)
movq 0x18(%rax,%rsi), %rdi
movss (%rdi,%rcx,4), %xmm2
addss %xmm1, %xmm2
movss %xmm2, (%rdi,%rcx,4)
movq 0x20(%rax,%rsi), %rdi
movss (%rdi,%rcx,4), %xmm2
addss %xmm0, %xmm2
movss %xmm2, (%rdi,%rcx,4)
movq 0x28(%rax,%rsi), %rdi
movaps %xmm1, %xmm2
mulss %xmm1, %xmm2
addss (%rdi,%rcx,4), %xmm2
movss %xmm2, (%rdi,%rcx,4)
movq 0x30(%rax,%rsi), %rdi
mulss %xmm0, %xmm1
addss (%rdi,%rcx,4), %xmm1
leaq (%rdx,%rdx,2), %rdx
movss %xmm1, (%rdi,%rcx,4)
movq 0x38(%rax,%rsi), %rax
mulss %xmm0, %xmm0
addss (%rax,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
movq 0x88(%rbx), %rax
movq (%rax,%rdx,8), %rax
incl (%rax,%r15,4)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x128c
jmp 0x309c
callq 0x12d8
jmp 0x30aa