// File: szmer[P]brill/./src/corpus.cpp
// Function: Corpus::compare_corpora(Corpus*, Corpus*)
double Corpus::compare_corpora(Corpus * fst, Corpus * sec) {
	if(fst->sentences.size() != sec->sentences.size())
		throw "compare_corpora: unequal number of sentences!";

	int word_count = 0;
	int err_count = 0;

	for(unsigned int si = 0; si < fst->sentences.size(); si++) {
		if(fst->sentences[si].size() != sec->sentences[si].size())
			throw "compare_corpora: unequal size of one of the sentences!";

		word_count += fst->sentences[si].size(); // count each word

		for(unsigned int wi = 0; wi < fst->sentences[si].size(); wi++) // find actual disagreements
			if(fst->sentences[si][wi].tag != sec->sentences[si][wi].tag)
				err_count ++;
	}

	if(word_count == 0)
		throw "compare_corpora: corpora seem to be empty!";

	return ((double)word_count - (double)err_count) / (double)word_count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7dd0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x7dd0
movq %rax, %rcx
movq -0x28(%rbp), %rax
cmpq %rcx, %rax
je 0x3649
movl $0x8, %edi
callq 0x3120
movq %rax, %rdi
leaq 0xf9fa(%rip), %rax      # 0x13030
movq %rax, (%rdi)
movq 0x18980(%rip), %rsi     # 0x1bfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33c0
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7dd0
movq %rax, %rcx
movq -0x30(%rbp), %rax
cmpq %rcx, %rax
jae 0x37b1
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x7e00
movq %rax, %rdi
callq 0x7e20
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x7e00
movq %rax, %rdi
callq 0x7e20
movq %rax, %rcx
movq -0x38(%rbp), %rax
cmpq %rcx, %rax
je 0x36e1
movl $0x8, %edi
callq 0x3120
movq %rax, %rdi
leaq 0xf990(%rip), %rax      # 0x1305e
movq %rax, (%rdi)
movq 0x188e8(%rip), %rsi     # 0x1bfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33c0
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x7e00
movq %rax, %rdi
callq 0x7e20
movq %rax, %rcx
movslq -0x14(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x14(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x7e00
movq %rax, %rdi
callq 0x7e20
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jae 0x37a1
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x7e00
movq %rax, %rdi
movl -0x20(%rbp), %eax
movl %eax, %esi
callq 0x7e70
addq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x7e00
movq %rax, %rdi
movl -0x20(%rbp), %eax
movl %eax, %esi
callq 0x7e70
movq -0x48(%rbp), %rdi
movq %rax, %rsi
addq $0x20, %rsi
callq 0x7e40
testb $0x1, %al
jne 0x3788
jmp 0x3791
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3793
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x370b
jmp 0x37a3
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x365e
cmpl $0x0, -0x14(%rbp)
jne 0x37de
movl $0x8, %edi
callq 0x3120
movq %rax, %rdi
leaq 0xf8ca(%rip), %rax      # 0x13095
movq %rax, (%rdi)
movq 0x187eb(%rip), %rsi     # 0x1bfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33c0
cvtsi2sdl -0x14(%rbp), %xmm0
cvtsi2sdl -0x18(%rbp), %xmm1
subsd %xmm1, %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
divsd %xmm1, %xmm0
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)