// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq 0xb0(%rdi), %rbx
subq 0xa8(%rdi), %rbx
movslq (%rdi), %rsi
leaq -0x30(%rbp), %rdx
movl $0x0, (%rdx)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
callq 0x5c44
sarq $0x3, %rbx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rbx, %rax
leaq 0xf0(%r14), %rdi
movq %rax, -0x50(%rbp)
movslq %eax, %rsi
leaq -0x48(%rbp), %rdx
callq 0x5ccc
movq %r14, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x3314
callq 0x2210
movslq 0xa0(%rbx), %r14
movslq (%rbx), %rsi
leaq -0x30(%rbp), %rdx
movl $0x0, (%rdx)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
callq 0x5c44
leaq 0x108(%rbx), %rdi
leaq -0x48(%rbp), %rdx
movq %r14, %rsi
callq 0x5ccc
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x3356
callq 0x2210
leaq 0x150(%rbx), %rdi
movslq (%rbx), %rsi
movq %rbx, %r15
xorl %ebx, %ebx
leaq -0x48(%rbp), %rdx
movl %ebx, (%rdx)
callq 0x5d4e
movslq 0xa0(%r15), %r14
movslq 0x4(%r15), %rsi
leaq -0x30(%rbp), %rdx
movl %ebx, (%rdx)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
callq 0x5c44
leaq 0x120(%r15), %rdi
leaq -0x48(%rbp), %rdx
movq %r14, %rsi
callq 0x5ccc
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x33af
callq 0x2210
leaq 0x168(%r15), %rdi
movslq 0x4(%r15), %rsi
xorl %ebx, %ebx
leaq -0x48(%rbp), %rdx
movl %ebx, (%rdx)
callq 0x5d4e
movslq 0x4(%r15), %r14
leaq -0x30(%rbp), %rdx
movl %ebx, (%rdx)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movq %r14, %rsi
callq 0x5c44
leaq 0x138(%r15), %rdi
leaq -0x48(%rbp), %rdx
movq %r14, %rsi
callq 0x5ccc
movq %r15, -0x58(%rbp)
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x3406
callq 0x2210
cmpl $0x0, -0x50(%rbp)
jle 0x3557
movq -0x58(%rbp), %rax
movq 0xa8(%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0xd8(%rax), %rcx
movq %rcx, -0x68(%rbp)
movq 0x120(%rax), %rdx
movq 0x168(%rax), %rsi
movq -0x50(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x50(%rbp)
xorl %eax, %eax
movq %rax, -0x60(%rbp)
leaq (%rax,%rax,2), %rax
movq -0x70(%rbp), %rcx
movq (%rcx,%rax,8), %r8
movq 0x8(%rcx,%rax,8), %r9
subq %r8, %r9
shrq $0x2, %r9
testl %r9d, %r9d
jle 0x3546
movq -0x60(%rbp), %rax
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %r10
movq -0x68(%rbp), %rax
movq (%rax,%r10), %r11
movq -0x58(%rbp), %rax
movq 0xf0(%rax), %rcx
addq %r10, %rcx
movq %rcx, -0x80(%rbp)
addq 0xc0(%rax), %r10
movq 0x108(%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x138(%rax), %r13
movq 0x150(%rax), %rax
movq %rax, -0x78(%rbp)
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movslq (%r8,%rcx,4), %rax
cmpl $0x0, (%r11,%rcx,4)
jne 0x350b
movq (%r10), %rdi
movslq (%rdi,%rcx,4), %r12
movq -0x80(%rbp), %r14
movq (%r14), %r15
incl (%r15,%r12,4)
leaq (%rax,%rax,2), %r15
movslq (%rdi,%rcx,4), %r12
movq -0x88(%rbp), %r14
movq (%r14,%r15,8), %r15
incl (%r15,%r12,4)
movslq (%rdi,%rcx,4), %rdi
movq -0x78(%rbp), %r14
incl (%r14,%rdi,4)
leaq (%rax,%rax,2), %rax
movslq (%r11,%rcx,4), %rdi
movq (%rdx,%rax,8), %rax
incl (%rax,%rdi,4)
movslq (%r11,%rcx,4), %rax
incl (%rsi,%rax,4)
movl (%r11,%rcx,4), %eax
cmpl $-0x1, %ebx
je 0x353c
movslq %eax, %rdi
movslq %ebx, %rbx
leaq (%rbx,%rbx,2), %rbx
movq (%r13,%rbx,8), %rbx
incl (%rbx,%rdi,4)
incq %rcx
movl %eax, %ebx
cmpq %rcx, %r9
jne 0x34cb
movq -0x60(%rbp), %rax
incq %rax
cmpq -0x50(%rbp), %rax
jne 0x3447
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3572
jmp 0x3585
jmp 0x3572
jmp 0x3585
jmp 0x3572
jmp 0x3585
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x3588
callq 0x2210
jmp 0x3588
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2390