// File: /workspace/github_cpp_makefile_star2_O1/szmer[P]brill/./src/rules_applier.cpp
// Function: RulesApplier::transform(Corpus*)
Corpus RulesApplier::transform(Corpus * corp) {

	Corpus next_corp = * corp;

	// Tag with loaded initial (unigram) tagger. 
	next_corp = next_corp.tag_with_table(& tag_lookup);
	baseline_score = Corpus::compare_corpora( gold_corp, & next_corp);

	// Apply each rule on the list consecutively.
	for(unsigned int i = 0; i < rules.size(); i++) {

		// Figure out what rule this is.
		int rule_type = -1;
		string cue1, cue2, alter_tag, target;

		if(rules[i] >= EXT_RULE_RANGE) {
			long long rule_ind = rules[i]; // temporary variable that will be stripped

			rule_type = rule_ind / EXT_RULE_RANGE; // nice that int will strip the remainder
			rule_ind -= rule_type * EXT_RULE_RANGE;

			int tag_id = rule_ind / pow(tag_index.size(), 3);
			cue1 = tag_index[ tag_id ];
			rule_ind -= tag_id * pow(tag_index.size(), 3);

			tag_id = rule_ind / pow(tag_index.size(), 2);
			cue2 = tag_index[ tag_id ];
			rule_ind -= tag_id * pow(tag_index.size(), 2);

			tag_id = rule_ind / tag_index.size();
			alter_tag = tag_index[ tag_id ];
			rule_ind -= tag_id * tag_index.size();

			target = tag_index[ rule_ind ];
		}

		else {
			long long rule_ind = rules[i]; // temporary variable that will be stripped

			rule_type = rule_ind / RULE_RANGE;
			rule_ind -= rule_type * RULE_RANGE;

			int tag_id = rule_ind / pow(tag_index.size(), 2);
			cue1 = tag_index[ tag_id ];
			rule_ind -= tag_id * pow(tag_index.size(), 2);

			tag_id = rule_ind / tag_index.size();
			alter_tag = tag_index[ tag_id ];
			rule_ind -= tag_id * tag_index.size();

			target = tag_index[ rule_ind ];
		}

		// Create this rule and apply it.
		Rule rl;
		rl.cue1 = cue1;
		rl.cue2 = cue2;
		rl.alter_tag = alter_tag;
		rl.target = target;
		rl.id = rules[i];

		next_corp = rl.transform_corp(& next_corp);
	}

	final_score = Corpus::compare_corpora( gold_corp, & next_corp);

	return next_corp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, %rsi
callq 0x696c
leaq 0x18(%r12), %rdi
addq $0x18, %r14
movq %rdi, -0x38(%rbp)
movq %r14, %rsi
callq 0x6abe
leaq 0x30(%r15), %rdx
leaq -0x168(%rbp), %rdi
movq %r12, %rsi
callq 0x3222
xorps %xmm0, %xmm0
leaq -0x1b0(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%r12), %rax
movups 0x8(%r12), %xmm0
leaq -0x150(%rbp), %r14
movq -0x18(%r14), %rcx
movq %rcx, (%r12)
movq -0x10(%r14), %rcx
movq %rcx, 0x8(%r12)
movq -0x8(%r14), %rcx
movq %rcx, 0x10(%r12)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movups %xmm0, 0x8(%rdi)
movq %rcx, -0x18(%r14)
movq %rdx, -0x10(%r14)
movq %rsi, -0x8(%r14)
callq 0x672e
movq -0x38(%rbp), %rdi
callq 0x6d3a
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x55c5
leaq 0x20(%r12), %rcx
leaq -0x148(%rbp), %rdx
movl (%rdx), %esi
movl %esi, 0x20(%r12)
movq %rax, 0x28(%r12)
movq 0x10(%rdx), %rsi
movq %rsi, 0x30(%r12)
movq 0x18(%rdx), %rsi
movq %rsi, 0x38(%r12)
movq %rcx, 0x8(%rax)
movq 0x20(%rdx), %rax
movq %rax, 0x40(%r12)
xorl %eax, %eax
movq %rax, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %rax, 0x20(%rdx)
movq %r14, %rdi
callq 0x68bc
leaq -0x168(%rbp), %rdi
callq 0x672e
movq 0x60(%r15), %rdi
movq %r12, %rsi
callq 0x251c
movsd %xmm0, 0x68(%r15)
movq 0x18(%r15), %rax
cmpq %rax, 0x20(%r15)
je 0x5ca2
leaq 0x20(%r12), %rcx
movq %rcx, -0x1b8(%rbp)
movl $0x1, %r14d
xorl %r13d, %r13d
movabsq $0xe6f93c791, %rsi      # imm = 0xE6F93C791
xorl %ebx, %ebx
movq %r12, -0xa8(%rbp)
movl %r14d, -0x3c(%rbp)
leaq -0x90(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movq %r13, -0x98(%rbp)
movb %r13b, -0x90(%rbp)
leaq -0xb8(%rbp), %rcx
movq %rcx, -0xc8(%rbp)
movq %r13, -0xc0(%rbp)
movb %r13b, -0xb8(%rbp)
leaq -0x70(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movq %r13, -0x78(%rbp)
movb %r13b, -0x70(%rbp)
leaq -0x50(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movq %r13, -0x58(%rbp)
movb %r13b, -0x50(%rbp)
movq (%rax,%rbx,8), %rcx
movq %rcx, %rax
cmpq %rsi, %rcx
jl 0x586e
movabsq $-0x72218692302eefe9, %rdx # imm = 0x8DDE796DCFD11017
mulq %rdx
shrq $0x23, %rdx
imulq %rsi, %rdx
subq %rdx, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x8(%r15), %rax
subq (%r15), %rax
sarq $0x5, %rax
movq %rax, %xmm1
punpckldq 0x3956(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x395e(%rip), %xmm1     # 0x9030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x3962(%rip), %xmm1     # 0x9048
callq 0x2310
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r14d
movslq %r14d, %rsi
shlq $0x5, %rsi
addq (%r15), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x2110
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, -0x1c0(%rbp)
movq 0x8(%r15), %rax
subq (%r15), %rax
sarq $0x5, %rax
movq %rax, %xmm1
movq 0x38e9(%rip), %xmm0     # 0x9020
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x38ed(%rip), %xmm0     # 0x9030
subpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x38ed(%rip), %xmm1     # 0x9048
callq 0x2310
mulsd -0x1c0(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
cvtsi2sd %rax, %xmm2
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
movq %rcx, %xmm0
punpckldq 0x388a(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3892(%rip), %xmm0     # 0x9030
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm2, -0x30(%rbp)
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %r14d
movslq %r14d, %rsi
shlq $0x5, %rsi
addq %rax, %rsi
leaq -0xc8(%rbp), %rdi
callq 0x2110
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq (%r15), %rcx
movq 0x8(%r15), %rsi
subq %rcx, %rsi
sarq $0x5, %rsi
movq %rsi, %xmm1
punpckldq 0x3827(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x382f(%rip), %xmm1     # 0x9030
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm2
movsd -0x30(%rbp), %xmm0
subsd %xmm2, %xmm0
cvttsd2si %xmm0, %r14
movq %r14, %rax
xorl %edx, %edx
divq %rsi
movslq %eax, %r12
movq %r12, %rsi
shlq $0x5, %rsi
addq %rcx, %rsi
leaq -0x80(%rbp), %rdi
callq 0x2110
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
imulq %r12, %rcx
subq %rcx, %r14
shlq $0x5, %r14
addq %rax, %r14
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
callq 0x2110
jmp 0x5986
movabsq $0x452229ac43052097, %rdx # imm = 0x452229AC43052097
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x19, %rdx
addl %eax, %edx
imull $0x767ed6b, %edx, %eax  # imm = 0x767ED6B
cltq
subq %rax, %rcx
cvtsi2sd %rcx, %xmm2
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
movq %rcx, %xmm0
punpckldq 0x376d(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3775(%rip), %xmm0     # 0x9030
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm2, -0x30(%rbp)
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %r14d
movslq %r14d, %rsi
shlq $0x5, %rsi
addq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x2110
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq (%r15), %rcx
movq 0x8(%r15), %rsi
subq %rcx, %rsi
sarq $0x5, %rsi
movq %rsi, %xmm1
punpckldq 0x370a(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3712(%rip), %xmm1     # 0x9030
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm2
movsd -0x30(%rbp), %xmm0
subsd %xmm2, %xmm0
cvttsd2si %xmm0, %r14
movq %r14, %rax
xorl %edx, %edx
divq %rsi
movslq %eax, %r12
movq %r12, %rsi
shlq $0x5, %rsi
addq %rcx, %rsi
leaq -0x80(%rbp), %rdi
callq 0x2110
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
imulq %r12, %rcx
subq %rcx, %r14
shlq $0x5, %r14
addq %rax, %r14
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
callq 0x2110
leaq -0x158(%rbp), %r14
movq %r14, -0x168(%rbp)
movq %r13, -0x160(%rbp)
movb %r13b, -0x158(%rbp)
leaq -0x138(%rbp), %rax
movq %rax, -0x148(%rbp)
movq %r13, -0x140(%rbp)
movb %r13b, -0x138(%rbp)
leaq -0x118(%rbp), %rax
movq %rax, -0x128(%rbp)
movq %r13, -0x120(%rbp)
movb %r13b, -0x118(%rbp)
leaq -0xf8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq %r13, -0x100(%rbp)
movb %r13b, -0xf8(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2110
leaq -0x148(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2110
leaq -0x128(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2110
leaq -0x108(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2110
movq 0x18(%r15), %rax
movq (%rax,%rbx,8), %rax
movq %rax, -0xe8(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x168(%rbp), %rsi
movq -0xa8(%rbp), %r12
movq %r12, %rdx
callq 0x3da2
xorpd %xmm0, %xmm0
movapd %xmm0, -0xe0(%rbp)
movq $0x0, -0xd0(%rbp)
movq (%r12), %rax
movups 0x8(%r12), %xmm0
movq -0x1b0(%rbp), %rcx
movq %rcx, (%r12)
movq -0x1a8(%rbp), %rcx
movq %rcx, 0x8(%r12)
movq -0x1a0(%rbp), %rcx
movq %rcx, 0x10(%r12)
movq -0xe0(%rbp), %rcx
movq -0xd8(%rbp), %rdx
movq -0xd0(%rbp), %rsi
movq %rax, -0xe0(%rbp)
movups %xmm0, -0xd8(%rbp)
movq %rcx, -0x1b0(%rbp)
movq %rdx, -0x1a8(%rbp)
movq %rsi, -0x1a0(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x672e
movq -0x38(%rbp), %rdi
callq 0x6d3a
movq -0x188(%rbp), %rax
testq %rax, %rax
je 0x5b67
movl -0x190(%rbp), %ecx
movl %ecx, 0x20(%r12)
movq %rax, 0x28(%r12)
movq -0x180(%rbp), %rcx
movq %rcx, 0x30(%r12)
movq -0x178(%rbp), %rcx
movq %rcx, 0x38(%r12)
movq -0x1b8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x170(%rbp), %rax
movq %rax, 0x40(%r12)
movq %r13, -0x188(%rbp)
leaq -0x190(%rbp), %rax
movq %rax, -0x180(%rbp)
movq %rax, -0x178(%rbp)
movq %r13, -0x170(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x68bc
leaq -0x1b0(%rbp), %rdi
callq 0x672e
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x5ba1
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x5bc3
movq -0x118(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0x5be5
movq -0x138(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x168(%rbp), %rdi
cmpq %r14, %rdi
je 0x5c00
movq -0x158(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x5c19
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x5c32
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x5c54
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
movl -0x3c(%rbp), %r14d
je 0x5c7a
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x21c0
movl %r14d, %ebx
movq 0x18(%r15), %rax
movq 0x20(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
incl %r14d
cmpq %rbx, %rcx
movabsq $0xe6f93c791, %rsi      # imm = 0xE6F93C791
ja 0x5621
movq 0x60(%r15), %rdi
movq %r12, %rsi
callq 0x251c
movsd %xmm0, 0x70(%r15)
movq %r12, %rax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5cd3
movq %rax, %r14
jmp 0x5d79
movq %rax, %r14
jmp 0x5d70
jmp 0x5ce4
jmp 0x5cdf
movq %rax, %r14
jmp 0x5cf3
movq %rax, %r14
leaq -0x168(%rbp), %rdi
callq 0x6682
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
movq -0xa8(%rbp), %r12
je 0x5d13
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x5d2c
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x5d4e
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x5d70
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x38(%rbp), %rdi
callq 0x68bc
movq %r12, %rdi
callq 0x672e
movq %r14, %rdi
callq 0x2320