// File: szmer[P]brill/./src/corpus.cpp
// Function: Corpus::tag_with_table(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>*)
Corpus Corpus::tag_with_table(map<string,string> * tbl) {

	// Find the most frequent tag in the table and make it default.
	map<string, int> freqs;
	for(map<string,string>::iterator i = tbl->begin(); i != tbl->end(); i++) {

		if(freqs.find(i->second) == freqs.end())
			freqs[i->second] = 1;

		else	freqs[i->second]++;

	}
	string default_tag;
	int default_freq = 0;
	for(map<string,int>::iterator i = freqs.begin(); i != freqs.end(); i++)
		if(i->second > default_freq) {
			default_freq = i->second;
			default_tag = i->first;
		}
	default_tag = "NN";

	// Create and tag the child corpus. 
	Corpus child;
	child.sentences.reserve(sentences.size());

	for( unsigned int si = 0; si < sentences.size(); si++ ) {

		vector<TaggedWord> * stc = & sentences[si];

		child.sentences.push_back( vector<TaggedWord>() );
		child.sentences.rbegin()->reserve( stc->size() );	// reserve space in the last sentence
									// vector of the child

		for( unsigned int wi = 0; wi < stc->size(); wi++ ) {
			if(tbl->find(stc->at(wi).word) != tbl->end()) // we know exact tag for this word
				child.sentences.rbegin()->push_back( TaggedWord(stc->at(wi).word,
									(*tbl)[stc->at(wi).word]) );
			else 					// use the default tag instead
				child.sentences.rbegin()->push_back( TaggedWord(stc->at(wi).word,
									default_tag) );
		}
	}

	return child;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x238(%rbp)
movq %rdi, %rax
movq %rax, -0x230(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x228(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x8d80
movq -0x18(%rbp), %rdi
callq 0x8da0
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
callq 0x8e00
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x8dd0
testb $0x1, %al
jne 0x493c
jmp 0x4a11
leaq -0x50(%rbp), %rdi
callq 0x8e90
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x48(%rbp), %rdi
callq 0x8e60
movq %rax, -0x240(%rbp)
jmp 0x495e
movq -0x240(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x8ae0
movq %rax, -0x78(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x8e30
testb $0x1, %al
jne 0x4989
jmp 0x49cb
leaq -0x50(%rbp), %rdi
callq 0x8e90
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x48(%rbp), %rdi
callq 0x88c0
movq %rax, -0x248(%rbp)
jmp 0x49ab
movq -0x248(%rbp), %rax
movl $0x1, (%rax)
jmp 0x49fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4ff1
leaq -0x50(%rbp), %rdi
callq 0x8e90
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x48(%rbp), %rdi
callq 0x88c0
movq %rax, -0x250(%rbp)
jmp 0x49ed
movq -0x250(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x49fd
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x8eb0
movq %rax, -0x80(%rbp)
jmp 0x4919
leaq -0xa0(%rbp), %rdi
callq 0x3320
movl $0x0, -0xa4(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x8a80
movq %rax, -0xb0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x8ae0
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x8ab0
testb $0x1, %al
jne 0x4a60
jmp 0x4adf
leaq -0xb0(%rbp), %rdi
callq 0x8b10
movl 0x20(%rax), %eax
cmpl -0xa4(%rbp), %eax
jle 0x4ac3
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x8b10
movq -0x258(%rbp), %rdi
movl 0x20(%rax), %eax
movl %eax, -0xa4(%rbp)
callq 0x8b10
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x3040
jmp 0x4ab0
jmp 0x4ac3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4fe5
jmp 0x4ac5
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x8b30
movq %rax, -0xc0(%rbp)
jmp 0x4a37
leaq 0xe6e0(%rip), %rsi      # 0x131c6
leaq -0xa0(%rbp), %rdi
callq 0x3310
jmp 0x4af4
movq -0x238(%rbp), %rdi
movb $0x0, -0xc1(%rbp)
callq 0x7e90
movq -0x228(%rbp), %rdi
callq 0x7dd0
movq -0x238(%rbp), %rdi
movq %rax, %rsi
callq 0x83e0
jmp 0x4b24
movl $0x0, -0xc8(%rbp)
movq -0x228(%rbp), %rdi
movl -0xc8(%rbp), %eax
movq %rax, -0x260(%rbp)
callq 0x7dd0
movq %rax, %rcx
movq -0x260(%rbp), %rax
cmpq %rcx, %rax
jae 0x4f98
movq -0x228(%rbp), %rdi
movl -0xc8(%rbp), %eax
movl %eax, %esi
callq 0x7e00
movq %rax, -0xd0(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xf0(%rbp)
movq $0x0, -0xe0(%rbp)
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x7fa0
movq -0x238(%rbp), %rdi
movq -0x268(%rbp), %rsi
callq 0x7f70
jmp 0x4bb2
leaq -0xf0(%rbp), %rdi
callq 0x7fc0
movq -0x238(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x8180
movq -0x278(%rbp), %rdi
callq 0x81d0
movq %rax, -0x270(%rbp)
jmp 0x4bed
movq -0xd0(%rbp), %rdi
callq 0x7e20
movq -0x270(%rbp), %rdi
movq %rax, %rsi
callq 0x85a0
jmp 0x4c0a
movl $0x0, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
movq %rax, -0x280(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x7e20
movq %rax, %rcx
movq -0x280(%rbp), %rax
cmpq %rcx, %rax
jae 0x4f82
movq -0x18(%rbp), %rax
movq %rax, -0x290(%rbp)
movq -0xd0(%rbp), %rdi
movl -0xfc(%rbp), %eax
movl %eax, %esi
callq 0x8a20
movq %rax, -0x288(%rbp)
jmp 0x4c68
movq -0x288(%rbp), %rsi
movq -0x290(%rbp), %rdi
callq 0x8ef0
movq %rax, -0x298(%rbp)
jmp 0x4c84
movq -0x298(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x18(%rbp), %rdi
callq 0x8e00
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x8dd0
testb $0x1, %al
jne 0x4cbe
jmp 0x4e51
movq -0x238(%rbp), %rsi
leaq -0x118(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x8180
movq -0x2a8(%rbp), %rdi
callq 0x81d0
movq %rax, -0x2a0(%rbp)
jmp 0x4ced
movq -0xd0(%rbp), %rdi
movl -0xfc(%rbp), %eax
movl %eax, %esi
callq 0x8a20
movq %rax, -0x2b0(%rbp)
jmp 0x4d0a
movq -0x2b0(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x30f0
jmp 0x4d1f
movq -0x18(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movq -0xd0(%rbp), %rdi
movl -0xfc(%rbp), %eax
movl %eax, %esi
callq 0x8a20
movq %rax, -0x2b8(%rbp)
jmp 0x4d47
movq -0x2b8(%rbp), %rsi
movq -0x2c0(%rbp), %rdi
callq 0x8c40
movq %rax, -0x2c8(%rbp)
jmp 0x4d63
movq -0x2c8(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0x30f0
jmp 0x4d78
leaq -0x158(%rbp), %rdi
leaq -0x178(%rbp), %rsi
leaq -0x198(%rbp), %rdx
callq 0x8240
jmp 0x4d94
movq -0x2a0(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x8210
jmp 0x4da9
leaq -0x158(%rbp), %rdi
callq 0x82d0
leaq -0x198(%rbp), %rdi
callq 0x34b8
leaq -0x178(%rbp), %rdi
callq 0x34b8
jmp 0x4f6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4fd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x7fc0
jmp 0x4fd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4e40
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4e34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x82d0
leaq -0x198(%rbp), %rdi
callq 0x34b8
leaq -0x178(%rbp), %rdi
callq 0x34b8
jmp 0x4fd9
movq -0x238(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x8180
movq -0x2d8(%rbp), %rdi
callq 0x81d0
movq %rax, -0x2d0(%rbp)
jmp 0x4e80
movq -0xd0(%rbp), %rdi
movl -0xfc(%rbp), %eax
movl %eax, %esi
callq 0x8a20
movq %rax, -0x2e0(%rbp)
jmp 0x4e9d
movq -0x2e0(%rbp), %rsi
leaq -0x200(%rbp), %rdi
callq 0x30f0
jmp 0x4eb2
leaq -0x220(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x30f0
jmp 0x4ec7
leaq -0x1e0(%rbp), %rdi
leaq -0x200(%rbp), %rsi
leaq -0x220(%rbp), %rdx
callq 0x8240
jmp 0x4ee3
movq -0x2d0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x8210
jmp 0x4ef8
leaq -0x1e0(%rbp), %rdi
callq 0x82d0
leaq -0x220(%rbp), %rdi
callq 0x34b8
leaq -0x200(%rbp), %rdi
callq 0x34b8
jmp 0x4f6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4f5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4f52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x82d0
leaq -0x220(%rbp), %rdi
callq 0x34b8
leaq -0x200(%rbp), %rdi
callq 0x34b8
jmp 0x4fd9
jmp 0x4f6e
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x4c14
jmp 0x4f84
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x4b2e
movb $0x1, -0xc1(%rbp)
testb $0x1, -0xc1(%rbp)
jne 0x4fb4
movq -0x238(%rbp), %rdi
callq 0x8300
leaq -0xa0(%rbp), %rdi
callq 0x34b8
leaq -0x48(%rbp), %rdi
callq 0x8f20
movq -0x230(%rbp), %rax
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
movq -0x238(%rbp), %rdi
callq 0x8300
leaq -0xa0(%rbp), %rdi
callq 0x34b8
leaq -0x48(%rbp), %rdi
callq 0x8f20
movq -0x68(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)