// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1a8, %rsp            # imm = 0x1A8
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, %rsi
callq 0x6a10
leaq 0x18(%r12), %rdi
addq $0x18, %r14
movq %rdi, -0x38(%rbp)
movq %r14, %rsi
callq 0x6b62
leaq 0x30(%r15), %rdx
leaq -0x150(%rbp), %rdi
movq %r12, %rsi
callq 0x3216
movups (%r12), %xmm0
movq 0x10(%r12), %rax
leaq -0x138(%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)
leaq -0x1a0(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, -0x18(%r14)
movq $0x0, -0x8(%r14)
callq 0x67cc
movq -0x38(%rbp), %rdi
callq 0x6dde
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x5682
leaq 0x20(%r12), %rcx
leaq -0x130(%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 0x6960
leaq -0x150(%rbp), %rdi
callq 0x67cc
movq 0x60(%r15), %rdi
movq %r12, %rsi
callq 0x251c
movsd %xmm0, 0x68(%r15)
movq 0x18(%r15), %rax
cmpq %rax, 0x20(%r15)
je 0x5d33
leaq 0x20(%r12), %rcx
movq %rcx, -0x1a8(%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 0x592b
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 0x3899(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x38a1(%rip), %xmm1     # 0x9030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x38a5(%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, -0x1b0(%rbp)
movq 0x8(%r15), %rax
subq (%r15), %rax
sarq $0x5, %rax
movq %rax, %xmm1
movq 0x382c(%rip), %xmm0     # 0x9020
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x3830(%rip), %xmm0     # 0x9030
subpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x3830(%rip), %xmm1     # 0x9048
callq 0x2310
mulsd -0x1b0(%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 0x37cd(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x37d5(%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 0x376a(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3772(%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 0x5a43
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 0x36b0(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x36b8(%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 0x364d(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3655(%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 -0x140(%rbp), %r14
movq %r14, -0x150(%rbp)
movq %r13, -0x148(%rbp)
movb %r13b, -0x140(%rbp)
leaq -0x120(%rbp), %rax
movq %rax, -0x130(%rbp)
movq %r13, -0x128(%rbp)
movb %r13b, -0x120(%rbp)
leaq -0x100(%rbp), %rax
movq %rax, -0x110(%rbp)
movq %r13, -0x108(%rbp)
movb %r13b, -0x100(%rbp)
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq %r13, -0xe8(%rbp)
movb %r13b, -0xe0(%rbp)
leaq -0x150(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2110
leaq -0x130(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2110
leaq -0x110(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2110
leaq -0xf0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2110
movq 0x18(%r15), %rax
movq (%rax,%rbx,8), %rax
movq %rax, -0xd0(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq -0x150(%rbp), %rsi
movq -0xa8(%rbp), %r12
movq %r12, %rdx
callq 0x3dc2
movups (%r12), %xmm0
movq 0x10(%r12), %rax
movq -0x1a0(%rbp), %rcx
movq %rcx, (%r12)
movq -0x198(%rbp), %rcx
movq %rcx, 0x8(%r12)
movq -0x190(%rbp), %rcx
movq %rcx, 0x10(%r12)
movups %xmm0, -0x1c8(%rbp)
movq %rax, -0x1b8(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x1a0(%rbp)
movq $0x0, -0x190(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x67cc
movq -0x38(%rbp), %rdi
callq 0x6dde
movq -0x178(%rbp), %rax
testq %rax, %rax
je 0x5bf8
movl -0x180(%rbp), %ecx
movl %ecx, 0x20(%r12)
movq %rax, 0x28(%r12)
movq -0x170(%rbp), %rcx
movq %rcx, 0x30(%r12)
movq -0x168(%rbp), %rcx
movq %rcx, 0x38(%r12)
movq -0x1a8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x160(%rbp), %rax
movq %rax, 0x40(%r12)
movq %r13, -0x178(%rbp)
leaq -0x180(%rbp), %rax
movq %rax, -0x170(%rbp)
movq %rax, -0x168(%rbp)
movq %r13, -0x160(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x6960
leaq -0x1a0(%rbp), %rdi
callq 0x67cc
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x5c32
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x5c54
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rax
cmpq %rax, %rdi
je 0x5c76
movq -0x120(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x150(%rbp), %rdi
cmpq %r14, %rdi
je 0x5c91
movq -0x140(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x5caa
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x5cc3
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x5ce5
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
movl -0x3c(%rbp), %r14d
je 0x5d0b
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 0x56de
movq 0x60(%r15), %rdi
movq %r12, %rsi
callq 0x251c
movsd %xmm0, 0x70(%r15)
movq %r12, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5d64
movq %rax, %r14
jmp 0x5e0a
movq %rax, %r14
jmp 0x5e01
jmp 0x5d75
jmp 0x5d70
movq %rax, %r14
jmp 0x5d84
movq %rax, %r14
leaq -0x150(%rbp), %rdi
callq 0x6720
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
movq -0xa8(%rbp), %r12
je 0x5da4
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x5dbd
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x5ddf
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x5e01
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x38(%rbp), %rdi
callq 0x6960
movq %r12, %rdi
callq 0x67cc
movq %r14, %rdi
callq 0x2320