// File: /workspace/github_cpp_makefile_star2_O2/abaheti95[P]HMM-LDA/Models/cpp_hmm_lda/model.cpp
// Function: HMMLDA::run_counts()
void HMMLDA::run_counts() {
	int n_documents = documents.size();
	//num_words_in_doc_assigned_to_topic
	// dimension of this 2d vector will be n_documents * num_topics
	num_words_in_doc_assigned_to_topic.resize(n_documents, vector<int>(num_topics, 0));
	//num_same_words_assigned_to_topic
	// dimension of this 2d vector will be vocab_size * num_topics
	num_same_words_assigned_to_topic.resize(vocab_size, vector<int>(num_topics, 0));
	//num_words_assigned_to_topic
	// dimension of this 1d vector will be num_topics
	num_words_assigned_to_topic.resize(num_topics, 0);
	//num_same_words_assigned_to_class
	// dimension of this 2d vector will be vocab_size * num_classes
	num_same_words_assigned_to_class.resize(vocab_size, vector<int>(num_classes, 0));
	//num_words_assigned_to_class
	// dimension of this 1d vector will be num_classes
	num_words_assigned_to_class.resize(num_classes, 0);
	//num_transitions
	// dimension of this 2d vector will be num_classes * num_classes
	num_transitions.resize(num_classes, vector<int>(num_classes, 0));
	
	for(int document_idx = 0; document_idx < n_documents; document_idx++) {
		int doc_size = documents[document_idx].size();
		int previous_class = -1;
		for(int word_idx = 0; word_idx < doc_size; word_idx++) {
			int word = documents[document_idx][word_idx];
			if(class_assignments[document_idx][word_idx] == 0) {		// Count the topic only when the class is 0
				num_words_in_doc_assigned_to_topic[document_idx][topic_assignments[document_idx][word_idx]]++;
				num_same_words_assigned_to_topic[word][topic_assignments[document_idx][word_idx]]++;
				num_words_assigned_to_topic[topic_assignments[document_idx][word_idx]]++;
			}
			num_same_words_assigned_to_class[word][class_assignments[document_idx][word_idx]]++;
			num_words_assigned_to_class[class_assignments[document_idx][word_idx]]++;
			int current_class = class_assignments[document_idx][word_idx];
			if(previous_class != -1)
				num_transitions[previous_class][current_class]++;
			previous_class = current_class;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0xb0(%rdi), %rax
subq 0xa8(%rdi), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, %r14
movslq (%rdi), %rsi
leaq -0x30(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
callq 0x4f44
leaq 0xf0(%rbx), %rdi
movslq %r14d, %rsi
leaq -0x48(%rbp), %rdx
callq 0x4fb2
leaq -0x48(%rbp), %rdi
callq 0x571a
movslq 0xa0(%rbx), %r15
movslq (%rbx), %rsi
leaq -0x30(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
callq 0x4f44
leaq 0x108(%rbx), %rdi
leaq -0x48(%rbp), %rdx
movq %r15, %rsi
callq 0x4fb2
leaq -0x48(%rbp), %r15
movq %r15, %rdi
callq 0x571a
leaq 0x150(%rbx), %rdi
movslq (%rbx), %rsi
andl $0x0, (%r15)
leaq -0x48(%rbp), %rdx
callq 0x4ffa
movslq 0xa0(%rbx), %r15
movslq 0x4(%rbx), %rsi
leaq -0x30(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
callq 0x4f44
leaq 0x120(%rbx), %rdi
leaq -0x48(%rbp), %rdx
movq %r15, %rsi
callq 0x4fb2
leaq -0x48(%rbp), %r15
movq %r15, %rdi
callq 0x571a
leaq 0x168(%rbx), %rdi
movslq 0x4(%rbx), %rsi
andl $0x0, (%r15)
leaq -0x48(%rbp), %rdx
callq 0x4ffa
movslq 0x4(%rbx), %r15
leaq -0x30(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movq %r15, %rsi
callq 0x4f44
leaq 0x138(%rbx), %rdi
leaq -0x48(%rbp), %rdx
movq %r15, %rsi
callq 0x4fb2
leaq -0x48(%rbp), %rdi
callq 0x571a
movq 0xa8(%rbx), %rax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
xorl %eax, %eax
movq %rbx, -0x60(%rbp)
movq %r14, -0x58(%rbp)
cmpq %r14, %rax
je 0x31b2
movq %rax, -0x68(%rbp)
imulq $0x18, %rax, %rcx
movq -0x50(%rbp), %rax
movq (%rax,%rcx), %r8
movq 0x8(%rax,%rcx), %r9
subq %r8, %r9
shrq $0x2, %r9
movq 0xd8(%rbx), %r10
addq %rcx, %r10
movq 0xf0(%rbx), %rax
addq %rcx, %rax
movq %rax, -0x88(%rbp)
addq 0xc0(%rbx), %rcx
movq %rcx, -0x78(%rbp)
movq 0x108(%rbx), %rax
movq %rax, -0x80(%rbp)
movq 0x120(%rbx), %r12
movq 0x150(%rbx), %rax
movq %rax, -0x70(%rbp)
movq 0x168(%rbx), %r14
movq 0x138(%rbx), %rcx
testl %r9d, %r9d
movl $0x0, %eax
cmovlel %eax, %r9d
xorl %edx, %edx
pushq $-0x1
popq %rax
cmpq %rdx, %r9
je 0x319e
movslq (%r8,%rdx,4), %rsi
movq (%r10), %rbx
movl (%rbx,%rdx,4), %r15d
testl %r15d, %r15d
jne 0x3164
movq -0x78(%rbp), %rdi
movq (%rdi), %r15
movslq (%r15,%rdx,4), %r13
movq -0x88(%rbp), %r11
movq (%r11), %r11
incl (%r11,%r13,4)
imulq $0x18, %rsi, %r11
movslq (%r15,%rdx,4), %r13
movq -0x80(%rbp), %rdi
movq (%rdi,%r11), %r11
incl (%r11,%r13,4)
movslq (%r15,%rdx,4), %r11
movq -0x70(%rbp), %rdi
incl (%rdi,%r11,4)
movl (%rbx,%rdx,4), %r15d
imulq $0x18, %rsi, %rsi
movslq %r15d, %r11
movq (%r12,%rsi), %rsi
incl (%rsi,%r11,4)
movslq (%rbx,%rdx,4), %rsi
incl (%r14,%rsi,4)
movl (%rbx,%rdx,4), %esi
cmpl $-0x1, %eax
je 0x3194
movslq %esi, %r11
cltq
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rax
incl (%rax,%r11,4)
incq %rdx
movl %esi, %eax
jmp 0x310e
movq -0x68(%rbp), %rax
incq %rax
movq -0x60(%rbp), %rbx
movq -0x58(%rbp), %r14
jmp 0x3087
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x31cd
jmp 0x31db
jmp 0x31cd
jmp 0x31db
jmp 0x31cd
jmp 0x31db
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x571a
jmp 0x31de
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2380