// File: xiangzejun[P]Optimizing_Implementations_of_Linear_Layers/main.cpp
// Function: print_seq(std::vector<std::bitset<32ul>, std::allocator<std::bitset<32ul>>>, std::vector<std::bitset<32ul>, std::allocator<std::bitset<32ul>>>, std::vector<xpair, std::allocator<xpair>>)
void print_seq(vector<ROW> m, vector<ROW> tmp_m, vector<xpair> seq)
{
	ofstream f;
	f.open(FILENAME);
	f << "Original Matrix:" << endl;
	for(int i = 0; i < m.size(); i++)
		f << m[i] << endl;
	f << endl << endl;
	f << "Reduced Matrix:" << endl;
	for(int i = 0; i < tmp_m.size(); i++)
		f << tmp_m[i] << endl;
	f << endl << endl;


	f << "Xor Count = " << seq.size() << endl;
	
	int tab[SIZE] = {0};
	for(int i = 0; i < tmp_m.size(); i++)
		{
			for(int j = 0; j < tmp_m.size(); j++)
			{
				if(tmp_m[i].test(tmp_m.size() - 1 - j))
				{
					tab[i] = j;
					break;
				}
			}
		}

	for(int i = seq.size() - 1; i >= 0; i--)
		{//f << seq[i].dst << " <- " << seq[i].src << endl;
			f<<"x["<<tab[seq[i].dst]<<"] = x["<<tab[seq[i].dst]<<"] ^ x["<<tab[seq[i].src]<<"]";
		    tmp_m[seq[i].dst] ^= tmp_m[seq[i].src];
		  	bool flag = false;
		    for(int j = 0; j < m.size(); j++)
		    {
				if(tmp_m[seq[i].dst] == m[j])
				{
					flag = true;
					f<<"    y["<<j<<"]"<<endl;
					break;
				}
			}
			
			if(!flag)
			{
				f<<endl;
			}
		}
		f.close();
}

// Assembly:
subq $0x3c8, %rsp            # imm = 0x3C8
movq %rdi, 0xd8(%rsp)
movq %rsi, 0xe0(%rsp)
movq %rdx, 0xe8(%rsp)
movq %rdi, 0x3c0(%rsp)
movq %rsi, 0x3b8(%rsp)
movq %rdx, 0x3b0(%rsp)
leaq 0x1b0(%rsp), %rdi
movq %rdi, 0xf0(%rsp)
callq 0x2270
movq 0xf0(%rsp), %rdi
leaq 0xb6d9(%rip), %rsi      # 0xe004
movl $0x10, %edx
callq 0x2040
jmp 0x2937
leaq 0xb6e7(%rip), %rsi      # 0xe025
leaq 0x1b0(%rsp), %rdi
callq 0x2140
movq %rax, 0xd0(%rsp)
jmp 0x2955
movq 0xd0(%rsp), %rdi
movq 0x10664(%rip), %rsi     # 0x12fc8
callq 0x2170
jmp 0x296b
movl $0x0, 0x1a0(%rsp)
movq 0xd8(%rsp), %rdi
movslq 0x1a0(%rsp), %rax
movq %rax, 0xc8(%rsp)
callq 0x32a0
movq %rax, %rcx
movq 0xc8(%rsp), %rax
cmpq %rcx, %rax
jae 0x2a2a
movq 0xd8(%rsp), %rdi
movslq 0x1a0(%rsp), %rsi
callq 0x33d0
movq %rax, %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x32c0
movq %rax, 0xc0(%rsp)
jmp 0x29d6
movq 0xc0(%rsp), %rdi
movq 0x105e3(%rip), %rsi     # 0x12fc8
callq 0x2170
jmp 0x29ec
jmp 0x29ee
movl 0x1a0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a0(%rsp)
jmp 0x2976
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x2210
jmp 0x2fb1
movq 0x10597(%rip), %rsi     # 0x12fc8
leaq 0x1b0(%rsp), %rdi
callq 0x2170
movq %rax, 0xb8(%rsp)
jmp 0x2a48
movq 0xb8(%rsp), %rdi
movq 0x10571(%rip), %rsi     # 0x12fc8
callq 0x2170
jmp 0x2a5e
leaq 0xb5d1(%rip), %rsi      # 0xe036
leaq 0x1b0(%rsp), %rdi
callq 0x2140
movq %rax, 0xb0(%rsp)
jmp 0x2a7c
movq 0xb0(%rsp), %rdi
movq 0x1053d(%rip), %rsi     # 0x12fc8
callq 0x2170
jmp 0x2a92
movl $0x0, 0x19c(%rsp)
movq 0xe0(%rsp), %rdi
movslq 0x19c(%rsp), %rax
movq %rax, 0xa8(%rsp)
callq 0x32a0
movq %rax, %rcx
movq 0xa8(%rsp), %rax
cmpq %rcx, %rax
jae 0x2b27
movq 0xe0(%rsp), %rdi
movslq 0x19c(%rsp), %rsi
callq 0x33d0
movq %rax, %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x32c0
movq %rax, 0xa0(%rsp)
jmp 0x2af9
movq 0xa0(%rsp), %rdi
movq 0x104c0(%rip), %rsi     # 0x12fc8
callq 0x2170
jmp 0x2b0f
jmp 0x2b11
movl 0x19c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x19c(%rsp)
jmp 0x2a9d
movq 0x1049a(%rip), %rsi     # 0x12fc8
leaq 0x1b0(%rsp), %rdi
callq 0x2170
movq %rax, 0x98(%rsp)
jmp 0x2b45
movq 0x98(%rsp), %rdi
movq 0x10474(%rip), %rsi     # 0x12fc8
callq 0x2170
jmp 0x2b5b
leaq 0xb4e4(%rip), %rsi      # 0xe046
leaq 0x1b0(%rsp), %rdi
callq 0x2140
movq %rax, 0x90(%rsp)
jmp 0x2b79
movq 0xe8(%rsp), %rdi
callq 0x3280
movq 0x90(%rsp), %rdi
movq %rax, %rsi
callq 0x2050
movq %rax, 0x88(%rsp)
jmp 0x2ba0
movq 0x88(%rsp), %rdi
movq 0x10419(%rip), %rsi     # 0x12fc8
callq 0x2170
jmp 0x2bb6
leaq 0x110(%rsp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x20b0
movl $0x0, 0x10c(%rsp)
movq 0xe0(%rsp), %rdi
movslq 0x10c(%rsp), %rax
movq %rax, 0x80(%rsp)
callq 0x32a0
movq %rax, %rcx
movq 0x80(%rsp), %rax
cmpq %rcx, %rax
jae 0x2ccf
movl $0x0, 0x108(%rsp)
movq 0xe0(%rsp), %rdi
movslq 0x108(%rsp), %rax
movq %rax, 0x78(%rsp)
callq 0x32a0
movq %rax, %rcx
movq 0x78(%rsp), %rax
cmpq %rcx, %rax
jae 0x2cb7
movq 0xe0(%rsp), %rdi
movslq 0x10c(%rsp), %rsi
callq 0x33d0
movq 0xe0(%rsp), %rdi
movq %rax, 0x68(%rsp)
callq 0x32a0
movq 0x68(%rsp), %rdi
movslq 0x108(%rsp), %rsi
notq %rsi
addq %rax, %rsi
callq 0x33f0
movb %al, 0x77(%rsp)
jmp 0x2c7d
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x2c87
jmp 0x2c9f
movl 0x108(%rsp), %ecx
movslq 0x10c(%rsp), %rax
movl %ecx, 0x110(%rsp,%rax,4)
jmp 0x2cb7
jmp 0x2ca1
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0x2c11
jmp 0x2cb9
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0x2bd5
movq 0xe8(%rsp), %rdi
callq 0x3280
subq $0x1, %rax
movl %eax, 0x104(%rsp)
cmpl $0x0, 0x104(%rsp)
jl 0x2f8d
leaq 0xb35b(%rip), %rsi      # 0xe057
leaq 0x1b0(%rsp), %rdi
callq 0x2140
movq %rax, 0x60(%rsp)
jmp 0x2d10
movq 0xe8(%rsp), %rdi
movslq 0x104(%rsp), %rsi
callq 0x3430
movq 0x60(%rsp), %rdi
movslq 0x4(%rax), %rax
movl 0x110(%rsp,%rax,4), %esi
callq 0x2280
movq %rax, 0x58(%rsp)
jmp 0x2d41
movq 0x58(%rsp), %rdi
leaq 0xb306(%rip), %rsi      # 0xe053
callq 0x2140
movq %rax, 0x50(%rsp)
jmp 0x2d59
movq 0xe8(%rsp), %rdi
movslq 0x104(%rsp), %rsi
callq 0x3430
movq 0x50(%rsp), %rdi
movslq 0x4(%rax), %rax
movl 0x110(%rsp,%rax,4), %esi
callq 0x2280
movq %rax, 0x48(%rsp)
jmp 0x2d8a
movq 0x48(%rsp), %rdi
leaq 0xb2c4(%rip), %rsi      # 0xe05a
callq 0x2140
movq %rax, 0x40(%rsp)
jmp 0x2da2
movq 0xe8(%rsp), %rdi
movslq 0x104(%rsp), %rsi
callq 0x3430
movq 0x40(%rsp), %rdi
movslq (%rax), %rax
movl 0x110(%rsp,%rax,4), %esi
callq 0x2280
movq %rax, 0x38(%rsp)
jmp 0x2dd2
movq 0x38(%rsp), %rdi
leaq 0xb283(%rip), %rsi      # 0xe061
callq 0x2140
jmp 0x2de5
movq 0xe8(%rsp), %rdi
movslq 0x104(%rsp), %rsi
callq 0x3430
movq 0xe0(%rsp), %rdi
movslq (%rax), %rsi
callq 0x33d0
movq 0xe8(%rsp), %rdi
movq %rax, 0x30(%rsp)
movslq 0x104(%rsp), %rsi
callq 0x3430
movq 0xe0(%rsp), %rdi
movslq 0x4(%rax), %rsi
callq 0x33d0
movq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x3450
movb $0x0, 0x103(%rsp)
movl $0x0, 0xfc(%rsp)
movq 0xd8(%rsp), %rdi
movslq 0xfc(%rsp), %rax
movq %rax, 0x28(%rsp)
callq 0x32a0
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
jae 0x2f53
movq 0xe8(%rsp), %rdi
movslq 0x104(%rsp), %rsi
callq 0x3430
movq 0xe0(%rsp), %rdi
movslq 0x4(%rax), %rsi
callq 0x33d0
movq 0xd8(%rsp), %rdi
movq %rax, 0x20(%rsp)
movslq 0xfc(%rsp), %rsi
callq 0x33d0
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x3480
testb $0x1, %al
jne 0x2ed3
jmp 0x2f3b
movb $0x1, 0x103(%rsp)
leaq 0xb181(%rip), %rsi      # 0xe063
leaq 0x1b0(%rsp), %rdi
callq 0x2140
movq %rax, 0x18(%rsp)
jmp 0x2ef6
movq 0x18(%rsp), %rdi
movl 0xfc(%rsp), %esi
callq 0x2280
movq %rax, 0x10(%rsp)
jmp 0x2f0e
movq 0x10(%rsp), %rdi
leaq 0xb147(%rip), %rsi      # 0xe061
callq 0x2140
movq %rax, 0x8(%rsp)
jmp 0x2f26
movq 0x8(%rsp), %rdi
movq 0x10096(%rip), %rsi     # 0x12fc8
callq 0x2170
jmp 0x2f39
jmp 0x2f53
jmp 0x2f3d
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x2e55
testb $0x1, 0x103(%rsp)
jne 0x2f75
movq 0x10064(%rip), %rsi     # 0x12fc8
leaq 0x1b0(%rsp), %rdi
callq 0x2170
jmp 0x2f73
jmp 0x2f75
jmp 0x2f77
movl 0x104(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x2ce7
leaq 0x1b0(%rsp), %rdi
callq 0x21f0
jmp 0x2f9c
leaq 0x1b0(%rsp), %rdi
callq 0x2210
addq $0x3c8, %rsp            # imm = 0x3C8
retq
movq 0x1a8(%rsp), %rdi
callq 0x22a0
nop