// File: 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
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
addq $0xa8, %rdi
callq 0x8be0
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movl %ecx, -0xc(%rbp)
movq %rax, %rcx
addq $0xf0, %rcx
movq %rcx, -0xe8(%rbp)
movslq -0xc(%rbp), %rcx
movq %rcx, -0xe0(%rbp)
movslq (%rax), %rax
movq %rax, -0xd8(%rbp)
movl $0x0, -0x2c(%rbp)
leaq -0x2d(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x8e70
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rcx
leaq -0x28(%rbp), %rdi
leaq -0x2c(%rbp), %rdx
callq 0x8e90
jmp 0x46ed
movq -0xe0(%rbp), %rsi
movq -0xe8(%rbp), %rdi
leaq -0x28(%rbp), %rdx
callq 0x8fa0
jmp 0x4706
leaq -0x28(%rbp), %rdi
callq 0x8aa0
leaq -0x2d(%rbp), %rdi
callq 0x8f10
movq -0xf0(%rbp), %rax
movq %rax, %rcx
addq $0x108, %rcx            # imm = 0x108
movq %rcx, -0x110(%rbp)
movslq 0xa0(%rax), %rcx
movq %rcx, -0x108(%rbp)
movslq (%rax), %rax
movq %rax, -0x100(%rbp)
movl $0x0, -0x5c(%rbp)
leaq -0x5d(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x8e70
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rcx
leaq -0x58(%rbp), %rdi
leaq -0x5c(%rbp), %rdx
callq 0x8e90
jmp 0x477c
movq -0x108(%rbp), %rsi
movq -0x110(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x8fa0
jmp 0x4795
leaq -0x58(%rbp), %rdi
callq 0x8aa0
leaq -0x5d(%rbp), %rdi
callq 0x8f10
movq -0xf0(%rbp), %rax
movq %rax, %rdi
addq $0x150, %rdi            # imm = 0x150
movslq (%rax), %rsi
movl $0x0, -0x64(%rbp)
leaq -0x64(%rbp), %rdx
callq 0x9050
movq -0xf0(%rbp), %rax
movq %rax, %rcx
addq $0x120, %rcx            # imm = 0x120
movq %rcx, -0x130(%rbp)
movslq 0xa0(%rax), %rcx
movq %rcx, -0x128(%rbp)
movslq 0x4(%rax), %rax
movq %rax, -0x120(%rbp)
movl $0x0, -0x84(%rbp)
leaq -0x85(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x8e70
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rcx
leaq -0x80(%rbp), %rdi
leaq -0x84(%rbp), %rdx
callq 0x8e90
jmp 0x4839
movq -0x128(%rbp), %rsi
movq -0x130(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x8fa0
jmp 0x4852
leaq -0x80(%rbp), %rdi
callq 0x8aa0
leaq -0x85(%rbp), %rdi
callq 0x8f10
movq -0xf0(%rbp), %rax
movq %rax, %rdi
addq $0x168, %rdi            # imm = 0x168
movslq 0x4(%rax), %rsi
movl $0x0, -0x8c(%rbp)
leaq -0x8c(%rbp), %rdx
callq 0x9050
movq -0xf0(%rbp), %rax
movq %rax, %rcx
addq $0x138, %rcx            # imm = 0x138
movq %rcx, -0x148(%rbp)
movslq 0x4(%rax), %rax
movq %rax, -0x140(%rbp)
movl $0x0, -0xac(%rbp)
leaq -0xad(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x8e70
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
leaq -0xac(%rbp), %rdx
callq 0x8e90
jmp 0x48f5
movq -0x140(%rbp), %rsi
movq -0x148(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0x8fa0
jmp 0x4911
leaq -0xa8(%rbp), %rdi
callq 0x8aa0
leaq -0xad(%rbp), %rdi
callq 0x8f10
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4d23
movq -0xf0(%rbp), %rdi
addq $0xa8, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
callq 0x8e50
movl %eax, -0xb8(%rbp)
movl $0xffffffff, -0xbc(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
cmpl -0xb8(%rbp), %eax
jge 0x4d0d
movq -0xf0(%rbp), %rdi
addq $0xa8, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x8f60
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
addq $0xd8, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x8f60
cmpl $0x0, (%rax)
jne 0x4bd4
movq -0xf0(%rbp), %rdi
addq $0xf0, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq -0xf0(%rbp), %rdi
movq %rax, -0x160(%rbp)
addq $0xc0, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x8f60
movq -0x160(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movq -0xf0(%rbp), %rdi
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
addq $0x108, %rdi            # imm = 0x108
movslq -0xc4(%rbp), %rsi
callq 0x8c10
movq -0xf0(%rbp), %rdi
movq %rax, -0x158(%rbp)
addq $0xc0, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x8f60
movq -0x158(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movq -0xf0(%rbp), %rdi
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq %rdi, %rax
addq $0x150, %rax            # imm = 0x150
movq %rax, -0x150(%rbp)
addq $0xc0, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x8f60
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4bd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4b2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x8aa0
leaq -0x2d(%rbp), %rdi
callq 0x8f10
jmp 0x4d2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4b5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x8aa0
leaq -0x5d(%rbp), %rdi
callq 0x8f10
jmp 0x4d2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4b8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x8aa0
leaq -0x85(%rbp), %rdi
callq 0x8f10
jmp 0x4d2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4bc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x8aa0
leaq -0xad(%rbp), %rdi
callq 0x8f10
jmp 0x4d2c
movq -0xf0(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movslq -0xc4(%rbp), %rsi
callq 0x8c10
movq -0xf0(%rbp), %rdi
movq %rax, -0x170(%rbp)
addq $0xd8, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x8f60
movq -0x170(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movq -0xf0(%rbp), %rdi
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq %rdi, %rax
addq $0x168, %rax            # imm = 0x168
movq %rax, -0x168(%rbp)
addq $0xd8, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x8f60
movq -0x168(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movq -0xf0(%rbp), %rdi
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
addq $0xd8, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x8f60
movl (%rax), %eax
movl %eax, -0xc8(%rbp)
cmpl $-0x1, -0xbc(%rbp)
je 0x4ced
movq -0xf0(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movslq -0xbc(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0xc8(%rbp), %rsi
callq 0x8f60
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0xc8(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x497e
jmp 0x4d0f
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x4933
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)