// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movl %ecx, %ebp
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %rbx
movb 0x4177(%rip), %al       # 0x7140
testb %al, %al
je 0x37b8
movb 0x4189(%rip), %al       # 0x7160
testb %al, %al
je 0x37c2
movl %r15d, %r15d
movl %r14d, %eax
movq %rax, 0x8(%rsp)
testb %bpl, %bpl
jne 0x30c1
leaq (%r15,%r15,2), %rcx
movq 0x58(%rbx), %rdx
movq 0x70(%rbx), %rax
movq (%rdx,%rcx,8), %rdi
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,4), %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), %rax
movss (%rax,%rcx,4), %xmm1
mulss %xmm0, %xmm0
subss %xmm0, %xmm1
movss %xmm1, (%rax,%rcx,4)
movq 0x88(%rbx), %rax
movq (%rax,%rdi,8), %rax
decl (%rax,%r15,4)
movq 0x78(%rbx), %rsi
subq 0x70(%rbx), %rsi
sarq $0x6, %rsi
leaq 0x4054(%rip), %rdi      # 0x7128
callq 0x38c0
movq 0x78(%rbx), %rsi
subq 0x70(%rbx), %rsi
sarq $0x6, %rsi
leaq 0x405c(%rip), %rdi      # 0x7148
callq 0x38c0
movq 0x78(%rbx), %rax
cmpq 0x70(%rbx), %rax
je 0x3168
movb $0x1, %bpl
xorl %r14d, %r14d
movq 0x88(%rbx), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax,%r15,4), %eax
cmpl %eax, 0xa0(%rbx)
jbe 0x312a
movq 0xb8(%rbx), %rcx
movsd (%rcx,%rax,8), %xmm0
jmp 0x3140
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0xb0(%rbx), %xmm0
callq *0xa8(%rbx)
movq 0x3fe1(%rip), %rax      # 0x7128
movsd %xmm0, (%rax,%r14,8)
movzbl %bpl, %r14d
movq 0x78(%rbx), %rax
subq 0x70(%rbx), %rax
sarq $0x6, %rax
movl %r14d, %ebp
incb %bpl
cmpq %r14, %rax
ja 0x3101
movq %r15, 0x10(%rsp)
movq 0x70(%rbx), %rax
cmpq %rax, 0x78(%rbx)
je 0x3255
movb $0x1, %bpl
xorl %r15d, %r15d
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,2), %r12
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,4), %r13
movq %r15, %r14
shlq $0x6, %r14
movq 0x8(%rax,%r14), %rax
movq 0x58(%rbx), %rcx
movq (%rcx,%r12,8), %rcx
movl (%rcx,%r13,4), %ecx
movl (%rax,%rcx,4), %eax
cmpl %eax, 0xc0(%rbx)
jbe 0x31c4
movq 0xd8(%rbx), %rcx
movsd (%rcx,%rax,8), %xmm1
jmp 0x31de
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0xd0(%rbx), %xmm0
callq *0xc8(%rbx)
movapd %xmm0, %xmm1
movq 0x70(%rbx), %rax
movl (%rax,%r14), %eax
cmpl %eax, 0xe0(%rbx)
jbe 0x31fc
movq 0xf8(%rbx), %rcx
movsd (%rcx,%rax,8), %xmm0
jmp 0x321c
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0xf0(%rbx), %xmm0
movsd %xmm1, (%rsp)
callq *0xe8(%rbx)
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x3f01(%rip), %rax      # 0x7128
addsd (%rax,%r15,8), %xmm1
movsd %xmm1, (%rax,%r15,8)
movzbl %bpl, %r15d
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
subq %rax, %rcx
sarq $0x6, %rcx
movl %r15d, %ebp
incb %bpl
cmpq %r15, %rcx
ja 0x3193
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
subq %rax, %rcx
je 0x35a6
movb $0x1, %r14b
xorl %r13d, %r13d
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,2), %r12
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,4), %rbp
cmpb $0x1, (%rbx)
jne 0x3582
movq 0x58(%rbx), %rcx
movq (%rcx,%r12,8), %rcx
movl 0x4(%rcx,%rbp,4), %ecx
movq %r13, %rdx
shlq $0x6, %rdx
movq 0x10(%rax,%rdx), %rsi
movq 0x18(%rax,%rdx), %rdi
movl (%rsi,%rcx,4), %esi
cvtss2sd (%rdi,%rcx,4), %xmm6
movq 0x20(%rax,%rdx), %rdi
xorps %xmm3, %xmm3
cvtss2sd (%rdi,%rcx,4), %xmm3
movsd 0x20(%rbx), %xmm8
movsd 0x28(%rbx), %xmm5
movsd 0x30(%rbx), %xmm2
movsd 0x38(%rbx), %xmm13
movsd 0x40(%rbx), %xmm12
movsd 0x48(%rbx), %xmm1
xorps %xmm4, %xmm4
cvtsi2sd %rsi, %xmm4
movapd %xmm2, %xmm0
addsd %xmm4, %xmm0
movapd %xmm2, %xmm7
mulsd %xmm8, %xmm7
addsd %xmm6, %xmm7
divsd %xmm0, %xmm7
movsd %xmm7, 0x50(%rsp)
movapd %xmm2, %xmm7
mulsd %xmm5, %xmm7
addsd %xmm3, %xmm7
divsd %xmm0, %xmm7
movsd %xmm7, 0x48(%rsp)
movsd 0x50(%rbx), %xmm14
addsd %xmm4, %xmm14
testl %esi, %esi
je 0x33d5
addq %rdx, %rax
movq 0x28(%rax), %rdx
movq 0x30(%rax), %rsi
movq 0x38(%rax), %rax
xorps %xmm7, %xmm7
cvtss2sd (%rax,%rcx,4), %xmm7
cvtss2sd (%rsi,%rcx,4), %xmm9
cvtss2sd (%rdx,%rcx,4), %xmm10
movapd %xmm6, %xmm11
mulsd %xmm6, %xmm11
divsd %xmm4, %xmm11
subsd %xmm11, %xmm10
mulsd %xmm4, %xmm2
divsd %xmm0, %xmm2
movapd %xmm6, %xmm11
divsd %xmm4, %xmm11
subsd %xmm8, %xmm11
movapd %xmm11, %xmm8
mulsd %xmm2, %xmm8
mulsd %xmm8, %xmm11
addsd %xmm10, %xmm11
addsd %xmm11, %xmm13
mulsd %xmm3, %xmm6
divsd %xmm4, %xmm6
subsd %xmm6, %xmm9
movapd %xmm3, %xmm6
divsd %xmm4, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm6, %xmm8
addsd %xmm9, %xmm8
addsd %xmm8, %xmm12
mulsd %xmm3, %xmm3
divsd %xmm4, %xmm3
subsd %xmm3, %xmm7
mulsd %xmm6, %xmm2
mulsd %xmm6, %xmm2
addsd %xmm7, %xmm2
addsd %xmm2, %xmm1
movapd %xmm0, %xmm3
movsd 0xc5f(%rip), %xmm2      # 0x4040
addsd %xmm2, %xmm3
mulsd %xmm3, %xmm13
divsd %xmm0, %xmm13
addsd 0xc50(%rip), %xmm14     # 0x4048
addsd %xmm2, %xmm14
movsd %xmm14, 0x18(%rsp)
divsd %xmm14, %xmm13
mulsd %xmm3, %xmm12
divsd %xmm0, %xmm12
divsd %xmm14, %xmm12
mulsd %xmm1, %xmm3
divsd %xmm0, %xmm3
divsd %xmm14, %xmm3
movapd %xmm12, %xmm0
mulsd %xmm12, %xmm0
movapd %xmm13, %xmm1
mulsd %xmm3, %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
divsd %xmm1, %xmm3
movsd %xmm3, 0x38(%rsp)
divsd %xmm1, %xmm12
movsd %xmm12, 0x30(%rsp)
divsd %xmm1, %xmm13
movsd %xmm13, 0x28(%rsp)
movapd %xmm14, %xmm1
addsd 0xbdf(%rip), %xmm1      # 0x4050
movsd 0xbdf(%rip), %xmm0      # 0x4058
mulsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
movapd %xmm1, %xmm0
callq 0x1090
addsd 0xbdc(%rip), %xmm0      # 0x4070
movsd %xmm0, (%rsp)
movsd 0x18(%rsp), %xmm0
mulsd 0xbb1(%rip), %xmm0      # 0x4058
callq 0x1090
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x11c8
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x11c8
mulsd 0xb7a(%rip), %xmm0      # 0x4060
movq 0x58(%rbx), %rax
movq (%rax,%r12,8), %rax
cvtss2sd 0xc(%rax,%rbp,4), %xmm4
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
subsd 0x50(%rsp), %xmm4
xorps %xmm1, %xmm1
cvtss2sd 0x10(%rax,%rbp,4), %xmm1
subsd 0x48(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
mulsd %xmm4, %xmm2
movsd 0x28(%rsp), %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm4, %xmm2
addsd %xmm3, %xmm2
movsd 0x30(%rsp), %xmm3
addsd %xmm3, %xmm3
mulsd %xmm4, %xmm3
mulsd %xmm1, %xmm3
subsd %xmm3, %xmm2
divsd 0x18(%rsp), %xmm2
addsd 0xae9(%rip), %xmm2      # 0x4040
movapd %xmm2, %xmm0
callq 0x11c8
mulsd 0x40(%rsp), %xmm0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x3bb2(%rip), %rax      # 0x7128
addsd (%rax,%r13,8), %xmm1
movsd %xmm1, (%rax,%r13,8)
movzbl %r14b, %r13d
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
subq %rax, %rcx
sarq $0x6, %rcx
movl %r13d, %r14d
incb %r14b
cmpq %r13, %rcx
ja 0x327e
jmp 0x35aa
sarq $0x6, %rcx
movq 0x3b77(%rip), %r14      # 0x7128
testl %ecx, %ecx
je 0x35e9
movl %ecx, %eax
xorps %xmm1, %xmm1
xorl %edx, %edx
movabsq $0x7ff0000000000000, %rsi # imm = 0x7FF0000000000000
movq (%r14,%rdx,8), %xmm0
movq %xmm0, %rdi
btrq $0x3f, %rdi
cmpq %rsi, %rdi
jge 0x35df
addsd %xmm0, %xmm1
incq %rdx
cmpq %rdx, %rax
jne 0x35c6
jmp 0x35ec
xorps %xmm1, %xmm1
testl %ecx, %ecx
je 0x362b
movl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm1
movl %ecx, %r15d
xorl %r12d, %r12d
movsd %xmm1, (%rsp)
movsd (%r14,%r12,8), %xmm0
subsd %xmm1, %xmm0
callq 0x1190
movsd (%rsp), %xmm1
movsd %xmm0, (%r14,%r12,8)
incq %r12
cmpq %r12, %r15
jne 0x3609
movq 0x3af6(%rip), %rsi      # 0x7128
movq 0x3b0f(%rip), %rcx      # 0x7148
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rdx
subq %rax, %rdx
shrq $0x6, %rdx
movsd (%rsi), %xmm0
movsd %xmm0, (%rcx)
cmpl $0x2, %edx
jb 0x3675
movl %edx, %edi
movsd (%rcx), %xmm0
movl $0x1, %r8d
addsd (%rsi,%r8,8), %xmm0
movsd %xmm0, (%rcx,%r8,8)
incq %r8
cmpq %r8, %rdi
jne 0x3661
movabsq $-0x42e60443a3f800b, %rdi # imm = 0xFBD19FBBC5C07FF5
imulq 0x3a79(%rip), %rdi      # 0x7100
incq %rdi
movq %rdi, 0x3a6f(%rip)      # 0x7100
movb $-0x1, %sil
testl %edx, %edx
movq 0x10(%rsp), %r9
je 0x36e9
movq %rdi, %xmm1
punpckldq 0x976(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x97e(%rip), %xmm1      # 0x4030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x9a2(%rip), %xmm0      # 0x4068
leal -0x1(%rdx), %edi
mulsd (%rcx,%rdi,8), %xmm0
movl %edx, %edi
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm1
ucomisd %xmm0, %xmm1
jae 0x36e7
incq %rdx
cmpq %rdx, %rdi
jne 0x36d2
jmp 0x36e9
movl %edx, %esi
movq 0x58(%rbx), %rcx
leaq (%r9,%r9,2), %rdx
movq (%rcx,%rdx,8), %rdx
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,4), %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,%r9,4)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x128c
jmp 0x2fd1
callq 0x12d8
jmp 0x2fdf