// File: abaheti95[P]HMM-LDA/Models/cpp_hmm_lda/model.cpp
// Function: HMMLDA::add_counts_for_new_document(std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, int)
void HMMLDA::add_counts_for_new_document(vector<int> &document, vector<int> &topic_assignment, vector<int> &class_assignment, vector<int> &num_words_in_document_assigned_to_topic, int doc_size) {
	int previous_class = -1;
	for(int word_idx = 0; word_idx < doc_size; word_idx++) {
		int word = document[word_idx];
		if(class_assignment[word_idx] == 0) {		// Count the topic only when the class is 0
			//TODO: Think about how to implement num_words_in_doc_assigned_to_topic for a new document
			num_words_in_document_assigned_to_topic[topic_assignment[word_idx]]++;
			num_same_words_assigned_to_topic[word][topic_assignment[word_idx]]++;
			num_words_assigned_to_topic[topic_assignment[word_idx]]++;
		}
		num_same_words_assigned_to_class[word][class_assignment[word_idx]]++;
		num_words_assigned_to_class[class_assignment[word_idx]]++;
		int current_class = class_assignment[word_idx];
		if(previous_class != -1)
			num_transitions[previous_class][current_class]++;
		previous_class = current_class;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x6b77
movq -0x10(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x8f60
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x8f60
cmpl $0x0, (%rax)
jne 0x6abb
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x8f60
movq -0x60(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movq -0x48(%rbp), %rdi
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
addq $0x108, %rdi            # imm = 0x108
movslq -0x38(%rbp), %rsi
callq 0x8c10
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x8f60
movq -0x58(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movq %rax, %rcx
movq -0x48(%rbp), %rax
movl (%rcx), %edx
addl $0x1, %edx
movl %edx, (%rcx)
addq $0x150, %rax            # imm = 0x150
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x8f60
movq -0x50(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movslq -0x38(%rbp), %rsi
callq 0x8c10
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x8f60
movq -0x70(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movq %rax, %rcx
movq -0x48(%rbp), %rax
movl (%rcx), %edx
addl $0x1, %edx
movl %edx, (%rcx)
addq $0x168, %rax            # imm = 0x168
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x8f60
movq -0x68(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8f60
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x8f60
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
cmpl $-0x1, -0x30(%rbp)
je 0x6b63
movq -0x48(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movslq -0x30(%rbp), %rsi
callq 0x8c10
movq %rax, %rdi
movslq -0x3c(%rbp), %rsi
callq 0x8f60
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x69f6
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)