// File: /workspace/github_cpp_makefile_star2_O3/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, -0x70(%rbp)
movq %rdx, %r14
movq %rdi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, -0x60(%rbp)
leaq 0x30(%rdi), %rax
movq %rax, -0x68(%rbp)
leaq 0x38(%rdi), %rax
movl $0x0, 0x38(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x40(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movupd %xmm0, 0x10(%rdi)
movupd %xmm0, 0x20(%rdi)
movq %rax, 0x48(%rdi)
movq %rax, 0x50(%rdi)
movq %rcx, 0x58(%rdi)
leaq -0x1b0(%rbp), %rdi
movq %rbx, -0x50(%rbp)
callq 0x2b68
movupd (%rbx), %xmm0
movq 0x10(%rbx), %rax
leaq -0x1b0(%rbp), %r15
movq (%r15), %rcx
movq %rcx, (%rbx)
movq 0x8(%r15), %rcx
movq %rcx, 0x8(%rbx)
movq 0x10(%r15), %rcx
movq %rcx, 0x10(%rbx)
leaq -0x3b8(%rbp), %rdi
movupd %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
callq 0x6230
movq %r15, %rdi
callq 0x6230
leaq -0x3b8(%rbp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x2340
xorpd %xmm0, %xmm0
movapd %xmm0, -0x1a0(%rbp)
movapd %xmm0, -0x1b0(%rbp)
movq -0x3b8(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x398(%rbp,%rax)
jne 0x52c7
leaq -0x1b0(%rbp), %r13
leaq 0x41a2(%rip), %rax      # 0x930c
movq %rax, -0x58(%rbp)
leaq -0x48(%rbp), %r14
leaq -0xb0(%rbp), %r15
leaq -0x90(%rbp), %r12
movl $0x100, %edx            # imm = 0x100
leaq -0x3b8(%rbp), %rdi
movq %r13, %rsi
movl $0x9, %ecx
callq 0x2360
movq %r13, %rdi
movl $0xa, %esi
callq 0x20b0
testq %rax, %rax
jne 0x52bc
cmpq $0x100, -0x3b0(%rbp) # imm = 0x100
jne 0x51c9
cmpb $0x0, -0xb1(%rbp)
jne 0x54aa
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %r13, %rdi
callq 0x20d0
leaq (%rax,%rbp), %rdx
addq $-0x1b0, %rdx           # imm = 0xFE50
movq %r14, %rdi
movq %r13, %rsi
callq 0x6eb4
movq %r14, %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x2230
leaq 0x1(%rax), %rdx
movq %r15, %rdi
movq %r14, %rsi
movq $-0x1, %rcx
callq 0x21e0
movq %r14, %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x2230
movq %r12, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x21e0
movq -0x68(%rbp), %rdi
movq %r12, %rsi
callq 0x66a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x2210
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x5266
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x5288
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x52a1
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x3b8(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x398(%rbp,%rax)
je 0x5180
jmp 0x52c7
movq -0x3b8(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x3b8, %rdi           # imm = 0xFC48
xorl %esi, %esi
callq 0x22d0
leaq -0x3b8(%rbp), %rdi
callq 0x22f0
leaq -0x3b8(%rbp), %rdi
subq 0x8(%rdi), %rax
movq %rax, %rsi
callq 0x2220
movq -0x3b8(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x398(%rbp,%rax)
jne 0x5484
leaq (%rax,%rbp), %rdi
addq $-0x3b8, %rdi           # imm = 0xFC48
leaq -0x38(%rbp), %r14
leaq -0x1b0(%rbp), %r15
leaq 0x402a(%rip), %rax      # 0x9358
movq %rax, -0x58(%rbp)
leaq -0x48(%rbp), %r12
movl $0xa, %esi
callq 0x2190
movsbl %al, %ecx
movl $0x100, %edx            # imm = 0x100
leaq -0x3b8(%rbp), %rdi
movq %r15, %rsi
callq 0x2360
cmpq $0x100, -0x3b0(%rbp) # imm = 0x100
jne 0x5371
cmpb $0x0, -0xb1(%rbp)
jne 0x54aa
movq %r14, -0x48(%rbp)
movq %r15, %rdi
callq 0x20d0
leaq (%rax,%rbp), %rdx
addq $-0x1b0, %rdx           # imm = 0xFE50
movq %r12, %rdi
movq %r15, %rsi
callq 0x6eb4
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rbx
cmpq %r14, %rdi
je 0x53ac
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testq %rbx, %rbx
movq -0x50(%rbp), %rbx
je 0x5464
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
jle 0x5420
movl %eax, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
leal -0x1(%rax), %ebx
xorl %r15d, %r15d
xorl %r14d, %r14d
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
movsd 0x3c59(%rip), %xmm0     # 0x9040
callq 0x2310
movsbl -0x1b0(%rbp,%r15), %eax
addl $-0x30, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r14, %xmm2
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %r14
incq %r15
decl %ebx
cmpq %r15, %r13
jne 0x53d8
jmp 0x5423
xorl %r14d, %r14d
movq %r14, -0x48(%rbp)
movq -0x50(%rbp), %rbx
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x544d
movq %r14, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x20(%rbx)
leaq -0x38(%rbp), %r14
leaq -0x1b0(%rbp), %r15
jmp 0x5464
movq -0x60(%rbp), %rdi
movq %r12, %rdx
callq 0x8692
leaq -0x38(%rbp), %r14
leaq -0x1b0(%rbp), %r15
movq -0x3b8(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x3b8, %rdi           # imm = 0xFC48
cmpl $0x0, 0x20(%rdi)
je 0x5336
movq -0x70(%rbp), %rax
movq %rax, 0x60(%rbx)
leaq -0x3b8(%rbp), %rdi
callq 0x2070
addq $0x398, %rsp            # imm = 0x398
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0x20f0
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
movq 0x7b06(%rip), %rsi      # 0xcfc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x22e0
jmp 0x54ce
movq %rax, %r14
jmp 0x5557
jmp 0x5548
jmp 0x5548
jmp 0x5548
movq %rax, %r14
jmp 0x5527
movq %rax, %r14
jmp 0x5505
movq %rax, %r14
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x5505
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x5527
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x554b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x554b
jmp 0x5548
jmp 0x5548
jmp 0x5548
movq %rax, %r14
leaq -0x3b8(%rbp), %rdi
callq 0x2070
movq -0x68(%rbp), %rdi
callq 0x6960
movq -0x60(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
movq -0x50(%rbp), %rbx
je 0x557c
movq 0x28(%rbx), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x6230
movq %r14, %rdi
callq 0x2320