// File: /workspace/github_cpp_makefile_star2_O1/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 0x2b7a
leaq -0x3c0(%rbp), %rdi
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rbx), %rax
movupd 0x8(%rbx), %xmm0
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)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movupd %xmm0, 0x8(%rdi)
movq %rcx, (%r15)
movq %rdx, 0x8(%r15)
movq %rsi, 0x10(%r15)
callq 0x61a0
movq %r15, %rdi
callq 0x61a0
leaq -0x3c0(%rbp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x2340
xorpd %xmm0, %xmm0
movapd %xmm0, -0x1a0(%rbp)
movapd %xmm0, -0x1b0(%rbp)
movq -0x3c0(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x3a0(%rbp,%rax)
jne 0x51ed
leaq -0x1b0(%rbp), %r14
leaq 0x426f(%rip), %rax      # 0x930c
movq %rax, -0x58(%rbp)
leaq -0x48(%rbp), %r15
leaq -0xb0(%rbp), %r12
leaq -0x90(%rbp), %r13
movl $0x100, %edx            # imm = 0x100
leaq -0x3c0(%rbp), %rdi
movq %r14, %rsi
movl $0x9, %ecx
callq 0x2360
movq %r14, %rdi
movl $0xa, %esi
callq 0x20b0
testq %rax, %rax
jne 0x51ed
cmpq $0x100, -0x3b8(%rbp) # imm = 0x100
jne 0x50fc
cmpb $0x0, -0xb1(%rbp)
jne 0x53d7
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %r14, %rdi
callq 0x20d0
leaq (%rax,%rbp), %rdx
addq $-0x1b0, %rdx           # imm = 0xFE50
movq %r15, %rdi
movq %r14, %rsi
callq 0x6e0c
movq %r15, %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x2230
leaq 0x1(%rax), %rdx
movq %r12, %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x21e0
movq %r15, %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x2230
movq %r13, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x21e0
movq -0x68(%rbp), %rdi
movq %r13, %rsi
callq 0x6602
movq %rax, %rdi
movq %r12, %rsi
callq 0x2210
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x5199
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x51bb
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x51d4
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x3c0(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x3a0(%rbp,%rax)
je 0x50b3
movq -0x3c0(%rbp), %rax
leaq -0x3c0(%rbp), %rdi
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x22d0
leaq -0x3c0(%rbp), %rdi
callq 0x22f0
leaq -0x3c0(%rbp), %rdi
subq 0x8(%rdi), %rax
movq %rax, %rsi
callq 0x2220
movq -0x3c0(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x3a0(%rbp,%rax)
jne 0x53b1
leaq (%rax,%rbp), %rdi
addq $-0x3c0, %rdi           # imm = 0xFC40
leaq -0x38(%rbp), %r14
leaq -0x1b0(%rbp), %r15
leaq 0x40fd(%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 -0x3c0(%rbp), %rdi
movq %r15, %rsi
callq 0x2360
cmpq $0x100, -0x3b8(%rbp) # imm = 0x100
jne 0x529e
cmpb $0x0, -0xb1(%rbp)
jne 0x53d7
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 0x6e0c
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rbx
cmpq %r14, %rdi
je 0x52d9
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testq %rbx, %rbx
movq -0x50(%rbp), %rbx
je 0x5391
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
jle 0x534d
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 0x3d2c(%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 0x5305
jmp 0x5350
xorl %r14d, %r14d
movq %r14, -0x48(%rbp)
movq -0x50(%rbp), %rbx
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x537a
movq %r14, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x20(%rbx)
leaq -0x38(%rbp), %r14
leaq -0x1b0(%rbp), %r15
jmp 0x5391
movq -0x60(%rbp), %rdi
movq %r12, %rdx
callq 0x85f2
leaq -0x38(%rbp), %r14
leaq -0x1b0(%rbp), %r15
movq -0x3c0(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x3c0, %rdi           # imm = 0xFC40
cmpl $0x0, 0x20(%rdi)
je 0x5263
movq -0x70(%rbp), %rax
movq %rax, 0x60(%rbx)
leaq -0x3c0(%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 0x7bd9(%rip), %rsi      # 0xcfc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x22e0
jmp 0x53fb
movq %rax, %r14
jmp 0x5484
jmp 0x5475
jmp 0x5475
movq %rax, %r14
jmp 0x5454
movq %rax, %r14
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x5432
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x5432
jmp 0x5475
movq %rax, %r14
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x5454
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x5478
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x5478
jmp 0x5475
jmp 0x5475
jmp 0x5475
movq %rax, %r14
leaq -0x3c0(%rbp), %rdi
callq 0x2070
movq -0x68(%rbp), %rdi
callq 0x68bc
movq -0x60(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
movq -0x50(%rbp), %rbx
je 0x54a9
movq 0x28(%rbx), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x61a0
movq %r14, %rdi
callq 0x2320
nop