// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x398, %rsp            # imm = 0x398
movq %rcx, -0x50(%rbp)
movq %rdx, %rbx
movq %rdi, %r15
leaq 0x18(%rdi), %rax
movq %rax, -0x48(%rbp)
leaq 0x30(%rdi), %rax
movq %rax, -0x40(%rbp)
leaq 0x38(%rdi), %rax
andl $0x0, 0x38(%rdi)
andq $0x0, 0x40(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movupd %xmm0, 0x10(%rdi)
movupd %xmm0, 0x20(%rdi)
movq %rax, 0x48(%rdi)
movq %rax, 0x50(%rdi)
andq $0x0, 0x58(%rdi)
leaq -0x2b8(%rbp), %rdi
movq %r15, -0x38(%rbp)
callq 0x2968
leaq -0x2b8(%rbp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x7306
movq %r14, %rdi
callq 0x4f3e
leaq -0x2b8(%rbp), %rdi
pushq $0x8
popq %rdx
movq %rbx, %rsi
callq 0x2300
xorpd %xmm0, %xmm0
leaq -0x3c0(%rbp), %r13
movapd %xmm0, 0x10(%r13)
movapd %xmm0, (%r13)
leaq 0x3f6e(%rip), %rax      # 0x830c
movq %rax, -0x30(%rbp)
leaq -0x70(%rbp), %r14
leaq -0x90(%rbp), %r12
pushq $0x20
popq %rbx
leaq -0xb0(%rbp), %r15
movq -0x2b8(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x298(%rbp,%rax)
jne 0x449c
movl $0x100, %edx            # imm = 0x100
leaq -0x2b8(%rbp), %rdi
movq %r13, %rsi
pushq $0x9
popq %rcx
callq 0x2330
movq %r13, %rdi
pushq $0xa
popq %rsi
callq 0x20a0
testq %rax, %rax
jne 0x4491
cmpq $0x100, -0x2b0(%rbp) # imm = 0x100
jne 0x4415
cmpb $0x0, -0x2c1(%rbp)
jne 0x45f4
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4d8c
movq %r14, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x2200
leaq 0x1(%rax), %rdx
movq %r12, %rdi
movq %r14, %rsi
pushq $-0x1
popq %rcx
callq 0x21b0
movq %r14, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x2200
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x21b0
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x534e
movq %rax, %rdi
movq %r12, %rsi
callq 0x21d0
movq %r15, %rdi
callq 0x2368
movq %r12, %rdi
callq 0x2368
movq %r14, %rdi
callq 0x2368
jmp 0x43b7
movq -0x2b8(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x2b8, %rdi           # imm = 0xFD48
xorl %esi, %esi
callq 0x22a0
leaq -0x2b8(%rbp), %rdi
callq 0x22c0
leaq -0x2b8(%rbp), %rdi
subq 0x8(%rdi), %rax
movq %rax, %rsi
callq 0x21e0
leaq -0x3c0(%rbp), %r14
leaq 0x3e7d(%rip), %rax      # 0x8358
movq %rax, -0x30(%rbp)
leaq -0x70(%rbp), %r15
movq -0x2b8(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x298(%rbp,%rax)
jne 0x45ca
movl $0x100, %edx            # imm = 0x100
leaq -0x2b8(%rbp), %rdi
movq %r14, %rsi
callq 0x2080
cmpq $0x100, -0x2b0(%rbp) # imm = 0x100
jne 0x452a
cmpb $0x0, -0x2c1(%rbp)
jne 0x45f4
movq %r15, %rdi
movq %r14, %rsi
leaq -0x90(%rbp), %rdx
callq 0x4d8c
movq -0x68(%rbp), %rbx
movq %r15, %rdi
callq 0x2368
testq %rbx, %rbx
je 0x44e3
movq %r14, %rdi
callq 0x20c0
movq %rax, %r13
testl %r13d, %r13d
movl $0x0, %ebx
cmovgl %r13d, %ebx
decl %r13d
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpq %r12, %rbx
je 0x45ae
cvtsi2sd %r13d, %xmm1
movsd 0x3ac1(%rip), %xmm0     # 0x8040
callq 0x22d0
movsbl -0x3c0(%rbp,%r12), %eax
addl $-0x30, %eax
cvtsi2sd %eax, %xmm1
cvtsi2sd %r14, %xmm2
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %r14
incq %r12
decl %r13d
jmp 0x456d
movq %r14, -0x70(%rbp)
movq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x74e4
leaq -0x3c0(%rbp), %r14
jmp 0x44e3
movq -0x38(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, 0x60(%rax)
leaq -0x2b8(%rbp), %rdi
callq 0x2060
addq $0x398, %rsp            # imm = 0x398
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x8
popq %rdi
callq 0x20f0
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq 0x79be(%rip), %rsi      # 0xbfc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x22b0
jmp 0x4616
movq %rax, %rbx
jmp 0x4666
jmp 0x4657
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x2368
jmp 0x4631
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x2368
jmp 0x4642
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x2368
jmp 0x465a
jmp 0x4657
jmp 0x4657
jmp 0x4657
jmp 0x4657
jmp 0x4657
movq %rax, %rbx
leaq -0x2b8(%rbp), %rdi
callq 0x2060
movq -0x40(%rbp), %rdi
callq 0x5634
movq -0x48(%rbp), %rdi
callq 0x72c8
movq -0x38(%rbp), %rdi
callq 0x4f3e
movq %rbx, %rdi
callq 0x22e0
nop