// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rsi, -0x38(%rbp)
leaq -0xf8(%rbp), %r13
andl $0x0, (%r13)
andq $0x0, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
andq $0x0, 0x20(%r13)
movq %rdi, -0x30(%rbp)
movq 0x18(%rdx), %r15
movq %rdx, -0x50(%rbp)
leaq 0x8(%rdx), %rax
movq %rax, -0x48(%rbp)
leaq -0x100(%rbp), %rbx
cmpq -0x48(%rbp), %r15
je 0x2f1a
leaq 0x40(%r15), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7052
cmpq %r13, %rax
je 0x2efc
movq %rbx, %rdi
movq %r12, %rsi
callq 0x513c
incl (%rax)
jmp 0x2f0d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x513c
movl $0x1, (%rax)
movq %r15, %rdi
callq 0x2120
movq %rax, %r15
jmp 0x2ed3
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %ebx, %ebx
movq -0xe8(%rbp), %r15
leaq -0x70(%rbp), %r14
cmpq %r13, %r15
je 0x2f61
movl 0x40(%r15), %r12d
cmpl %ebx, %r12d
jle 0x2f54
leaq 0x20(%r15), %rsi
movq %r14, %rdi
callq 0x2110
movl %r12d, %ebx
movq %r15, %rdi
callq 0x2120
movq %rax, %r15
jmp 0x2f37
leaq 0x527e(%rip), %rsi      # 0x81e6
leaq -0x70(%rbp), %rdi
callq 0x2320
xorps %xmm0, %xmm0
movq -0x30(%rbp), %rdi
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x20(%rdi), %rax
andl $0x0, 0x20(%rdi)
andq $0x0, 0x28(%rdi)
movq %rax, 0x30(%rdi)
movq %rax, 0x38(%rdi)
andq $0x0, 0x40(%rdi)
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, %rsi
callq 0x4f6a
xorl %esi, %esi
leaq -0x140(%rbp), %r12
movl %esi, %esi
movq -0x38(%rbp), %rax
movq (%rax), %r15
movq 0x8(%rax), %rax
subq %r15, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rsi, -0x40(%rbp)
cmpq %rsi, %rax
jbe 0x3167
xorps %xmm0, %xmm0
movaps %xmm0, -0x140(%rbp)
andq $0x0, -0x130(%rbp)
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5d3c
imulq $0x18, -0x40(%rbp), %rax
addq %rax, %r15
movq %r12, %rdi
callq 0x4dc8
movq 0x8(%rbx), %rdi
addq $-0x18, %rdi
movq 0x8(%r15), %rsi
subq (%r15), %rsi
sarq $0x6, %rsi
callq 0x501a
xorl %ebx, %ebx
movl %ebx, %ebx
movq 0x8(%r15), %rax
subq (%r15), %rax
sarq $0x6, %rax
cmpq %rbx, %rax
jbe 0x315c
movq %r15, %rdi
movq %rbx, %rsi
callq 0x51a6
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x709a
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %r13
addq $-0x18, %r13
cmpq -0x48(%rbp), %rax
je 0x30eb
movq %r15, %rdi
movq %rbx, %rsi
callq 0x51a6
leaq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0x2210
movq %r15, %rdi
movq %rbx, %rsi
callq 0x51a6
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x51c8
leaq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x2210
movq %r12, %rdi
leaq -0xd0(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x4e92
movq %r13, %rdi
movq %r12, %rsi
callq 0x5f32
movq %r12, %rdi
callq 0x4efe
leaq -0xb0(%rbp), %rdi
callq 0x2368
leaq -0xd0(%rbp), %rdi
jmp 0x3150
movq %r15, %rdi
movq %rbx, %rsi
callq 0x51a6
leaq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x2210
leaq -0x160(%rbp), %r14
movq %r14, %rdi
leaq -0x70(%rbp), %rsi
callq 0x2210
movq %r12, %rdi
leaq -0x90(%rbp), %rsi
movq %r14, %rdx
callq 0x4e92
movq %r13, %rdi
movq %r12, %rsi
callq 0x5f32
movq %r12, %rdi
callq 0x4efe
leaq -0x160(%rbp), %rdi
callq 0x2368
leaq -0x90(%rbp), %rdi
callq 0x2368
incl %ebx
jmp 0x302e
movq -0x40(%rbp), %rsi
incl %esi
jmp 0x2fbe
leaq -0x70(%rbp), %rdi
callq 0x2368
leaq -0x100(%rbp), %rdi
callq 0x55b8
movq -0x30(%rbp), %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3220
jmp 0x3199
movq %rax, %rbx
jmp 0x322c
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x4dc8
jmp 0x3223
jmp 0x3220
jmp 0x31b6
movq %rax, %rbx
jmp 0x3235
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x4efe
jmp 0x31cf
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
callq 0x2368
jmp 0x31e0
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0x3219
movq %rax, %rbx
jmp 0x31fd
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x4efe
leaq -0xb0(%rbp), %rdi
callq 0x2368
jmp 0x3212
jmp 0x3220
jmp 0x3220
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x2368
jmp 0x3223
movq %rax, %rbx
movq -0x30(%rbp), %rdi
callq 0x4f1e
leaq -0x70(%rbp), %rdi
callq 0x2368
leaq -0x100(%rbp), %rdi
callq 0x55b8
movq %rbx, %rdi
callq 0x22e0
nop