// File: szmer[P]brill/./src/rules_applier.cpp
// Function: RulesApplier::RulesApplier(char const*, char const*, Corpus*)
RulesApplier::RulesApplier(const char * tgfname, const char * rlfname, Corpus * standard) {

	tag_index = Corpus::load_tagset(tgfname);

	ifstream rl_file(rlfname);
	char buff [256];
	memset(buff, 256, ' '); // avoid memory junk (see loop condition)

	// Load the unigram table.
	while(rl_file.good()) { // until we reach linebreak (where rule numbers begin)
		rl_file.getline(buff, 256, '\t');

		if(strchr(buff, '\n') != NULL) // this is where rule ids start
			break;

		if(rl_file.gcount() == 256 && buff[255] != '\0')
			throw "load_rules: tag table in ruleset file has entry longer than 256 characters!";

		string tag_entry(buff);
		// Word and tag are delimited by a space.
		tag_lookup[ tag_entry.substr(0, tag_entry.find(' ')) ]
								= tag_entry.substr( tag_entry.find(' ') + 1 );
	}

	// Return to the place where rules ids are:
	rl_file.clear();
	rl_file.seekg( rl_file.tellg() - rl_file.gcount() );

	// Load the list of the rules.
	while(rl_file.good()) {

		rl_file.getline(buff, 256);
		if(rl_file.gcount() == 256 && buff[255] != '\0')
			throw "load_rules: ruleset file has a line longer than 256 characters!";
		if(string(buff).size() > 0)
			rules.push_back( atoi_longlong(buff) );
	}

	gold_corp = standard;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4d0, %rsp            # imm = 0x4D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x418(%rbp)
movq %rdi, %rax
movq %rax, -0x428(%rbp)
callq 0x8330
movq -0x418(%rbp), %rdi
addq $0x18, %rdi
movq %rdi, -0x420(%rbp)
callq 0x9200
movq -0x418(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x410(%rbp)
callq 0x9220
movq -0x10(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x3da0
jmp 0x6dc2
movq -0x428(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movq %rsi, -0x430(%rbp)
callq 0x9240
movq -0x430(%rbp), %rdi
callq 0x8380
movq -0x18(%rbp), %rsi
leaq -0x250(%rbp), %rdi
movl $0x8, %edx
callq 0x3430
jmp 0x6dfc
leaq -0x350(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x3140
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x250(%rbp,%rax), %rdi
callq 0x33b0
movb %al, -0x431(%rbp)
jmp 0x6e2f
movb -0x431(%rbp), %al
testb $0x1, %al
jne 0x6e3e
jmp 0x708a
leaq -0x250(%rbp), %rdi
leaq -0x350(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
movl $0x9, %ecx
callq 0x3460
jmp 0x6e5d
leaq -0x350(%rbp), %rdi
movl $0xa, %esi
callq 0x30c0
cmpq $0x0, %rax
je 0x6e9b
jmp 0x708a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x72f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x72eb
leaq -0x250(%rbp), %rdi
callq 0x34a0
movq %rax, -0x440(%rbp)
jmp 0x6eb0
movq -0x440(%rbp), %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x6ef7
movsbl -0x251(%rbp), %eax
cmpl $0x0, %eax
je 0x6ef7
movl $0x8, %edi
callq 0x3120
movq %rax, %rdi
leaq 0xc40d(%rip), %rax      # 0x132ec
movq %rax, (%rdi)
movq 0x150d7(%rip), %rsi     # 0x1bfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33c0
jmp 0x7324
leaq -0x371(%rbp), %rdi
movq %rdi, -0x448(%rbp)
callq 0x3410
movq -0x448(%rbp), %rdx
leaq -0x370(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x7ec0
jmp 0x6f26
leaq -0x371(%rbp), %rdi
callq 0x3280
xorl %eax, %eax
movl %eax, %edx
leaq -0x370(%rbp), %rdi
movq %rdi, -0x450(%rbp)
movl $0x20, %esi
callq 0x3300
movq -0x450(%rbp), %rsi
movq %rax, %rdx
incq %rdx
leaq -0x398(%rbp), %rdi
movq $-0x1, %rcx
callq 0x3240
jmp 0x6f70
movq -0x428(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x468(%rbp)
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x458(%rbp)
leaq -0x370(%rbp), %rdi
movq %rdi, -0x460(%rbp)
movl $0x20, %esi
callq 0x3300
movq -0x460(%rbp), %rsi
movq -0x458(%rbp), %rdx
movq %rax, %rcx
leaq -0x3b8(%rbp), %rdi
callq 0x3240
jmp 0x6fc4
movq -0x468(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0x9270
movq %rax, -0x470(%rbp)
jmp 0x6fe0
movq -0x470(%rbp), %rdi
leaq -0x398(%rbp), %rsi
callq 0x32b0
leaq -0x3b8(%rbp), %rdi
callq 0x34b8
leaq -0x398(%rbp), %rdi
callq 0x34b8
leaq -0x370(%rbp), %rdi
callq 0x34b8
jmp 0x6e0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x371(%rbp), %rdi
callq 0x3280
jmp 0x72eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7079
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x706d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x3b8(%rbp), %rdi
callq 0x34b8
leaq -0x398(%rbp), %rdi
callq 0x34b8
leaq -0x370(%rbp), %rdi
callq 0x34b8
jmp 0x72eb
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x250(%rbp,%rax), %rdi
xorl %esi, %esi
callq 0x33a0
jmp 0x70a6
leaq -0x250(%rbp), %rdi
callq 0x33e0
movq %rdx, -0x480(%rbp)
movq %rax, -0x478(%rbp)
jmp 0x70c2
movq -0x480(%rbp), %rax
movq -0x478(%rbp), %rcx
movq %rcx, -0x3d8(%rbp)
movq %rax, -0x3d0(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x34a0
movq %rax, -0x488(%rbp)
jmp 0x70f3
movq -0x488(%rbp), %rsi
leaq -0x3d8(%rbp), %rdi
callq 0x9350
movq %rdx, -0x498(%rbp)
movq %rax, -0x490(%rbp)
jmp 0x7116
movq -0x498(%rbp), %rax
movq -0x490(%rbp), %rcx
movq %rcx, -0x3c8(%rbp)
movq %rax, -0x3c0(%rbp)
movq -0x3c8(%rbp), %rsi
movq -0x3c0(%rbp), %rdx
leaq -0x250(%rbp), %rdi
callq 0x32d0
jmp 0x714e
jmp 0x7150
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x250(%rbp,%rax), %rdi
callq 0x33b0
movb %al, -0x499(%rbp)
jmp 0x7170
movb -0x499(%rbp), %al
testb $0x1, %al
jne 0x717f
jmp 0x72c7
leaq -0x250(%rbp), %rdi
leaq -0x350(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x30a0
jmp 0x7199
leaq -0x250(%rbp), %rdi
callq 0x34a0
movq %rax, -0x4a8(%rbp)
jmp 0x71ae
movq -0x4a8(%rbp), %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x71f5
movsbl -0x251(%rbp), %eax
cmpl $0x0, %eax
je 0x71f5
movl $0x8, %edi
callq 0x3120
movq %rax, %rdi
leaq 0xc15b(%rip), %rax      # 0x13338
movq %rax, (%rdi)
movq 0x14dd9(%rip), %rsi     # 0x1bfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33c0
jmp 0x7324
leaq -0x3f9(%rbp), %rdi
movq %rdi, -0x4b0(%rbp)
callq 0x3410
movq -0x4b0(%rbp), %rdx
leaq -0x3f8(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x7ec0
jmp 0x7224
leaq -0x3f8(%rbp), %rdi
callq 0x3190
movq %rax, -0x4b8(%rbp)
leaq -0x3f8(%rbp), %rdi
callq 0x34b8
leaq -0x3f9(%rbp), %rdi
callq 0x3280
movq -0x4b8(%rbp), %rax
cmpq $0x0, %rax
jbe 0x72c2
movq -0x428(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x4c8(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x7330
movq %rax, -0x4c0(%rbp)
jmp 0x7283
movq -0x4c8(%rbp), %rdi
movq -0x4c0(%rbp), %rax
movq %rax, -0x408(%rbp)
leaq -0x408(%rbp), %rsi
callq 0x9390
jmp 0x72a6
jmp 0x72c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x3f9(%rbp), %rdi
callq 0x3280
jmp 0x72eb
jmp 0x7150
movq -0x428(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, 0x60(%rax)
leaq -0x250(%rbp), %rdi
callq 0x3080
addq $0x4d0, %rsp            # imm = 0x4D0
popq %rbp
retq
leaq -0x250(%rbp), %rdi
callq 0x3080
movq -0x410(%rbp), %rdi
callq 0x93c0
movq -0x420(%rbp), %rdi
callq 0x93e0
movq -0x418(%rbp), %rdi
callq 0x8380
movq -0x40(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)