// File: /workspace/github_cpp_makefile_star2_O2/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 $0x178, %rsp            # imm = 0x178
movq %rsi, %r15
movq %rdi, %r14
movq %rdx, %rsi
callq 0x53b8
leaq 0x30(%r15), %rdx
leaq -0x150(%rbp), %rdi
movq %r14, %rsi
callq 0x2e82
leaq -0x150(%rbp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x53f2
movq %rbx, %rdi
callq 0x4f1e
movq 0x60(%r15), %rdi
movq %r14, %rsi
callq 0x249c
movq %r15, -0x40(%rbp)
movsd %xmm0, 0x68(%r15)
movabsq $0xe6f93c791, %rsi      # imm = 0xE6F93C791
leaq -0xc8(%rbp), %r12
xorl %r13d, %r13d
movq %r14, -0x38(%rbp)
movl %r13d, %r13d
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rax
movq 0x20(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
jbe 0x4b95
leaq -0xb8(%rbp), %rcx
movq %rcx, -0xc8(%rbp)
andq $0x0, -0xc0(%rbp)
xorl %edx, %edx
movb %dl, -0xb8(%rbp)
leaq -0x98(%rbp), %rcx
movq %rcx, -0xa8(%rbp)
andq $0x0, -0xa0(%rbp)
movb %dl, -0x98(%rbp)
leaq -0x70(%rbp), %rcx
movq %rcx, -0x80(%rbp)
andq $0x0, -0x78(%rbp)
leaq -0x50(%rbp), %rcx
movq %rcx, -0x60(%rbp)
andq $0x0, -0x58(%rbp)
movb %dl, -0x70(%rbp)
movb %dl, -0x50(%rbp)
movq (%rax,%r13,8), %rcx
cmpq %rsi, %rcx
jl 0x4958
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
cvtsi2sd %rdx, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x40(%rbp), %r14
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x5, %rax
movq %rax, %xmm1
punpckldq 0x3865(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x386d(%rip), %xmm1     # 0x8030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x3871(%rip), %xmm1     # 0x8048
callq 0x22d0
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %ebx
movslq %ebx, %rsi
shlq $0x5, %rsi
addq (%r14), %rsi
movq %r12, %rdi
callq 0x2110
leaq -0x198(%rbp), %r15
cvtsi2sd %ebx, %xmm0
movsd %xmm0, -0x88(%rbp)
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x5, %rax
movq %rax, %xmm1
movq 0x37fa(%rip), %xmm0     # 0x8020
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x37fe(%rip), %xmm0     # 0x8030
subpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x37fe(%rip), %xmm1     # 0x8048
callq 0x22d0
mulsd -0x88(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
cvtsi2sd %rax, %xmm2
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
movq %rcx, %xmm0
punpckldq 0x379b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x37a3(%rip), %xmm0     # 0x8030
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, %ebx
movslq %ebx, %rsi
shlq $0x5, %rsi
addq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x2110
cvtsi2sd %ebx, %xmm0
movq (%r14), %rcx
movq 0x8(%r14), %rsi
subq %rcx, %rsi
sarq $0x5, %rsi
movq %rsi, %xmm1
punpckldq 0x373d(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3745(%rip), %xmm1     # 0x8030
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, %r12
movq %r12, %rax
xorl %edx, %edx
divq %rsi
movslq %eax, %rbx
movq %rbx, %rsi
shlq $0x5, %rsi
addq %rcx, %rsi
leaq -0x80(%rbp), %rdi
callq 0x2110
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
imulq %rbx, %rcx
subq %rcx, %r12
shlq $0x5, %r12
addq %rax, %r12
leaq -0x60(%rbp), %rdi
movq %r12, %rsi
callq 0x2110
jmp 0x4a63
movq %rcx, %rax
cqto
movl $0x767ed6b, %esi        # imm = 0x767ED6B
idivq %rsi
movl %ecx, %eax
subl %edx, %eax
cltq
subq %rax, %rcx
cvtsi2sd %rcx, %xmm2
movq -0x40(%rbp), %r14
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
movq %rcx, %xmm0
punpckldq 0x368e(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3696(%rip), %xmm0     # 0x8030
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, %ebx
movslq %ebx, %rsi
shlq $0x5, %rsi
addq %rax, %rsi
movq %r12, %rdi
callq 0x2110
leaq -0x198(%rbp), %r15
cvtsi2sd %ebx, %xmm0
movq (%r14), %rcx
movq 0x8(%r14), %rsi
subq %rcx, %rsi
sarq $0x5, %rsi
movq %rsi, %xmm1
punpckldq 0x362d(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3635(%rip), %xmm1     # 0x8030
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, %r12
movq %r12, %rax
xorl %edx, %edx
divq %rsi
movslq %eax, %rbx
movq %rbx, %rsi
shlq $0x5, %rsi
addq %rcx, %rsi
leaq -0x80(%rbp), %rdi
callq 0x2110
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
imulq %rbx, %rcx
subq %rcx, %r12
shlq $0x5, %r12
addq %rax, %r12
leaq -0x60(%rbp), %rdi
movq %r12, %rsi
callq 0x2110
leaq -0x140(%rbp), %rax
movq %rax, -0x150(%rbp)
andq $0x0, -0x148(%rbp)
xorl %ecx, %ecx
movb %cl, -0x140(%rbp)
leaq -0x120(%rbp), %rax
movq %rax, -0x130(%rbp)
andq $0x0, -0x128(%rbp)
movb %cl, -0x120(%rbp)
leaq -0x100(%rbp), %rax
movq %rax, -0x110(%rbp)
andq $0x0, -0x108(%rbp)
movb %cl, -0x100(%rbp)
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
andq $0x0, -0xe8(%rbp)
movb %cl, -0xe0(%rbp)
leaq -0x150(%rbp), %rbx
movq %rbx, %rdi
leaq -0xc8(%rbp), %r12
movq %r12, %rsi
callq 0x2110
leaq -0x130(%rbp), %rdi
leaq -0xa8(%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(%r14), %rax
movq (%rax,%r13,8), %rax
movq %rax, -0xd0(%rbp)
movq %r15, %rdi
movq %rbx, %rsi
movq -0x38(%rbp), %r14
movq %r14, %rdx
callq 0x3596
movq %r14, %rdi
movq %r15, %rsi
callq 0x53f2
movq %r15, %rdi
callq 0x4f1e
movq %rbx, %rdi
callq 0x541c
leaq -0x60(%rbp), %rdi
callq 0x2368
leaq -0x80(%rbp), %rdi
callq 0x2368
leaq -0xa8(%rbp), %rdi
callq 0x2368
movq %r12, %rdi
callq 0x2368
incl %r13d
movabsq $0xe6f93c791, %rsi      # imm = 0xE6F93C791
jmp 0x4707
movq -0x40(%rbp), %rbx
movq 0x60(%rbx), %rdi
movq %r14, %rsi
callq 0x249c
movsd %xmm0, 0x70(%rbx)
movq %r14, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4bc1
movq %rax, %rbx
jmp 0x4c13
movq %rax, %rbx
jmp 0x4bdd
jmp 0x4bcd
movq %rax, %rbx
movq -0x38(%rbp), %r14
jmp 0x4be9
movq %rax, %rbx
movq -0x38(%rbp), %r14
leaq -0x150(%rbp), %rdi
callq 0x541c
leaq -0x60(%rbp), %rdi
callq 0x2368
leaq -0x80(%rbp), %rdi
callq 0x2368
leaq -0xa8(%rbp), %rdi
callq 0x2368
leaq -0xc8(%rbp), %rdi
callq 0x2368
movq %r14, %rdi
callq 0x4f1e
movq %rbx, %rdi
callq 0x22e0